Я не могу добавить новое представление в группу просмотра.
Это вызывает ошибку:
AndroidRuntime: вызвано: java .lang.NullPointerException: попытка вызвать виртуальный метод void android .view.ViewGroup.addView (android .view.View) для ссылки на нулевой объект
Я имею в виду эту библиотеку
Я могу показать вид игрока без фильтра и recyclerview, если я использую как показано ниже. binding.playerView.setPlayer (player) в методе play () без gpuPlayerView. В этом случае мой activity_view. xml работает с PlayerView Exoplayer:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.test.view.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/player_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:controller_layout_id="@layout/item_player_controler"
app:resize_mode="fill"
app:show_timeout="1000"
app:shutter_background_color="@color/black" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/black_55"
android:orientation="horizontal">
<ImageView
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:onClick="@{onBackClick}"
android:padding="15dp"
android:src="@drawable/ic_back"
android:tint="@color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:fontFamily="@font/popins_reguler"
android:gravity="center"
android:text="Preview" />
</RelativeLayout>
</RelativeLayout>
</layout>
Но проблема начинается отсюда, если я заменяю указанный выше файл 'xml' на файл ниже и добавляю шаги, связанные с 'gpuPlayerView.setSimpleExoPlaye' и c:
activity_view. xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.test.view.MainActivity">
<com.broadmind.clipps.filter.MovieWrapperView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/layout_movie_wrapper"/>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/recylerview"
android:paddingBottom="20dp"
android:background="@color/fifty_transparent_black"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
MainActivity. java
public class MainActivity extends BaseActivity {
private ActivityPreviewBinding binding;
private MainViewModel viewModel;
private CustomDialogBuilder customDialogBuilder;
private SimpleExoPlayer player;
GPUPlayerView gpuPlayerView;
public static int select_postion=0;
final List<FilterType> filterTypes = FilterType.createFilterList();
Filter_Adapter adapter;
RecyclerView recylerview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_view);
viewModel = ViewModelProviders.of(this, new ViewModelFactory(new MainViewModel()).createFor()).get(MainViewModel.class);
customDialogBuilder = new CustomDialogBuilder(this);
viewModel.sessionManager = sessionManager;
initView();
play();
initObserve();
//initListener();
}
private void initView() {
viewModel.vidPath = getIntent().getStringExtra("send_video_path");
}
private void play() {
DefaultTrackSelector trackSelector = new DefaultTrackSelector();
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this,
Util.getUserAgent(this, "MyApp"));
MediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory)
.createMediaSource(Uri.parse(viewModel.vidPath));
player.prepare(videoSource);
player.setRepeatMode(Player.REPEAT_MODE_ALL);
player.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT);
player.setPlaybackParameters(PlaybackParameters.DEFAULT);
//player.addListener(this);
//binding.playerView.setPlayer(player);
player.setPlayWhenReady(true);
gpuPlayerView = new GPUPlayerView(this);
gpuPlayerView.setPlayerScaleType(PlayerScaleType.RESIZE_NONE);
gpuPlayerView.setSimpleExoPlayer(player);
gpuPlayerView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
MovieWrapperView rl = (MovieWrapperView) findViewById(R.id.layout_movie_wrapper);
rl.addView(gpuPlayerView);
gpuPlayerView.onResume();
recylerview=findViewById(R.id.recylerview);
adapter = new Filter_Adapter(this, filterTypes, new Filter_Adapter.OnItemClickListener() {
@Override
public void onItemClick(View view, int postion, FilterType item) {
select_postion=postion;
gpuPlayerView.setGlFilter(FilterType.createGlFilter(filterTypes.get(postion), getApplicationContext()));
adapter.notifyDataSetChanged();
}
});
recylerview.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
recylerview.setAdapter(adapter);
}
@Override
protected void onResume() {
if (player != null) {
player.setPlayWhenReady(true);
}
super.onResume();
}
@Override
protected void onPause() {
if (player != null) {
player.setPlayWhenReady(false);
}
super.onPause();
}
}