use of com.zype.android.ui.player.SensorViewModel in project zype-android by zype.
the class PlayerFragment method onActivityCreated.
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Logger.d("onActivityCreated()");
// Initialize Google Cast
castContext = CastContext.getSharedInstance();
castSessionManager = CastContext.getSharedInstance().getSessionManager();
setupCastListener();
initIMA();
initMediaSession();
sensorViewModel = ViewModelProviders.of(getActivity()).get(SensorViewModel.class);
playerViewModel = ViewModelProviders.of(getActivity()).get(PlayerViewModel.class);
if (playerModeObserver == null)
playerModeObserver = createPlayerModeObserver();
if (playerUrlObserver == null)
playerUrlObserver = createPlayerUrlObserver();
if (playerErrorObserver == null)
playerErrorObserver = createPlayerErrorObserver();
playerViewModel.getPlayerMode().observe(this, playerModeObserver);
playerViewModel.getPlayerUrl().observe(this, playerUrlObserver);
playerViewModel.getPlayerError().observe(this, playerErrorObserver);
if (playerViewModel.isTrailer().getValue()) {
ImageButton buttonCloseTrailer = getView().findViewById(R.id.buttonCloseTrailer);
buttonCloseTrailer.setVisibility(View.VISIBLE);
buttonCloseTrailer.setOnClickListener(v -> {
stop();
videoViewModel.onVideoFinished(true);
playerViewModel.setTrailerVideoId(null);
setPortraitOrientation();
});
setLandscapeOrientation();
}
videoViewModel = ViewModelProviders.of(getActivity()).get(VideoDetailViewModel.class);
videoViewModel.getVideo().observe(this, video -> {
thumbnail = VideoHelper.getThumbnailByHeight(video, 480);
if (thumbnail != null) {
UiUtils.loadImage(thumbnail.getUrl(), R.drawable.placeholder_video, imageThumbnail);
}
initProgress(video);
});
videoViewModel.isFullscreen().observe(this, fullscreen -> {
if (fullscreen != null) {
updateFullscreenButton(fullscreen);
}
});
}
Aggregations