com.google.android.exoplayer2.trackselection.DefaultTrackSelector Java Examples
The following examples show how to use
com.google.android.exoplayer2.trackselection.DefaultTrackSelector.
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: TubiPlayerActivity.java From TubiPlayer with MIT License | 6 votes |
protected void initMoviePlayer() { // 1. Create a default TrackSelector mMainHandler = new Handler(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); // 3. Create the mMoviePlayer mMoviePlayer = ExoPlayerFactory.newSimpleInstance(this, mTrackSelector); mEventLogger = new EventLogger(mTrackSelector); mMoviePlayer.addAnalyticsListener(mEventLogger); mMoviePlayer.addMetadataOutput(mEventLogger); mTubiPlayerView.setPlayer(mMoviePlayer, this); mTubiPlayerView.setMediaModel(mediaModel); }
Example #2
Source File: DownloadHelper.java From MediaSDK with Apache License 2.0 | 6 votes |
/** * Creates a {@link DownloadHelper} for HLS streams. * * @param uri A playlist {@link Uri}. * @param dataSourceFactory A {@link DataSource.Factory} used to load the playlist. * @param renderersFactory A {@link RenderersFactory} creating the renderers for which tracks are * selected. * @param drmSessionManager An optional {@link DrmSessionManager} used by the renderers created by * {@code renderersFactory}. * @param trackSelectorParameters {@link DefaultTrackSelector.Parameters} for selecting tracks for * downloading. * @return A {@link DownloadHelper} for HLS streams. * @throws IllegalStateException If the HLS module is missing. */ public static DownloadHelper forHls( Uri uri, DataSource.Factory dataSourceFactory, RenderersFactory renderersFactory, @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager, DefaultTrackSelector.Parameters trackSelectorParameters) { return new DownloadHelper( DownloadRequest.TYPE_HLS, uri, /* cacheKey= */ null, createMediaSourceInternal( HLS_FACTORY_CONSTRUCTOR, uri, dataSourceFactory, /* streamKeys= */ null), trackSelectorParameters, Util.getRendererCapabilities(renderersFactory, drmSessionManager)); }
Example #3
Source File: DownloadHelper.java From MediaSDK with Apache License 2.0 | 6 votes |
/** * Creates a {@link DownloadHelper} for SmoothStreaming streams. * * @param uri A manifest {@link Uri}. * @param dataSourceFactory A {@link DataSource.Factory} used to load the manifest. * @param renderersFactory A {@link RenderersFactory} creating the renderers for which tracks are * selected. * @param drmSessionManager An optional {@link DrmSessionManager} used by the renderers created by * {@code renderersFactory}. * @param trackSelectorParameters {@link DefaultTrackSelector.Parameters} for selecting tracks for * downloading. * @return A {@link DownloadHelper} for SmoothStreaming streams. * @throws IllegalStateException If the SmoothStreaming module is missing. */ public static DownloadHelper forSmoothStreaming( Uri uri, DataSource.Factory dataSourceFactory, RenderersFactory renderersFactory, @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager, DefaultTrackSelector.Parameters trackSelectorParameters) { return new DownloadHelper( DownloadRequest.TYPE_SS, uri, /* cacheKey= */ null, createMediaSourceInternal( SS_FACTORY_CONSTRUCTOR, uri, dataSourceFactory, /* streamKeys= */ null), trackSelectorParameters, Util.getRendererCapabilities(renderersFactory, drmSessionManager)); }
Example #4
Source File: CompositeTrackSelectorCreator.java From no-player with Apache License 2.0 | 6 votes |
CompositeTrackSelector create(Options options, DefaultBandwidthMeter bandwidthMeter) { TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory( bandwidthMeter, options.minDurationBeforeQualityIncreaseInMillis(), AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS, AdaptiveTrackSelection.DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS, AdaptiveTrackSelection.DEFAULT_BANDWIDTH_FRACTION, AdaptiveTrackSelection.DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE, AdaptiveTrackSelection.DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS, Clock.DEFAULT ); DefaultTrackSelector trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory); DefaultTrackSelector.Parameters trackSelectorParameters = trackSelector.buildUponParameters() .setMaxVideoBitrate(options.maxVideoBitrate()) .build(); trackSelector.setParameters(trackSelectorParameters); ExoPlayerTrackSelector exoPlayerTrackSelector = ExoPlayerTrackSelector.newInstance(trackSelector); ExoPlayerAudioTrackSelector audioTrackSelector = new ExoPlayerAudioTrackSelector(exoPlayerTrackSelector); ExoPlayerVideoTrackSelector videoTrackSelector = new ExoPlayerVideoTrackSelector(exoPlayerTrackSelector); ExoPlayerSubtitleTrackSelector subtitleTrackSelector = new ExoPlayerSubtitleTrackSelector(exoPlayerTrackSelector); return new CompositeTrackSelector(trackSelector, audioTrackSelector, videoTrackSelector, subtitleTrackSelector); }
Example #5
Source File: DownloadHelper.java From MediaSDK with Apache License 2.0 | 6 votes |
/** * Creates a {@link DownloadHelper} for DASH streams. * * @param uri A manifest {@link Uri}. * @param dataSourceFactory A {@link DataSource.Factory} used to load the manifest. * @param renderersFactory A {@link RenderersFactory} creating the renderers for which tracks are * selected. * @param drmSessionManager An optional {@link DrmSessionManager} used by the renderers created by * {@code renderersFactory}. * @param trackSelectorParameters {@link DefaultTrackSelector.Parameters} for selecting tracks for * downloading. * @return A {@link DownloadHelper} for DASH streams. * @throws IllegalStateException If the DASH module is missing. */ public static DownloadHelper forDash( Uri uri, DataSource.Factory dataSourceFactory, RenderersFactory renderersFactory, @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager, DefaultTrackSelector.Parameters trackSelectorParameters) { return new DownloadHelper( DownloadRequest.TYPE_DASH, uri, /* cacheKey= */ null, createMediaSourceInternal( DASH_FACTORY_CONSTRUCTOR, uri, dataSourceFactory, /* streamKeys= */ null), trackSelectorParameters, Util.getRendererCapabilities(renderersFactory, drmSessionManager)); }
Example #6
Source File: DownloadHelper.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
/** * Creates download helper. * * @param downloadType A download type. This value will be used as {@link DownloadRequest#type}. * @param uri A {@link Uri}. * @param cacheKey An optional cache key. * @param mediaSource A {@link MediaSource} for which tracks are selected, or null if no track * selection needs to be made. * @param trackSelectorParameters {@link DefaultTrackSelector.Parameters} for selecting tracks for * downloading. * @param rendererCapabilities The {@link RendererCapabilities} of the renderers for which tracks * are selected. */ public DownloadHelper( String downloadType, Uri uri, @Nullable String cacheKey, @Nullable MediaSource mediaSource, DefaultTrackSelector.Parameters trackSelectorParameters, RendererCapabilities[] rendererCapabilities) { this.downloadType = downloadType; this.uri = uri; this.cacheKey = cacheKey; this.mediaSource = mediaSource; this.trackSelector = new DefaultTrackSelector(new DownloadTrackSelection.Factory()); this.rendererCapabilities = rendererCapabilities; this.scratchSet = new SparseIntArray(); trackSelector.setParameters(trackSelectorParameters); trackSelector.init(/* listener= */ () -> {}, new DummyBandwidthMeter()); callbackHandler = new Handler(Util.getLooper()); }
Example #7
Source File: ExoMediaPlayer.java From ExoMedia with Apache License 2.0 | 6 votes |
public void setRendererEnabled(@NonNull RendererType type, boolean enabled) { MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo(); ExoPlayerRendererTracksInfo tracksInfo = getExoPlayerTracksInfo(type, 0, mappedTrackInfo); if (!tracksInfo.rendererTrackIndexes.isEmpty()) { boolean enabledSomething = false; DefaultTrackSelector.ParametersBuilder parametersBuilder = trackSelector.buildUponParameters(); for (int rendererTrackIndex : tracksInfo.rendererTrackIndexes) { if (enabled) { DefaultTrackSelector.SelectionOverride selectionOverride = trackSelector.getParameters().getSelectionOverride(rendererTrackIndex, mappedTrackInfo.getTrackGroups(rendererTrackIndex)); // check whether the renderer has been selected before // other renderers should be kept disabled to avoid playback errors if (selectionOverride != null) { parametersBuilder.setRendererDisabled(rendererTrackIndex, false); enabledSomething = true; } } else { parametersBuilder.setRendererDisabled(rendererTrackIndex, true); } } if (enabled && !enabledSomething) { // if nothing has been enabled enable the first sequential renderer parametersBuilder.setRendererDisabled(tracksInfo.rendererTrackIndexes.get(0), false); } trackSelector.setParameters(parametersBuilder); } }
Example #8
Source File: DownloadHelper.java From MediaSDK with Apache License 2.0 | 6 votes |
/** * Convenience method to add a selection of tracks to be downloaded for a single renderer. Must * not be called until after preparation completes. * * @param periodIndex The period index the track selection is added for. * @param rendererIndex The renderer index the track selection is added for. * @param trackSelectorParameters The {@link DefaultTrackSelector.Parameters} to obtain the new * selection of tracks. * @param overrides A list of {@link SelectionOverride SelectionOverrides} to apply to the {@code * trackSelectorParameters}. If empty, {@code trackSelectorParameters} are used as they are. */ public void addTrackSelectionForSingleRenderer( int periodIndex, int rendererIndex, DefaultTrackSelector.Parameters trackSelectorParameters, List<SelectionOverride> overrides) { assertPreparedWithMedia(); DefaultTrackSelector.ParametersBuilder builder = trackSelectorParameters.buildUpon(); for (int i = 0; i < mappedTrackInfos[periodIndex].getRendererCount(); i++) { builder.setRendererDisabled(/* rendererIndex= */ i, /* disabled= */ i != rendererIndex); } if (overrides.isEmpty()) { addTrackSelection(periodIndex, builder.build()); } else { TrackGroupArray trackGroupArray = mappedTrackInfos[periodIndex].getTrackGroups(rendererIndex); for (int i = 0; i < overrides.size(); i++) { builder.setSelectionOverride(rendererIndex, trackGroupArray, overrides.get(i)); addTrackSelection(periodIndex, builder.build()); } } }
Example #9
Source File: DownloadHelper.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
/** * Convenience method to add selections of tracks for all specified audio languages. If an audio * track in one of the specified languages is not available, the default fallback audio track is * used instead. Must not be called until after preparation completes. * * @param languages A list of audio languages for which tracks should be added to the download * selection, as IETF BCP 47 conformant tags. */ public void addAudioLanguagesToSelection(String... languages) { assertPreparedWithMedia(); for (int periodIndex = 0; periodIndex < mappedTrackInfos.length; periodIndex++) { DefaultTrackSelector.ParametersBuilder parametersBuilder = DEFAULT_TRACK_SELECTOR_PARAMETERS.buildUpon(); MappedTrackInfo mappedTrackInfo = mappedTrackInfos[periodIndex]; int rendererCount = mappedTrackInfo.getRendererCount(); for (int rendererIndex = 0; rendererIndex < rendererCount; rendererIndex++) { if (mappedTrackInfo.getRendererType(rendererIndex) != C.TRACK_TYPE_AUDIO) { parametersBuilder.setRendererDisabled(rendererIndex, /* disabled= */ true); } } for (String language : languages) { parametersBuilder.setPreferredAudioLanguage(language); addTrackSelection(periodIndex, parametersBuilder.build()); } } }
Example #10
Source File: DownloadHelper.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
/** * Convenience method to add selections of tracks for all specified text languages. Must not be * called until after preparation completes. * * @param selectUndeterminedTextLanguage Whether a text track with undetermined language should be * selected for downloading if no track with one of the specified {@code languages} is * available. * @param languages A list of text languages for which tracks should be added to the download * selection, as IETF BCP 47 conformant tags. */ public void addTextLanguagesToSelection( boolean selectUndeterminedTextLanguage, String... languages) { assertPreparedWithMedia(); for (int periodIndex = 0; periodIndex < mappedTrackInfos.length; periodIndex++) { DefaultTrackSelector.ParametersBuilder parametersBuilder = DEFAULT_TRACK_SELECTOR_PARAMETERS.buildUpon(); MappedTrackInfo mappedTrackInfo = mappedTrackInfos[periodIndex]; int rendererCount = mappedTrackInfo.getRendererCount(); for (int rendererIndex = 0; rendererIndex < rendererCount; rendererIndex++) { if (mappedTrackInfo.getRendererType(rendererIndex) != C.TRACK_TYPE_TEXT) { parametersBuilder.setRendererDisabled(rendererIndex, /* disabled= */ true); } } parametersBuilder.setSelectUndeterminedTextLanguage(selectUndeterminedTextLanguage); for (String language : languages) { parametersBuilder.setPreferredTextLanguage(language); addTrackSelection(periodIndex, parametersBuilder.build()); } } }
Example #11
Source File: PlayerActivity.java From GPUVideo-android with MIT License | 6 votes |
private void setUpSimpleExoPlayer() { TrackSelector trackSelector = new DefaultTrackSelector(); // Measures bandwidth during playback. Can be null if not required. DefaultBandwidthMeter defaultBandwidthMeter = new DefaultBandwidthMeter(); // Produces DataSource instances through which media data is loaded. DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "yourApplicationName"), defaultBandwidthMeter); MediaSource mediaSource = new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(STREAM_URL_MP4_VOD_LONG)); // SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(this, trackSelector); // Prepare the player with the source. player.prepare(mediaSource); player.setPlayWhenReady(true); }
Example #12
Source File: AudioSlidePlayer.java From deltachat-android with GNU General Public License v3.0 | 6 votes |
public void requestDuration() { try { LoadControl loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE).createDefaultLoadControl(); durationCalculator = ExoPlayerFactory.newSimpleInstance(context, new DefaultRenderersFactory(context), new DefaultTrackSelector(), loadControl); durationCalculator.setPlayWhenReady(false); durationCalculator.addListener(new Player.EventListener() { @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { if (playbackState == Player.STATE_READY) { Util.runOnMain(() -> { Log.d(TAG, "request duration " + durationCalculator.getDuration()); getListener().onReceivedDuration(Long.valueOf(durationCalculator.getDuration()).intValue()); durationCalculator.release(); durationCalculator.removeListener(this); durationCalculator = null; }); } } }); durationCalculator.prepare(createMediaSource(slide.getUri())); } catch (Exception e) { Log.w(TAG, e); getListener().onReceivedDuration(0); } }
Example #13
Source File: TrackSelectionHelper.java From leafpicrevived with GNU General Public License v3.0 | 6 votes |
@Override public void onClick(DialogInterface dialog, int which) { DefaultTrackSelector.ParametersBuilder parametersBuilder = DEFAULT_TRACK_SELECTOR_PARAMETERS.buildUpon(); MappedTrackInfo mappedTrackInfo = this.trackInfo; int rendererCount = trackInfo.getRendererCount(); for (int rendererIndex = 0; rendererIndex < rendererCount; rendererIndex++) { if (trackInfo.getRendererType(rendererIndex) != C.TRACK_TYPE_TEXT) { parametersBuilder.setRendererDisabled(rendererIndex, true); } if (override != null) { parametersBuilder.setSelectionOverride(rendererIndex, trackGroups, override); } else { parametersBuilder.clearSelectionOverrides(rendererIndex); } } // @TODO fix this // mappedTrackInfo.setParameters(parametersBuilder.build()); }
Example #14
Source File: DownloadHelper.java From Telegram with GNU General Public License v2.0 | 6 votes |
/** * Convenience method to add a selection of tracks to be downloaded for a single renderer. Must * not be called until after preparation completes. * * @param periodIndex The period index the track selection is added for. * @param rendererIndex The renderer index the track selection is added for. * @param trackSelectorParameters The {@link DefaultTrackSelector.Parameters} to obtain the new * selection of tracks. * @param overrides A list of {@link SelectionOverride SelectionOverrides} to apply to the {@code * trackSelectorParameters}. If empty, {@code trackSelectorParameters} are used as they are. */ public void addTrackSelectionForSingleRenderer( int periodIndex, int rendererIndex, DefaultTrackSelector.Parameters trackSelectorParameters, List<SelectionOverride> overrides) { assertPreparedWithMedia(); DefaultTrackSelector.ParametersBuilder builder = trackSelectorParameters.buildUpon(); for (int i = 0; i < mappedTrackInfos[periodIndex].getRendererCount(); i++) { builder.setRendererDisabled(/* rendererIndex= */ i, /* disabled= */ i != rendererIndex); } if (overrides.isEmpty()) { addTrackSelection(periodIndex, builder.build()); } else { TrackGroupArray trackGroupArray = mappedTrackInfos[periodIndex].getTrackGroups(rendererIndex); for (int i = 0; i < overrides.size(); i++) { builder.setSelectionOverride(rendererIndex, trackGroupArray, overrides.get(i)); addTrackSelection(periodIndex, builder.build()); } } }
Example #15
Source File: MainActivity.java From ExoplayerExample with The Unlicense | 6 votes |
/** * Prepares exoplayer for audio playback from a local file * @param uri */ private void prepareExoPlayerFromFileUri(Uri uri){ exoPlayer = ExoPlayerFactory.newSimpleInstance(this, new DefaultTrackSelector(null), new DefaultLoadControl()); exoPlayer.addListener(eventListener); DataSpec dataSpec = new DataSpec(uri); final FileDataSource fileDataSource = new FileDataSource(); try { fileDataSource.open(dataSpec); } catch (FileDataSource.FileDataSourceException e) { e.printStackTrace(); } DataSource.Factory factory = new DataSource.Factory() { @Override public DataSource createDataSource() { return fileDataSource; } }; MediaSource audioSource = new ExtractorMediaSource(fileDataSource.getUri(), factory, new DefaultExtractorsFactory(), null, null); exoPlayer.prepare(audioSource); initMediaControls(); }
Example #16
Source File: MainActivity.java From ExoplayerExample with The Unlicense | 6 votes |
/** * Prepares exoplayer for audio playback from a remote URL audiofile. Should work with most * popular audiofile types (.mp3, .m4a,...) * @param uri Provide a Uri in a form of Uri.parse("http://blabla.bleble.com/blublu.mp3) */ private void prepareExoPlayerFromURL(Uri uri){ TrackSelector trackSelector = new DefaultTrackSelector(); LoadControl loadControl = new DefaultLoadControl(); exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl); DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "exoplayer2example"), null); ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); MediaSource audioSource = new ExtractorMediaSource(uri, dataSourceFactory, extractorsFactory, null, null); exoPlayer.addListener(eventListener); exoPlayer.prepare(audioSource); initMediaControls(); }
Example #17
Source File: MainActivity.java From ExoplayerExample with The Unlicense | 6 votes |
private void prepareExoPlayerFromRawResourceUri(Uri uri){ exoPlayer = ExoPlayerFactory.newSimpleInstance(this, new DefaultTrackSelector(null), new DefaultLoadControl()); exoPlayer.addListener(eventListener); DataSpec dataSpec = new DataSpec(uri); final RawResourceDataSource rawResourceDataSource = new RawResourceDataSource(this); try { rawResourceDataSource.open(dataSpec); } catch (RawResourceDataSource.RawResourceDataSourceException e) { e.printStackTrace(); } DataSource.Factory factory = new DataSource.Factory() { @Override public DataSource createDataSource() { return rawResourceDataSource; } }; MediaSource audioSource = new ExtractorMediaSource(rawResourceDataSource.getUri(), factory, new DefaultExtractorsFactory(), null, null); exoPlayer.prepare(audioSource); initMediaControls(); }
Example #18
Source File: MediaPlayback21.java From Melophile with Apache License 2.0 | 6 votes |
@Override public void startPlayer() { if (exoPlayer == null) { exoPlayer = ExoPlayerFactory.newSimpleInstance( context, new DefaultTrackSelector(), new DefaultLoadControl()); exoPlayer.addListener(this); } exoPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory( context, Util.getUserAgent(context, "uamp"), null); ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); MediaSource mediaSource = new ExtractorMediaSource( Uri.parse(currentUrl), dataSourceFactory, extractorsFactory, null, null); exoPlayer.prepare(mediaSource); configPlayer(); }
Example #19
Source File: VideoPlayer.java From deltachat-android with GNU General Public License v3.0 | 6 votes |
private void setExoViewSource(@NonNull VideoSlide videoSource, boolean autoplay) throws IOException { BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); exoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl); exoPlayer.addListener(new ExoPlayerListener(window)); //noinspection ConstantConditions exoView.setPlayer(exoPlayer); DefaultDataSourceFactory defaultDataSourceFactory = new DefaultDataSourceFactory(getContext(), "GenericUserAgent", null); AttachmentDataSourceFactory attachmentDataSourceFactory = new AttachmentDataSourceFactory(getContext(), defaultDataSourceFactory, null); ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); MediaSource mediaSource = new ExtractorMediaSource(videoSource.getUri(), attachmentDataSourceFactory, extractorsFactory, null, null); exoPlayer.prepare(mediaSource); exoPlayer.setPlayWhenReady(autoplay); }
Example #20
Source File: VideoPlayerComponent.java From android-arch-components-lifecycle with Apache License 2.0 | 6 votes |
private void initializePlayer() { if (player == null) { trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(context, trackSelector); player.addListener(this); DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(context, Util.getUserAgent(context, "testApp"), bandwidthMeter); ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); ExtractorMediaSource videoSource = new ExtractorMediaSource(Uri.parse(videoUrl), dataSourceFactory, extractorsFactory, null, null); simpleExoPlayerView.setPlayer(player); player.setPlayWhenReady(true); boolean haveResumePosition = resumeWindow != C.INDEX_UNSET; if (haveResumePosition) { Log.d(TAG, "Have Resume position true!" + resumePosition); player.seekTo(resumeWindow, resumePosition); } player.prepare(videoSource, !haveResumePosition, false); } }
Example #21
Source File: ExoPlayer2Helper.java From mimi-reader with Apache License 2.0 | 6 votes |
public ExoPlayer2Helper(Context context) { DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); dataSourceFactory = new FileDataSourceFactory(this); extractorsFactory = new DefaultExtractorsFactory(); DefaultTrackSelector trackSelector = new DefaultTrackSelector(bandwidthMeter); DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(context); EventLogger eventLogger = new EventLogger(trackSelector); player = ExoPlayerFactory.newSimpleInstance(context, renderersFactory, trackSelector); player.addListener(this); player.addListener(eventLogger); player.setAudioDebugListener(eventLogger); player.setVideoDebugListener(eventLogger); player.setMetadataOutput(eventLogger); player.setVideoListener(this); }
Example #22
Source File: ExoMediaPlayer.java From ExoMedia with Apache License 2.0 | 6 votes |
public ExoMediaPlayer(@NonNull Context context) { this.context = context; bufferRepeater.setRepeaterDelay(BUFFER_REPEAT_DELAY); bufferRepeater.setRepeatListener(new BufferRepeatListener()); mainHandler = new Handler(); ComponentListener componentListener = new ComponentListener(); RendererProvider rendererProvider = new RendererProvider(context, mainHandler, componentListener, componentListener, componentListener, componentListener); DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = generateDrmSessionManager(); rendererProvider.setDrmSessionManager(drmSessionManager); renderers = rendererProvider.generate(); adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory); LoadControl loadControl = ExoMedia.Data.loadControl != null ? ExoMedia.Data.loadControl : new DefaultLoadControl(); player = ExoPlayerFactory.newInstance(renderers.toArray(new Renderer[renderers.size()]), trackSelector, loadControl); player.addListener(this); analyticsCollector = new AnalyticsCollector.Factory().createAnalyticsCollector(player, Clock.DEFAULT); player.addListener(analyticsCollector); setupDamSessionManagerAnalytics(drmSessionManager); }
Example #23
Source File: ExoMedia.java From QSVideoPlayer with Apache License 2.0 | 5 votes |
@Override public boolean doPrepar(Context context, String url, Map<String, String> headers, Object... objects) { release(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(BANDWIDTH_METER); DefaultTrackSelector trackSelector = new DefaultTrackSelector(mainThreadHandler, videoTrackSelectionFactory); simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(context, trackSelector, new DefaultLoadControl(), null, false); simpleExoPlayer.setPlayWhenReady(true); MediaSource mediaSource = buildMediaSource(context, Uri.parse(url)); simpleExoPlayer.addListener(ExoMedia.this); simpleExoPlayer.setVideoListener(ExoMedia.this); simpleExoPlayer.prepare(mediaSource, true, true); return true; }
Example #24
Source File: VideoExoPlayer.java From TigerVideo with Apache License 2.0 | 5 votes |
/**--------------------- 创建SimpleExoPlayer ----------------------------**/ private void initExoPlayer() { mMediaDataSourceFactory = buildDataSourceFactory(true); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); mEventLogger = new EventLogger(mTrackSelector); mMainHandler = new Handler(Looper.getMainLooper()); DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(mContext, null, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF); mExoPlayer = ExoPlayerFactory.newSimpleInstance(renderersFactory, mTrackSelector); mExoPlayer.addListener(mEventLogger); mExoPlayer.setAudioDebugListener(mEventLogger); mExoPlayer.setVideoDebugListener(mEventLogger); mExoPlayer.setMetadataOutput(mEventLogger); mExoPlayer.setTextOutput(null); mExoPlayer.setVideoListener(null); mExoPlayer.removeListener(this); mExoPlayer.setVideoTextureView(null); mExoPlayer.setVideoListener(this); mExoPlayer.addListener(this); mExoPlayer.setTextOutput(this); }
Example #25
Source File: ExoMediaPlayer.java From ExoMedia with Apache License 2.0 | 5 votes |
/** * Return true if at least one renderer for the given type is enabled * @param type The renderer type * @return true if at least one renderer for the given type is enabled */ public boolean isRendererEnabled(@NonNull RendererType type) { MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo(); ExoPlayerRendererTracksInfo tracksInfo = getExoPlayerTracksInfo(type, 0, mappedTrackInfo); DefaultTrackSelector.Parameters parameters = trackSelector.getParameters(); for (Integer rendererTrackIndex : tracksInfo.rendererTrackIndexes) { if (!parameters.getRendererDisabled(rendererTrackIndex)) { return true; } } return false; }
Example #26
Source File: ExoPlayerVideoTrackSelectorTest.java From no-player with Apache License 2.0 | 5 votes |
private ArgumentCaptor<DefaultTrackSelector.SelectionOverride> whenSelectingVideoTrack(PlayerVideoTrack videoTrack) { exoPlayerVideoTrackSelector.selectVideoTrack(videoTrack, rendererTypeRequester); ArgumentCaptor<DefaultTrackSelector.SelectionOverride> argumentCaptor = ArgumentCaptor.forClass(DefaultTrackSelector.SelectionOverride.class); verify(trackSelector).setSelectionOverride(eq(TrackType.VIDEO), any(RendererTypeRequester.class), any(TrackGroupArray.class), argumentCaptor.capture()); return argumentCaptor; }
Example #27
Source File: ExoPlayerVideoTrackSelectorTest.java From no-player with Apache License 2.0 | 5 votes |
@Test public void givenTrackSelectorContainsTracks_whenSelectingVideoTrack_thenSelectsTrack() { givenTrackSelectorContainsTracks(); ArgumentCaptor<DefaultTrackSelector.SelectionOverride> argumentCaptor = whenSelectingVideoTrack(ADDITIONAL_PLAYER_VIDEO_TRACK); DefaultTrackSelector.SelectionOverride selectionOverride = argumentCaptor.getValue(); assertThat(selectionOverride.groupIndex).isEqualTo(FIRST_GROUP); assertThat(selectionOverride.tracks).contains(SECOND_TRACK); }
Example #28
Source File: ExoPlayerHelper.java From ExoPlayer-Wrapper with Apache License 2.0 | 5 votes |
@Override public void createPlayer(boolean isToPrepare) { if (mExoPlayerListener != null) { mExoPlayerListener.createExoPlayerCalled(isToPrepare); } if (mPlayer != null) { return; } if (isThumbImageViewEnabled) { addThumbImageView(); } mPlayer = ExoPlayerFactory.newSimpleInstance( mContext, new DefaultRenderersFactory(mContext), new DefaultTrackSelector(), mLoadControl); mExoPlayerView.setPlayer(mPlayer); mExoPlayerView.setControllerShowTimeoutMs(1500); mExoPlayerView.setControllerHideOnTouch(false); mTempCurrentVolume = mPlayer.getVolume(); mPlayer.setRepeatMode(isRepeatModeOn ? Player.REPEAT_MODE_ALL : Player.REPEAT_MODE_OFF); mPlayer.setPlayWhenReady(isAutoPlayOn); mPlayer.addListener(this); createMediaSource(); if (isToPrepare) { preparePlayer(); } }
Example #29
Source File: ProviderTvPlayer.java From xipl with Apache License 2.0 | 5 votes |
/** * Initializes and prepares the player but doesn't make it play the content. * * @param context the context needed to initialize the player. */ private void init(Context context) { BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(context, trackSelector); player.prepare(getMediaSource(context)); }
Example #30
Source File: ExoPlayerTrackSelector.java From no-player with Apache License 2.0 | 5 votes |
boolean setSelectionOverride(TrackType trackType, RendererTypeRequester rendererTypeRequester, TrackGroupArray trackGroups, DefaultTrackSelector.SelectionOverride selectionOverride) { Optional<Integer> rendererIndex = rendererTrackIndexExtractor.extract(trackType, mappedTrackInfoLength(), rendererTypeRequester); if (rendererIndex.isPresent()) { trackSelector.setParameters(trackSelector .buildUponParameters() .setSelectionOverride(rendererIndex.get(), trackGroups, selectionOverride) ); return true; } else { return false; } }