Search in sources :

Example 1 with SensorViewModel

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);
        }
    });
}
Also used : SensorViewModel(com.zype.android.ui.player.SensorViewModel) ImageButton(android.widget.ImageButton) VideoDetailViewModel(com.zype.android.ui.video_details.VideoDetailViewModel) PlayerViewModel(com.zype.android.ui.player.PlayerViewModel)

Aggregations

ImageButton (android.widget.ImageButton)1 PlayerViewModel (com.zype.android.ui.player.PlayerViewModel)1 SensorViewModel (com.zype.android.ui.player.SensorViewModel)1 VideoDetailViewModel (com.zype.android.ui.video_details.VideoDetailViewModel)1