android.support.v17.leanback.media.MediaPlayerAdapter Java Examples

The following examples show how to use android.support.v17.leanback.media.MediaPlayerAdapter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlaybackFragment.java    From leanback-assistant with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    int movieId = getActivity().getIntent().getIntExtra(EXTRA_MOVIE_ID, -1);
    if (movieId == -1) {
        Log.w(TAG, "Invalid movieId, cannot playback.");
        throw new IllegalArgumentException("Invalid movieId " + movieId);
    }

    mPlaylistAdapter =
            MockPlaylistAdapterFactory.createMoviePlaylistAdapterWithActiveMovieId(movieId);

    mSession = new MediaSessionCompat(getContext(), TAG);
    mSession.setFlags(
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
                    | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mSession.setActive(true);
    MediaControllerCompat.setMediaController((Activity) getContext(), mSession.getController());

    mPlayerGlue =
            new PrimaryPlaybackControlsGlue<>(
                    getContext(),
                    new MediaPlayerAdapter(getContext()),
                    mSession.getController());
    mPlayerGlue.setHost(new VideoSupportFragmentGlueHost(this));
    mPlayerGlue.addPlayerCallback(playWhenReadyPlayerCallback);
    mPlayerGlue.addPlayerCallback(playPausePlayerCallback);

    mMediaSessionCallback = new MediaSessionCallback(mPlayerGlue);
    mSession.setCallback(mMediaSessionCallback);

    playMedia(mPlaylistAdapter.getCurrentItem());
}
 
Example #2
Source File: VideoFragment.java    From leanback-homescreen-channels with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mMediaPlayerGlue = new PlaybackBannerControlGlue<MediaPlayerAdapter>(getContext(),
            new int[]{1}, new MediaPlayerAdapter(getContext())) {
        @Override
        public long getSupportedActions() {
            return PlaybackBannerControlGlue.ACTION_PLAY_PAUSE
                    | PlaybackBannerControlGlue.ACTION_SKIP_TO_NEXT
                    | PlaybackBannerControlGlue.ACTION_SKIP_TO_PREVIOUS;
        }
    };
    mMediaPlayerGlue.setHost(mHost);

    Bundle args = getArguments();
    mSelectedClip = args.getParcelable(PlaybackActivity.EXTRA_CLIP);
    mProgress = args.getLong(PlaybackActivity.EXTRA_PROGRESS);

    mMediaPlayerGlue.setTitle(mSelectedClip.getTitle());
    mMediaPlayerGlue.setSubtitle(mSelectedClip.getDescription());
    mMediaPlayerGlue.getPlayerAdapter().setDataSource(Uri.parse(mSelectedClip.getVideoUrl()));
    mSession = new MediaSessionCompat(getContext(), "TvLauncherSampleApp");
    mSession.setActive(true);
    mSession.setCallback(new MediaSessionCallback());
    playWhenReady();
    updatePlaybackState();
    updateMetadata(mSelectedClip);
}
 
Example #3
Source File: VideoConsumptionExampleFragment.java    From leanback-showcase with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mMediaPlayerGlue = new VideoMediaPlayerGlue(getActivity(),
            new MediaPlayerAdapter(getActivity()));
    mMediaPlayerGlue.setHost(mHost);
    AudioManager audioManager = (AudioManager) getActivity()
            .getSystemService(Context.AUDIO_SERVICE);
    if (audioManager.requestAudioFocus(mOnAudioFocusChangeListener, AudioManager.STREAM_MUSIC,
            AudioManager.AUDIOFOCUS_GAIN) != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
        Log.w(TAG, "video player cannot obtain audio focus!");
    }

    mMediaPlayerGlue.setMode(PlaybackControlsRow.RepeatAction.NONE);
    MediaMetaData intentMetaData = getActivity().getIntent().getParcelableExtra(
            VideoExampleActivity.TAG);
    if (intentMetaData != null) {
        mMediaPlayerGlue.setTitle(intentMetaData.getMediaTitle());
        mMediaPlayerGlue.setSubtitle(intentMetaData.getMediaArtistName());
        mMediaPlayerGlue.getPlayerAdapter().setDataSource(
                Uri.parse(intentMetaData.getMediaSourcePath()));
    } else {
        mMediaPlayerGlue.setTitle("Diving with Sharks");
        mMediaPlayerGlue.setSubtitle("A Googler");
        mMediaPlayerGlue.getPlayerAdapter().setDataSource(Uri.parse(URL));
    }
    PlaybackSeekDiskDataProvider.setDemoSeekProvider(mMediaPlayerGlue);
    playWhenReady(mMediaPlayerGlue);
    setBackgroundType(BG_LIGHT);
}
 
Example #4
Source File: DetailViewExampleWithVideoBackgroundFragment.java    From leanback-showcase with Apache License 2.0 5 votes vote down vote up
private void playMainVideoOnBackground() {
    VideoMediaPlayerGlue<MediaPlayerAdapter> playerGlue = new VideoMediaPlayerGlue(
            getActivity(), new MediaPlayerAdapter(getActivity()));

    mDetailsBackground.setupVideoPlayback(playerGlue);
    playerGlue.setTitle(data.getTitle() + " (Main Video)");
    playerGlue.setSubtitle(data.getDescription());
    playerGlue.getPlayerAdapter().setDataSource(Uri.parse(data.getVideoUrl()));
    PlaybackSeekDiskDataProvider.setDemoSeekProvider(playerGlue);

    mDetailsBackground.switchToVideo();
}