com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector Java Examples

The following examples show how to use com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector. 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: StreamFragment.java    From Twire with GNU General Public License v3.0 6 votes vote down vote up
private void initializePlayer() {
    if (player == null) {
        player = new SimpleExoPlayer.Builder(getContext()).build();
        player.addListener(this);
        mVideoView.setPlayer(player);
        mVideoView.setPlaybackPreparer(this);

        if (currentMediaSource != null)
            player.prepare(currentMediaSource);

        mediaSession = new MediaSessionCompat(getContext(), getContext().getPackageName());
        MediaSessionConnector mediaSessionConnector = new MediaSessionConnector(mediaSession);
        mediaSessionConnector.setPlayer(player);
        mediaSession.setActive(true);

        progressHandler.postDelayed(progressRunnable, 1000);
    }
}
 
Example #2
Source File: MainActivity.java    From lbry-android with MIT License 5 votes vote down vote up
public void initMediaSession() {
    ComponentName mediaButtonReceiver = new ComponentName(getApplicationContext(), MediaButtonReceiver.class);
    mediaSession = new MediaSessionCompat(getApplicationContext(), "LBRYMediaSession", mediaButtonReceiver, null);
    MediaSessionConnector connector = new MediaSessionConnector(mediaSession);
    connector.setPlayer(MainActivity.appPlayer);
    mediaSession.setActive(true);
}
 
Example #3
Source File: Player.java    From zapp with MIT License 4 votes vote down vote up
public Player(Context context) {
	settings = new SettingsRepository(context);
	networkConnectionHelper = new NetworkConnectionHelper(context);

	String userAgent = Util.getUserAgent(context, context.getString(R.string.app_name));
	TransferListener transferListener = new OnlyWifiTransferListener();
	dataSourceFactory = new DefaultDataSourceFactory(context, userAgent, transferListener);
	TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory();
	DefaultTrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

	player = ExoPlayerFactory.newSimpleInstance(context, trackSelector);
	playerHandler = new Handler(player.getApplicationLooper());
	trackSelectorWrapper = new TrackSelectorWrapper(trackSelector);

	// media session setup
	mediaSession = new MediaSessionCompat(context, context.getPackageName());
	MediaSessionConnector mediaSessionConnector = new MediaSessionConnector(mediaSession);
	mediaSessionConnector.setPlayer(player, null);
	mediaSession.setActive(true);

	// audio focus setup
	AudioAttributes audioAttributes = new AudioAttributes.Builder()
		.setUsage(C.USAGE_MEDIA)
		.setContentType(C.CONTENT_TYPE_MOVIE)
		.build();
	player.setAudioAttributes(audioAttributes, true);

	playerEventHandler = new PlayerEventHandler();

	// enable subtitles
	enableSubtitles(settings.getEnableSubtitles());

	// wakelocks
	playerWakeLocks = new PlayerWakeLocks(context, "Zapp::Player");
	Disposable wakelockDisposable = playerEventHandler
		.getShouldHoldWakelock()
		.distinctUntilChanged()
		.subscribe(this::shouldHoldWakelockChanged);
	disposables.add(wakelockDisposable);

	// set listeners
	networkConnectionHelper.startListenForNetworkChanges(this::setStreamQualityByNetworkType);
}