Search in sources :

Example 1 with DefaultTrackSelector

use of com.google.android.exoplayer2.trackselection.DefaultTrackSelector in project react-native-video by react-native-community.

the class ReactExoplayerView method initializePlayer.

// Internal methods
private void initializePlayer() {
    if (player == null) {
        TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(BANDWIDTH_METER);
        trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
        player = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, new DefaultLoadControl());
        player.addListener(this);
        player.setMetadataOutput(this);
        exoPlayerView.setPlayer(player);
        if (isTimelineStatic) {
            if (playerPosition == C.TIME_UNSET) {
                player.seekToDefaultPosition(playerWindow);
            } else {
                player.seekTo(playerWindow, playerPosition);
            }
        }
        audioBecomingNoisyReceiver.setListener(this);
        setPlayWhenReady(!isPaused);
        playerNeedsSource = true;
    }
    if (playerNeedsSource && srcUri != null) {
        MediaSource mediaSource = buildMediaSource(srcUri, extension);
        mediaSource = repeat ? new LoopingMediaSource(mediaSource) : mediaSource;
        player.prepare(mediaSource, !shouldRestorePosition, true);
        playerNeedsSource = false;
        eventEmitter.loadStart();
        loadVideoStarted = true;
    }
}
Also used : HlsMediaSource(com.google.android.exoplayer2.source.hls.HlsMediaSource) DashMediaSource(com.google.android.exoplayer2.source.dash.DashMediaSource) ExtractorMediaSource(com.google.android.exoplayer2.source.ExtractorMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) LoopingMediaSource(com.google.android.exoplayer2.source.LoopingMediaSource) SsMediaSource(com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource) ExoPlayerFactory(com.google.android.exoplayer2.ExoPlayerFactory) DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) TrackSelection(com.google.android.exoplayer2.trackselection.TrackSelection) AdaptiveVideoTrackSelection(com.google.android.exoplayer2.trackselection.AdaptiveVideoTrackSelection) DefaultLoadControl(com.google.android.exoplayer2.DefaultLoadControl) LoopingMediaSource(com.google.android.exoplayer2.source.LoopingMediaSource)

Example 2 with DefaultTrackSelector

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

the class PlayerActivity method initializePlayer.

// Internal methods
private void initializePlayer() {
    Intent intent = getIntent();
    boolean needNewPlayer = player == null;
    if (needNewPlayer) {
        boolean preferExtensionDecoders = intent.getBooleanExtra(PREFER_EXTENSION_DECODERS, false);
        UUID drmSchemeUuid = intent.hasExtra(DRM_SCHEME_UUID_EXTRA) ? UUID.fromString(intent.getStringExtra(DRM_SCHEME_UUID_EXTRA)) : null;
        DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = null;
        if (drmSchemeUuid != null) {
            String drmLicenseUrl = intent.getStringExtra(DRM_LICENSE_URL);
            String[] keyRequestPropertiesArray = intent.getStringArrayExtra(DRM_KEY_REQUEST_PROPERTIES);
            try {
                drmSessionManager = buildDrmSessionManager(drmSchemeUuid, drmLicenseUrl, keyRequestPropertiesArray);
            } catch (UnsupportedDrmException e) {
                int errorStringId = Util.SDK_INT < 18 ? R.string.error_drm_not_supported : (e.reason == UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME ? R.string.error_drm_unsupported_scheme : R.string.error_drm_unknown);
                showToast(errorStringId);
                return;
            }
        }
        @SimpleExoPlayer.ExtensionRendererMode int extensionRendererMode = ((DemoApplication) getApplication()).useExtensionRenderers() ? (preferExtensionDecoders ? SimpleExoPlayer.EXTENSION_RENDERER_MODE_PREFER : SimpleExoPlayer.EXTENSION_RENDERER_MODE_ON) : SimpleExoPlayer.EXTENSION_RENDERER_MODE_OFF;
        TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
        trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
        trackSelectionHelper = new TrackSelectionHelper(trackSelector, videoTrackSelectionFactory);
        player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, new DefaultLoadControl(), drmSessionManager, extensionRendererMode);
        player.addListener(this);
        eventLogger = new EventLogger(trackSelector);
        player.addListener(eventLogger);
        player.setAudioDebugListener(eventLogger);
        player.setVideoDebugListener(eventLogger);
        player.setMetadataOutput(eventLogger);
        simpleExoPlayerView.setPlayer(player);
        player.setPlayWhenReady(shouldAutoPlay);
        debugViewHelper = new DebugTextViewHelper(player, debugTextView);
        debugViewHelper.start();
    }
    if (needNewPlayer || needRetrySource) {
        String action = intent.getAction();
        Uri[] uris;
        String[] extensions;
        if (ACTION_VIEW.equals(action)) {
            uris = new Uri[] { intent.getData() };
            extensions = new String[] { intent.getStringExtra(EXTENSION_EXTRA) };
        } else if (ACTION_VIEW_LIST.equals(action)) {
            String[] uriStrings = intent.getStringArrayExtra(URI_LIST_EXTRA);
            uris = new Uri[uriStrings.length];
            for (int i = 0; i < uriStrings.length; i++) {
                uris[i] = Uri.parse(uriStrings[i]);
            }
            extensions = intent.getStringArrayExtra(EXTENSION_LIST_EXTRA);
            if (extensions == null) {
                extensions = new String[uriStrings.length];
            }
        } else {
            showToast(getString(R.string.unexpected_intent_action, action));
            return;
        }
        if (Util.maybeRequestReadExternalStoragePermission(this, uris)) {
            // The player will be reinitialized if the permission is granted.
            return;
        }
        MediaSource[] mediaSources = new MediaSource[uris.length];
        for (int i = 0; i < uris.length; i++) {
            mediaSources[i] = buildMediaSource(uris[i], extensions[i]);
        }
        MediaSource mediaSource = mediaSources.length == 1 ? mediaSources[0] : new ConcatenatingMediaSource(mediaSources);
        boolean haveResumePosition = resumeWindow != C.INDEX_UNSET;
        if (haveResumePosition) {
            player.seekTo(resumeWindow, resumePosition);
        }
        player.prepare(mediaSource, !haveResumePosition, false);
        needRetrySource = false;
        updateButtonVisibilities();
    }
}
Also used : DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) ExoPlayerFactory(com.google.android.exoplayer2.ExoPlayerFactory) Intent(android.content.Intent) Uri(android.net.Uri) DefaultLoadControl(com.google.android.exoplayer2.DefaultLoadControl) DebugTextViewHelper(com.google.android.exoplayer2.ui.DebugTextViewHelper) FrameworkMediaCrypto(com.google.android.exoplayer2.drm.FrameworkMediaCrypto) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) DashMediaSource(com.google.android.exoplayer2.source.dash.DashMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) SsMediaSource(com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource) HlsMediaSource(com.google.android.exoplayer2.source.hls.HlsMediaSource) ExtractorMediaSource(com.google.android.exoplayer2.source.ExtractorMediaSource) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) UnsupportedDrmException(com.google.android.exoplayer2.drm.UnsupportedDrmException) UUID(java.util.UUID) TrackSelection(com.google.android.exoplayer2.trackselection.TrackSelection) AdaptiveTrackSelection(com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection)

Example 3 with DefaultTrackSelector

use of com.google.android.exoplayer2.trackselection.DefaultTrackSelector in project PreviewSeekBar by rubensousa.

the class ExoPlayerManager method createPreviewPlayer.

private SimpleExoPlayer createPreviewPlayer() {
    TrackSelection.Factory videoTrackSelectionFactory = new WorstVideoTrackSelection.Factory();
    TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
    LoadControl loadControl = new PreviewLoadControl();
    SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(previewPlayerView.getContext(), trackSelector, loadControl);
    player.setPlayWhenReady(false);
    player.prepare(mediaSourceBuilder.getMediaSource(true));
    return player;
}
Also used : SimpleExoPlayer(com.google.android.exoplayer2.SimpleExoPlayer) LoadControl(com.google.android.exoplayer2.LoadControl) DefaultLoadControl(com.google.android.exoplayer2.DefaultLoadControl) TrackSelector(com.google.android.exoplayer2.trackselection.TrackSelector) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) ExoPlayerFactory(com.google.android.exoplayer2.ExoPlayerFactory) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) TrackSelection(com.google.android.exoplayer2.trackselection.TrackSelection) AdaptiveVideoTrackSelection(com.google.android.exoplayer2.trackselection.AdaptiveVideoTrackSelection)

Example 4 with DefaultTrackSelector

use of com.google.android.exoplayer2.trackselection.DefaultTrackSelector in project PreviewSeekBar by rubensousa.

the class ExoPlayerManager method createFullPlayer.

private SimpleExoPlayer createFullPlayer() {
    TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(new DefaultBandwidthMeter());
    TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
    LoadControl loadControl = new DefaultLoadControl();
    SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(playerView.getContext(), trackSelector, loadControl);
    player.setPlayWhenReady(true);
    player.prepare(mediaSourceBuilder.getMediaSource(false));
    player.addListener(this);
    return player;
}
Also used : SimpleExoPlayer(com.google.android.exoplayer2.SimpleExoPlayer) DefaultBandwidthMeter(com.google.android.exoplayer2.upstream.DefaultBandwidthMeter) LoadControl(com.google.android.exoplayer2.LoadControl) DefaultLoadControl(com.google.android.exoplayer2.DefaultLoadControl) TrackSelector(com.google.android.exoplayer2.trackselection.TrackSelector) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) ExoPlayerFactory(com.google.android.exoplayer2.ExoPlayerFactory) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) TrackSelection(com.google.android.exoplayer2.trackselection.TrackSelection) AdaptiveVideoTrackSelection(com.google.android.exoplayer2.trackselection.AdaptiveVideoTrackSelection) DefaultLoadControl(com.google.android.exoplayer2.DefaultLoadControl)

Aggregations

DefaultLoadControl (com.google.android.exoplayer2.DefaultLoadControl)4 ExoPlayerFactory (com.google.android.exoplayer2.ExoPlayerFactory)4 DefaultTrackSelector (com.google.android.exoplayer2.trackselection.DefaultTrackSelector)4 TrackSelection (com.google.android.exoplayer2.trackselection.TrackSelection)4 AdaptiveVideoTrackSelection (com.google.android.exoplayer2.trackselection.AdaptiveVideoTrackSelection)3 LoadControl (com.google.android.exoplayer2.LoadControl)2 SimpleExoPlayer (com.google.android.exoplayer2.SimpleExoPlayer)2 DefaultExtractorsFactory (com.google.android.exoplayer2.extractor.DefaultExtractorsFactory)2 ExtractorMediaSource (com.google.android.exoplayer2.source.ExtractorMediaSource)2 MediaSource (com.google.android.exoplayer2.source.MediaSource)2 DashMediaSource (com.google.android.exoplayer2.source.dash.DashMediaSource)2 HlsMediaSource (com.google.android.exoplayer2.source.hls.HlsMediaSource)2 SsMediaSource (com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource)2 TrackSelector (com.google.android.exoplayer2.trackselection.TrackSelector)2 Intent (android.content.Intent)1 Uri (android.net.Uri)1 FrameworkMediaCrypto (com.google.android.exoplayer2.drm.FrameworkMediaCrypto)1 UnsupportedDrmException (com.google.android.exoplayer2.drm.UnsupportedDrmException)1 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)1 LoopingMediaSource (com.google.android.exoplayer2.source.LoopingMediaSource)1