Search in sources :

Example 1 with BandwidthMeter

use of com.google.android.exoplayer2.upstream.BandwidthMeter in project ExoPlayer by google.

the class ExoHostedTest method onStart.

// HostedTest implementation
@Override
public final void onStart(HostActivity host, Surface surface) {
    // Build the player.
    DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    trackSelector = buildTrackSelector(host, bandwidthMeter);
    String userAgent = "ExoPlayerPlaybackTests";
    DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = buildDrmSessionManager(userAgent);
    player = buildExoPlayer(host, surface, trackSelector, drmSessionManager);
    player.prepare(buildSource(host, Util.getUserAgent(host, userAgent), bandwidthMeter));
    player.addListener(this);
    player.setAudioDebugListener(this);
    player.setVideoDebugListener(this);
    player.setPlayWhenReady(true);
    actionHandler = new Handler();
    // Schedule any pending actions.
    if (pendingSchedule != null) {
        pendingSchedule.start(player, trackSelector, actionHandler);
        pendingSchedule = null;
    }
}
Also used : DefaultBandwidthMeter(com.google.android.exoplayer2.upstream.DefaultBandwidthMeter) FrameworkMediaCrypto(com.google.android.exoplayer2.drm.FrameworkMediaCrypto) Handler(android.os.Handler)

Example 2 with BandwidthMeter

use of com.google.android.exoplayer2.upstream.BandwidthMeter in project Signal-Android by signalapp.

the class VideoPlayer method setExoViewSource.

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);
}
Also used : DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) DefaultBandwidthMeter(com.google.android.exoplayer2.upstream.DefaultBandwidthMeter) DefaultLoadControl(com.google.android.exoplayer2.DefaultLoadControl) LoadControl(com.google.android.exoplayer2.LoadControl) TrackSelector(com.google.android.exoplayer2.trackselection.TrackSelector) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) AttachmentDataSourceFactory(org.thoughtcrime.securesms.video.exo.AttachmentDataSourceFactory) DefaultDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultDataSourceFactory) ExoPlayerFactory(com.google.android.exoplayer2.ExoPlayerFactory) ExtractorsFactory(com.google.android.exoplayer2.extractor.ExtractorsFactory) DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) ExtractorMediaSource(com.google.android.exoplayer2.source.ExtractorMediaSource) DefaultLoadControl(com.google.android.exoplayer2.DefaultLoadControl) ExtractorMediaSource(com.google.android.exoplayer2.source.ExtractorMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) ExtractorsFactory(com.google.android.exoplayer2.extractor.ExtractorsFactory) DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) DefaultDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultDataSourceFactory) BandwidthMeter(com.google.android.exoplayer2.upstream.BandwidthMeter) DefaultBandwidthMeter(com.google.android.exoplayer2.upstream.DefaultBandwidthMeter) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) TrackSelection(com.google.android.exoplayer2.trackselection.TrackSelection) AdaptiveTrackSelection(com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection) AttachmentDataSourceFactory(org.thoughtcrime.securesms.video.exo.AttachmentDataSourceFactory)

Example 3 with BandwidthMeter

use of com.google.android.exoplayer2.upstream.BandwidthMeter 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 4 with BandwidthMeter

use of com.google.android.exoplayer2.upstream.BandwidthMeter in project ExoPlayer by google.

the class AdaptiveTrackSelectionTest method builderCreateTrackSelections_withMultipleAdaptiveGroups_usesCorrectAdaptationCheckpoints.

@Test
public void builderCreateTrackSelections_withMultipleAdaptiveGroups_usesCorrectAdaptationCheckpoints() {
    Format group1Format1 = new Format.Builder().setAverageBitrate(500).build();
    Format group1Format2 = new Format.Builder().setAverageBitrate(1000).build();
    Format group2Format1 = new Format.Builder().setAverageBitrate(250).build();
    Format group2Format2 = new Format.Builder().setAverageBitrate(500).build();
    Format group2Format3 = new Format.Builder().setAverageBitrate(1250).build();
    Format group2UnusedFormat = new Format.Builder().setAverageBitrate(2000).build();
    Format fixedFormat = new Format.Builder().setAverageBitrate(5000).build();
    TrackGroup trackGroup1 = new TrackGroup(group1Format1, group1Format2);
    TrackGroup trackGroup2 = new TrackGroup(group2Format1, group2Format2, group2Format3, group2UnusedFormat);
    TrackGroup fixedGroup = new TrackGroup(fixedFormat);
    Definition definition1 = new Definition(trackGroup1, /* tracks...= */
    0, 1);
    Definition definition2 = new Definition(trackGroup2, /* tracks...= */
    0, 1, 2);
    Definition fixedDefinition = new Definition(fixedGroup, /* tracks...= */
    0);
    List<List<AdaptationCheckpoint>> checkPoints = new ArrayList<>();
    AdaptiveTrackSelection.Factory factory = new AdaptiveTrackSelection.Factory() {

        @Override
        protected AdaptiveTrackSelection createAdaptiveTrackSelection(TrackGroup group, int[] tracks, int type, BandwidthMeter bandwidthMeter, ImmutableList<AdaptationCheckpoint> adaptationCheckpoints) {
            checkPoints.add(adaptationCheckpoints);
            return super.createAdaptiveTrackSelection(group, tracks, TrackSelection.TYPE_UNSET, bandwidthMeter, adaptationCheckpoints);
        }
    };
    Timeline timeline = new FakeTimeline();
    factory.createTrackSelections(new Definition[] { null, definition1, fixedDefinition, definition2, null }, mockBandwidthMeter, new MediaSource.MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
    0)), timeline);
    assertThat(checkPoints).hasSize(2);
    assertThat(checkPoints.get(0)).containsExactly(new AdaptationCheckpoint(/* totalBandwidth= */
    0, /* allocatedBandwidth= */
    0), new AdaptationCheckpoint(/* totalBandwidth= */
    5750, /* allocatedBandwidth= */
    500), new AdaptationCheckpoint(/* totalBandwidth= */
    6000, /* allocatedBandwidth= */
    500), new AdaptationCheckpoint(/* totalBandwidth= */
    6500, /* allocatedBandwidth= */
    1000), new AdaptationCheckpoint(/* totalBandwidth= */
    7250, /* allocatedBandwidth= */
    1000), new AdaptationCheckpoint(/* totalBandwidth= */
    9500, /* allocatedBandwidth= */
    2000)).inOrder();
    assertThat(checkPoints.get(1)).containsExactly(new AdaptationCheckpoint(/* totalBandwidth= */
    0, /* allocatedBandwidth= */
    0), new AdaptationCheckpoint(/* totalBandwidth= */
    5750, /* allocatedBandwidth= */
    250), new AdaptationCheckpoint(/* totalBandwidth= */
    6000, /* allocatedBandwidth= */
    500), new AdaptationCheckpoint(/* totalBandwidth= */
    6500, /* allocatedBandwidth= */
    500), new AdaptationCheckpoint(/* totalBandwidth= */
    7250, /* allocatedBandwidth= */
    1250), new AdaptationCheckpoint(/* totalBandwidth= */
    9500, /* allocatedBandwidth= */
    2500)).inOrder();
}
Also used : AdaptationCheckpoint(com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection.AdaptationCheckpoint) ImmutableList(com.google.common.collect.ImmutableList) Definition(com.google.android.exoplayer2.trackselection.ExoTrackSelection.Definition) ArrayList(java.util.ArrayList) Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Format(com.google.android.exoplayer2.Format) MediaSource(com.google.android.exoplayer2.source.MediaSource) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) BandwidthMeter(com.google.android.exoplayer2.upstream.BandwidthMeter) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Test(org.junit.Test)

Example 5 with BandwidthMeter

use of com.google.android.exoplayer2.upstream.BandwidthMeter in project ExoPlayer by google.

the class AdaptiveTrackSelectionTest method builderCreateTrackSelections_withSingleAdaptiveGroup_usesCorrectAdaptationCheckpoints.

@Test
public void builderCreateTrackSelections_withSingleAdaptiveGroup_usesCorrectAdaptationCheckpoints() {
    Format formatFixed1 = new Format.Builder().setAverageBitrate(500).build();
    Format formatFixed2 = new Format.Builder().setAverageBitrate(1000).build();
    Format formatAdaptive1 = new Format.Builder().setAverageBitrate(2000).build();
    Format formatAdaptive2 = new Format.Builder().setAverageBitrate(3000).build();
    Format formatAdaptive3 = new Format.Builder().setAverageBitrate(4000).build();
    Format formatAdaptive4 = new Format.Builder().setAverageBitrate(5000).build();
    TrackGroup trackGroupMultipleFixed = new TrackGroup(formatFixed1, formatFixed2);
    TrackGroup trackGroupAdaptive = new TrackGroup(formatAdaptive1, formatAdaptive2, formatAdaptive3, formatAdaptive4);
    Definition definitionFixed1 = new Definition(trackGroupMultipleFixed, /* tracks...= */
    0);
    Definition definitionFixed2 = new Definition(trackGroupMultipleFixed, /* tracks...= */
    1);
    Definition definitionAdaptive = new Definition(trackGroupAdaptive, /* tracks...= */
    1, 2, 3);
    List<List<AdaptationCheckpoint>> checkPoints = new ArrayList<>();
    AdaptiveTrackSelection.Factory factory = new AdaptiveTrackSelection.Factory() {

        @Override
        protected AdaptiveTrackSelection createAdaptiveTrackSelection(TrackGroup group, int[] tracks, int type, BandwidthMeter bandwidthMeter, ImmutableList<AdaptationCheckpoint> adaptationCheckpoints) {
            checkPoints.add(adaptationCheckpoints);
            return super.createAdaptiveTrackSelection(group, tracks, TrackSelection.TYPE_UNSET, bandwidthMeter, adaptationCheckpoints);
        }
    };
    Timeline timeline = new FakeTimeline();
    factory.createTrackSelections(new Definition[] { null, definitionFixed1, null, definitionFixed2, definitionAdaptive }, mockBandwidthMeter, new MediaSource.MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
    0)), timeline);
    assertThat(checkPoints).hasSize(1);
    assertThat(checkPoints.get(0)).containsExactly(new AdaptationCheckpoint(/* totalBandwidth= */
    0, /* allocatedBandwidth= */
    0), new AdaptationCheckpoint(/* totalBandwidth= */
    4500, /* allocatedBandwidth= */
    3000), new AdaptationCheckpoint(/* totalBandwidth= */
    5500, /* allocatedBandwidth= */
    4000), new AdaptationCheckpoint(/* totalBandwidth= */
    6500, /* allocatedBandwidth= */
    5000), new AdaptationCheckpoint(/* totalBandwidth= */
    11500, /* allocatedBandwidth= */
    10000)).inOrder();
}
Also used : AdaptationCheckpoint(com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection.AdaptationCheckpoint) ImmutableList(com.google.common.collect.ImmutableList) Definition(com.google.android.exoplayer2.trackselection.ExoTrackSelection.Definition) ArrayList(java.util.ArrayList) Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Format(com.google.android.exoplayer2.Format) MediaSource(com.google.android.exoplayer2.source.MediaSource) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) BandwidthMeter(com.google.android.exoplayer2.upstream.BandwidthMeter) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Test(org.junit.Test)

Aggregations

MediaSource (com.google.android.exoplayer2.source.MediaSource)4 BandwidthMeter (com.google.android.exoplayer2.upstream.BandwidthMeter)4 DefaultBandwidthMeter (com.google.android.exoplayer2.upstream.DefaultBandwidthMeter)4 Test (org.junit.Test)4 ExoPlayerFactory (com.google.android.exoplayer2.ExoPlayerFactory)2 Format (com.google.android.exoplayer2.Format)2 LoadControl (com.google.android.exoplayer2.LoadControl)2 RenderersFactory (com.google.android.exoplayer2.RenderersFactory)2 Timeline (com.google.android.exoplayer2.Timeline)2 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)2 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)2 AdaptiveTrackSelection (com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection)2 AdaptationCheckpoint (com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection.AdaptationCheckpoint)2 Definition (com.google.android.exoplayer2.trackselection.ExoTrackSelection.Definition)2 DefaultDataSourceFactory (com.google.android.exoplayer2.upstream.DefaultDataSourceFactory)2 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AuthenticatorException (android.accounts.AuthenticatorException)1 OperationCanceledException (android.accounts.OperationCanceledException)1