Search in sources :

Example 6 with TrackSelector

use of com.google.android.exoplayer2.trackselection.TrackSelector in project NewPipe by TeamNewPipe.

the class BasePlayer method initPlayer.

public void initPlayer() {
    if (DEBUG)
        Log.d(TAG, "initPlayer() called with: context = [" + context + "]");
    if (databaseUpdateReactor != null)
        databaseUpdateReactor.dispose();
    databaseUpdateReactor = new CompositeDisposable();
    final String userAgent = Downloader.USER_AGENT;
    final DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    dataSource = new PlayerDataSource(context, userAgent, bandwidthMeter);
    final AdaptiveTrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
    trackSelector = new CustomTrackSelector(trackSelectionFactory);
    final LoadControl loadControl = new LoadController(context);
    final RenderersFactory renderFactory = new DefaultRenderersFactory(context);
    simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(renderFactory, trackSelector, loadControl);
    simpleExoPlayer.addListener(this);
    simpleExoPlayer.setPlayWhenReady(true);
    simpleExoPlayer.setSeekParameters(PlayerHelper.getSeekParameters(context));
    audioReactor = new AudioReactor(context, simpleExoPlayer);
    mediaSessionManager = new MediaSessionManager(context, simpleExoPlayer, new BasePlayerMediaSession(this));
}
Also used : DefaultBandwidthMeter(com.google.android.exoplayer2.upstream.DefaultBandwidthMeter) LoadControl(com.google.android.exoplayer2.LoadControl) RenderersFactory(com.google.android.exoplayer2.RenderersFactory) ExoPlayerFactory(com.google.android.exoplayer2.ExoPlayerFactory) DefaultRenderersFactory(com.google.android.exoplayer2.DefaultRenderersFactory) MediaSessionManager(org.schabi.newpipe.player.helper.MediaSessionManager) PlayerHelper.getTimeString(org.schabi.newpipe.player.helper.PlayerHelper.getTimeString) RenderersFactory(com.google.android.exoplayer2.RenderersFactory) DefaultRenderersFactory(com.google.android.exoplayer2.DefaultRenderersFactory) AudioReactor(org.schabi.newpipe.player.helper.AudioReactor) BasePlayerMediaSession(org.schabi.newpipe.player.playback.BasePlayerMediaSession) PlayerDataSource(org.schabi.newpipe.player.helper.PlayerDataSource) AdaptiveTrackSelection(com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection) CustomTrackSelector(org.schabi.newpipe.player.playback.CustomTrackSelector) DefaultRenderersFactory(com.google.android.exoplayer2.DefaultRenderersFactory) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) LoadController(org.schabi.newpipe.player.helper.LoadController)

Example 7 with TrackSelector

use of com.google.android.exoplayer2.trackselection.TrackSelector in project NewPipe by TeamNewPipe.

the class VideoPlayer method onTextTrackUpdate.

/*//////////////////////////////////////////////////////////////////////////
    // ExoPlayer Track Updates
    //////////////////////////////////////////////////////////////////////////*/
private void onTextTrackUpdate() {
    final int textRenderer = getRendererIndex(C.TRACK_TYPE_TEXT);
    if (captionTextView == null)
        return;
    if (trackSelector == null || trackSelector.getCurrentMappedTrackInfo() == null || textRenderer == RENDERER_UNAVAILABLE) {
        captionTextView.setVisibility(View.GONE);
        return;
    }
    final TrackGroupArray textTracks = trackSelector.getCurrentMappedTrackInfo().getTrackGroups(textRenderer);
    // Extract all loaded languages
    List<String> availableLanguages = new ArrayList<>(textTracks.length);
    for (int i = 0; i < textTracks.length; i++) {
        final TrackGroup textTrack = textTracks.get(i);
        if (textTrack.length > 0 && textTrack.getFormat(0) != null) {
            availableLanguages.add(textTrack.getFormat(0).language);
        }
    }
    // Normalize mismatching language strings
    final String preferredLanguage = trackSelector.getPreferredTextLanguage();
    // Build UI
    buildCaptionMenu(availableLanguages);
    if (trackSelector.getRendererDisabled(textRenderer) || preferredLanguage == null || !availableLanguages.contains(preferredLanguage)) {
        captionTextView.setText(R.string.caption_none);
    } else {
        captionTextView.setText(preferredLanguage);
    }
    captionTextView.setVisibility(availableLanguages.isEmpty() ? View.GONE : View.VISIBLE);
}
Also used : TrackGroup(com.google.android.exoplayer2.source.TrackGroup) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) ArrayList(java.util.ArrayList) PlayerHelper.getTimeString(org.schabi.newpipe.player.helper.PlayerHelper.getTimeString)

Example 8 with TrackSelector

use of com.google.android.exoplayer2.trackselection.TrackSelector in project android by owncloud.

the class PreviewVideoActivity method preparePlayer.

// Video player internal methods
private void preparePlayer() {
    // Create a default TrackSelector
    AdaptiveTrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory();
    trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
    player = new SimpleExoPlayer.Builder(this).setTrackSelector(trackSelector).setLoadControl(new DefaultLoadControl()).build();
    player.addListener(this);
    exoPlayerView.setPlayer(player);
    // Prepare video player asynchronously
    new PrepareVideoPlayerAsyncTask(getApplicationContext(), this, getFile(), getAccount()).execute();
}
Also used : AdaptiveTrackSelection(com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) DefaultLoadControl(com.google.android.exoplayer2.DefaultLoadControl)

Example 9 with TrackSelector

use of com.google.android.exoplayer2.trackselection.TrackSelector in project android by owncloud.

the class PreviewVideoFragment method preparePlayer.

// Video player internal methods
private void preparePlayer() {
    AdaptiveTrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory();
    trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
    // Video streaming is only supported at Jelly Bean or higher Android versions (>= API 16)
    // Create the player
    player = new SimpleExoPlayer.Builder(requireContext()).setTrackSelector(trackSelector).setLoadControl(new DefaultLoadControl()).build();
    player.addListener(this);
    // Bind the player to the view.
    exoPlayerView.setPlayer(player);
    // Prepare video player asynchronously
    new PrepareVideoPlayerAsyncTask(getActivity(), this, getFile(), mAccount).execute();
}
Also used : AdaptiveTrackSelection(com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) DefaultLoadControl(com.google.android.exoplayer2.DefaultLoadControl)

Example 10 with TrackSelector

use of com.google.android.exoplayer2.trackselection.TrackSelector in project ExoPlayer by google.

the class PlayerActivity method initializePlayer.

/**
 * @return Whether initialization was successful.
 */
protected boolean initializePlayer() {
    if (player == null) {
        Intent intent = getIntent();
        mediaItems = createMediaItems(intent);
        if (mediaItems.isEmpty()) {
            return false;
        }
        boolean preferExtensionDecoders = intent.getBooleanExtra(IntentUtil.PREFER_EXTENSION_DECODERS_EXTRA, false);
        RenderersFactory renderersFactory = DemoUtil.buildRenderersFactory(/* context= */
        this, preferExtensionDecoders);
        trackSelector = new DefaultTrackSelector(/* context= */
        this);
        lastSeenTracksInfo = TracksInfo.EMPTY;
        player = new ExoPlayer.Builder(/* context= */
        this).setRenderersFactory(renderersFactory).setMediaSourceFactory(createMediaSourceFactory()).setTrackSelector(trackSelector).build();
        player.setTrackSelectionParameters(trackSelectionParameters);
        player.addListener(new PlayerEventListener());
        player.addAnalyticsListener(new EventLogger(trackSelector));
        player.setAudioAttributes(AudioAttributes.DEFAULT, /* handleAudioFocus= */
        true);
        player.setPlayWhenReady(startAutoPlay);
        playerView.setPlayer(player);
        serverSideAdsLoader.setPlayer(player);
        debugViewHelper = new DebugTextViewHelper(player, debugTextView);
        debugViewHelper.start();
    }
    boolean haveStartPosition = startItemIndex != C.INDEX_UNSET;
    if (haveStartPosition) {
        player.seekTo(startItemIndex, startPosition);
    }
    player.setMediaItems(mediaItems, /* resetPosition= */
    !haveStartPosition);
    player.prepare();
    updateButtonVisibility();
    return true;
}
Also used : DebugTextViewHelper(com.google.android.exoplayer2.util.DebugTextViewHelper) EventLogger(com.google.android.exoplayer2.util.EventLogger) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) Intent(android.content.Intent) RenderersFactory(com.google.android.exoplayer2.RenderersFactory) ExoPlayer(com.google.android.exoplayer2.ExoPlayer)

Aggregations

DefaultTrackSelector (com.google.android.exoplayer2.trackselection.DefaultTrackSelector)16 DefaultLoadControl (com.google.android.exoplayer2.DefaultLoadControl)11 Test (org.junit.Test)10 MediaSource (com.google.android.exoplayer2.source.MediaSource)8 ExoPlayerFactory (com.google.android.exoplayer2.ExoPlayerFactory)7 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)7 AdaptiveTrackSelection (com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection)7 TrackSelection (com.google.android.exoplayer2.trackselection.TrackSelection)7 DefaultRenderersFactory (com.google.android.exoplayer2.DefaultRenderersFactory)6 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)6 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)5 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)5 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)5 TrackSelector (com.google.android.exoplayer2.trackselection.TrackSelector)5 LoadControl (com.google.android.exoplayer2.LoadControl)4 SimpleExoPlayer (com.google.android.exoplayer2.SimpleExoPlayer)4 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)4 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)4 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)4 ServerSideAdInsertionMediaSource (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource)4