use of com.zype.android.ui.player.PlayerViewModel in project zype-android by zype.
the class VideoDetailActivity method initModel.
// //////////
// Data
//
private void initModel() {
final Video video = DataRepository.getInstance(getApplication()).getVideoSync(mVideoId);
if (video != null) {
// Load player urls
playerViewModel = ViewModelProviders.of(this).get(PlayerViewModel.class);
PlayerViewModel.PlayerMode mediaType = null;
switch(mType) {
case PlayerFragment.TYPE_AUDIO_LOCAL:
case PlayerFragment.TYPE_AUDIO_WEB:
mediaType = PlayerViewModel.PlayerMode.AUDIO;
break;
case PlayerFragment.TYPE_VIDEO_LOCAL:
case PlayerFragment.TYPE_VIDEO_WEB:
case BaseVideoActivity.TYPE_WEB:
mediaType = PlayerViewModel.PlayerMode.VIDEO;
break;
}
playerViewModel.init(video.id, playlistId, mediaType);
playerViewModel.getPlayerError().observe(this, playerErrorObserver);
playerViewModel.getPlayerUrl().observe(this, playerUrlObserver);
if (video.isZypeLive == 0) {
updateDownloadUrls();
} else {
// showVideoThumbnail();
videoDetailViewModel = new VideoDetailViewModel(getApplication());
final Observer<Video> videoObserver = new Observer<Video>() {
@Override
public void onChanged(@Nullable Video video) {
if (VideoHelper.isLiveEventOnAir(video)) {
if (videoDetailViewModel.updateVideoOnAir(video)) {
showPlayer();
}
} else {
changeFragment(isChromecastConntected());
videoDetailViewModel.checkOnAir(mVideoId).observe(VideoDetailActivity.this, new Observer<Video>() {
@Override
public void onChanged(@Nullable Video video) {
videoDetailViewModel.onCleared();
videoDetailViewModel.updateVideoOnAir(video);
showPlayer();
}
});
}
videoDetailViewModel.getVideo(mVideoId).removeObserver(this);
}
};
videoDetailViewModel.getVideo(mVideoId).observe(this, videoObserver);
}
}
}
use of com.zype.android.ui.player.PlayerViewModel 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