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;
}
}
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);
}
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));
}
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();
}
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();
}
Aggregations