Pass player and isTopLevelSource to MediaSource.prepareSource.
These additions are useful for sources that need to track the playback position and control playback. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=140828310
This commit is contained in:
parent
0a52e823de
commit
45bc4a0374
@ -208,7 +208,7 @@ public final class ExoPlayerTest extends TestCase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareSource(Listener listener) {
|
||||
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
|
||||
assertFalse(preparedSource);
|
||||
preparedSource = true;
|
||||
listener.onSourceInfoRefreshed(timeline, manifest);
|
||||
|
@ -95,7 +95,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||
};
|
||||
playbackInfo = new ExoPlayerImplInternal.PlaybackInfo(0, 0);
|
||||
internalPlayer = new ExoPlayerImplInternal(renderers, trackSelector, loadControl, playWhenReady,
|
||||
eventHandler, playbackInfo);
|
||||
eventHandler, playbackInfo, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -145,6 +145,7 @@ import java.io.IOException;
|
||||
private final Handler handler;
|
||||
private final HandlerThread internalPlaybackThread;
|
||||
private final Handler eventHandler;
|
||||
private final ExoPlayer player;
|
||||
private final Timeline.Window window;
|
||||
private final Timeline.Period period;
|
||||
|
||||
@ -174,7 +175,7 @@ import java.io.IOException;
|
||||
|
||||
public ExoPlayerImplInternal(Renderer[] renderers, TrackSelector trackSelector,
|
||||
LoadControl loadControl, boolean playWhenReady, Handler eventHandler,
|
||||
PlaybackInfo playbackInfo) {
|
||||
PlaybackInfo playbackInfo, ExoPlayer player) {
|
||||
this.renderers = renderers;
|
||||
this.trackSelector = trackSelector;
|
||||
this.loadControl = loadControl;
|
||||
@ -182,6 +183,7 @@ import java.io.IOException;
|
||||
this.eventHandler = eventHandler;
|
||||
this.state = ExoPlayer.STATE_IDLE;
|
||||
this.playbackInfo = playbackInfo;
|
||||
this.player = player;
|
||||
|
||||
rendererCapabilities = new RendererCapabilities[renderers.length];
|
||||
for (int i = 0; i < renderers.length; i++) {
|
||||
@ -382,7 +384,7 @@ import java.io.IOException;
|
||||
playbackInfo = new PlaybackInfo(0, C.TIME_UNSET);
|
||||
}
|
||||
this.mediaSource = mediaSource;
|
||||
mediaSource.prepareSource(this);
|
||||
mediaSource.prepareSource(player, true, this);
|
||||
setState(ExoPlayer.STATE_BUFFERING);
|
||||
handler.sendEmptyMessage(MSG_DO_SOME_WORK);
|
||||
}
|
||||
|
@ -26,7 +26,6 @@ import com.google.android.exoplayer2.extractor.Extractor;
|
||||
import com.google.android.exoplayer2.extractor.ExtractorInput;
|
||||
import com.google.android.exoplayer2.extractor.ExtractorOutput;
|
||||
import com.google.android.exoplayer2.extractor.ExtractorsFactory;
|
||||
import com.google.android.exoplayer2.extractor.MpegAudioHeader;
|
||||
import com.google.android.exoplayer2.extractor.PositionHolder;
|
||||
import com.google.android.exoplayer2.extractor.SeekMap;
|
||||
import com.google.android.exoplayer2.extractor.TrackOutput;
|
||||
@ -85,7 +84,6 @@ public final class MatroskaExtractor implements Extractor {
|
||||
private static final String CODEC_ID_VORBIS = "A_VORBIS";
|
||||
private static final String CODEC_ID_OPUS = "A_OPUS";
|
||||
private static final String CODEC_ID_AAC = "A_AAC";
|
||||
private static final String CODEC_ID_MP2 = "A_MPEG/L2";
|
||||
private static final String CODEC_ID_MP3 = "A_MPEG/L3";
|
||||
private static final String CODEC_ID_AC3 = "A_AC3";
|
||||
private static final String CODEC_ID_E_AC3 = "A_EAC3";
|
||||
@ -102,6 +100,7 @@ public final class MatroskaExtractor implements Extractor {
|
||||
|
||||
private static final int VORBIS_MAX_INPUT_SIZE = 8192;
|
||||
private static final int OPUS_MAX_INPUT_SIZE = 5760;
|
||||
private static final int MP3_MAX_INPUT_SIZE = 4096;
|
||||
private static final int ENCRYPTION_IV_SIZE = 8;
|
||||
private static final int TRACK_TYPE_AUDIO = 2;
|
||||
|
||||
@ -1219,7 +1218,6 @@ public final class MatroskaExtractor implements Extractor {
|
||||
|| CODEC_ID_OPUS.equals(codecId)
|
||||
|| CODEC_ID_VORBIS.equals(codecId)
|
||||
|| CODEC_ID_AAC.equals(codecId)
|
||||
|| CODEC_ID_MP2.equals(codecId)
|
||||
|| CODEC_ID_MP3.equals(codecId)
|
||||
|| CODEC_ID_AC3.equals(codecId)
|
||||
|| CODEC_ID_E_AC3.equals(codecId)
|
||||
@ -1405,13 +1403,9 @@ public final class MatroskaExtractor implements Extractor {
|
||||
mimeType = MimeTypes.AUDIO_AAC;
|
||||
initializationData = Collections.singletonList(codecPrivate);
|
||||
break;
|
||||
case CODEC_ID_MP2:
|
||||
mimeType = MimeTypes.AUDIO_MPEG_L2;
|
||||
maxInputSize = MpegAudioHeader.MAX_FRAME_SIZE_BYTES;
|
||||
break;
|
||||
case CODEC_ID_MP3:
|
||||
mimeType = MimeTypes.AUDIO_MPEG;
|
||||
maxInputSize = MpegAudioHeader.MAX_FRAME_SIZE_BYTES;
|
||||
maxInputSize = MP3_MAX_INPUT_SIZE;
|
||||
break;
|
||||
case CODEC_ID_AC3:
|
||||
mimeType = MimeTypes.AUDIO_AC3;
|
||||
|
@ -17,6 +17,7 @@ package com.google.android.exoplayer2.source;
|
||||
|
||||
import android.util.Pair;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
import com.google.android.exoplayer2.Timeline;
|
||||
import com.google.android.exoplayer2.upstream.Allocator;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
@ -53,12 +54,12 @@ public final class ConcatenatingMediaSource implements MediaSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareSource(Listener listener) {
|
||||
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
|
||||
this.listener = listener;
|
||||
for (int i = 0; i < mediaSources.length; i++) {
|
||||
if (!duplicateFlags[i]) {
|
||||
final int index = i;
|
||||
mediaSources[i].prepareSource(new Listener() {
|
||||
mediaSources[i].prepareSource(player, false, new Listener() {
|
||||
@Override
|
||||
public void onSourceInfoRefreshed(Timeline timeline, Object manifest) {
|
||||
handleSourceInfoRefreshed(index, timeline, manifest);
|
||||
|
@ -18,6 +18,7 @@ package com.google.android.exoplayer2.source;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
import com.google.android.exoplayer2.ParserException;
|
||||
import com.google.android.exoplayer2.Timeline;
|
||||
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
|
||||
@ -135,7 +136,7 @@ public final class ExtractorMediaSource implements MediaSource, MediaSource.List
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareSource(MediaSource.Listener listener) {
|
||||
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
|
||||
sourceListener = listener;
|
||||
timeline = new SinglePeriodTimeline(C.TIME_UNSET, false);
|
||||
listener.onSourceInfoRefreshed(timeline, null);
|
||||
|
@ -18,6 +18,7 @@ package com.google.android.exoplayer2.source;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
import com.google.android.exoplayer2.Timeline;
|
||||
import com.google.android.exoplayer2.upstream.Allocator;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
@ -59,8 +60,8 @@ public final class LoopingMediaSource implements MediaSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareSource(final Listener listener) {
|
||||
childSource.prepareSource(new Listener() {
|
||||
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, final Listener listener) {
|
||||
childSource.prepareSource(player, false, new Listener() {
|
||||
@Override
|
||||
public void onSourceInfoRefreshed(Timeline timeline, Object manifest) {
|
||||
childPeriodCount = timeline.getPeriodCount();
|
||||
|
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.google.android.exoplayer2.source;
|
||||
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
import com.google.android.exoplayer2.Timeline;
|
||||
import com.google.android.exoplayer2.upstream.Allocator;
|
||||
import java.io.IOException;
|
||||
@ -42,9 +43,14 @@ public interface MediaSource {
|
||||
/**
|
||||
* Starts preparation of the source.
|
||||
*
|
||||
* @param player The player for which this source is being prepared.
|
||||
* @param isTopLevelSource Whether this source has been passed directly to
|
||||
* {@link ExoPlayer#prepare(MediaSource)} or
|
||||
* {@link ExoPlayer#prepare(MediaSource, boolean, boolean)}. If {@code false}, this source is
|
||||
* being prepared by another source (e.g. {@link ConcatenatingMediaSource}) for composition.
|
||||
* @param listener The listener for source events.
|
||||
*/
|
||||
void prepareSource(Listener listener);
|
||||
void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener);
|
||||
|
||||
/**
|
||||
* Throws any pending error encountered while loading or refreshing source information.
|
||||
|
@ -16,6 +16,7 @@
|
||||
package com.google.android.exoplayer2.source;
|
||||
|
||||
import android.support.annotation.IntDef;
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
import com.google.android.exoplayer2.Timeline;
|
||||
import com.google.android.exoplayer2.upstream.Allocator;
|
||||
import java.io.IOException;
|
||||
@ -92,11 +93,11 @@ public final class MergingMediaSource implements MediaSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareSource(final Listener listener) {
|
||||
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, final Listener listener) {
|
||||
this.listener = listener;
|
||||
for (int i = 0; i < mediaSources.length; i++) {
|
||||
final int sourceIndex = i;
|
||||
mediaSources[sourceIndex].prepareSource(new Listener() {
|
||||
mediaSources[sourceIndex].prepareSource(player, false, new Listener() {
|
||||
@Override
|
||||
public void onSourceInfoRefreshed(Timeline timeline, Object manifest) {
|
||||
handleSourceInfoRefreshed(sourceIndex, timeline, manifest);
|
||||
|
@ -17,6 +17,7 @@ package com.google.android.exoplayer2.source;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.Timeline;
|
||||
import com.google.android.exoplayer2.upstream.Allocator;
|
||||
@ -84,7 +85,7 @@ public final class SingleSampleMediaSource implements MediaSource {
|
||||
// MediaSource implementation.
|
||||
|
||||
@Override
|
||||
public void prepareSource(MediaSource.Listener listener) {
|
||||
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
|
||||
listener.onSourceInfoRefreshed(timeline, null);
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
import com.google.android.exoplayer2.ParserException;
|
||||
import com.google.android.exoplayer2.Timeline;
|
||||
import com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener;
|
||||
@ -94,7 +95,7 @@ public final class DashMediaSource implements MediaSource {
|
||||
private final Runnable refreshManifestRunnable;
|
||||
private final Runnable simulateManifestRefreshRunnable;
|
||||
|
||||
private MediaSource.Listener sourceListener;
|
||||
private Listener sourceListener;
|
||||
private DataSource dataSource;
|
||||
private Loader loader;
|
||||
private LoaderErrorThrower loaderErrorThrower;
|
||||
@ -258,7 +259,7 @@ public final class DashMediaSource implements MediaSource {
|
||||
// MediaSource implementation.
|
||||
|
||||
@Override
|
||||
public void prepareSource(MediaSource.Listener listener) {
|
||||
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
|
||||
sourceListener = listener;
|
||||
if (sideloadedManifest) {
|
||||
loaderErrorThrower = new LoaderErrorThrower.Dummy();
|
||||
|
@ -18,6 +18,7 @@ package com.google.android.exoplayer2.source.hls;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
import com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener;
|
||||
import com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener.EventDispatcher;
|
||||
import com.google.android.exoplayer2.source.MediaPeriod;
|
||||
@ -48,7 +49,7 @@ public final class HlsMediaSource implements MediaSource,
|
||||
private final EventDispatcher eventDispatcher;
|
||||
|
||||
private HlsPlaylistTracker playlistTracker;
|
||||
private MediaSource.Listener sourceListener;
|
||||
private Listener sourceListener;
|
||||
|
||||
public HlsMediaSource(Uri manifestUri, DataSource.Factory dataSourceFactory, Handler eventHandler,
|
||||
AdaptiveMediaSourceEventListener eventListener) {
|
||||
@ -66,7 +67,7 @@ public final class HlsMediaSource implements MediaSource,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareSource(MediaSource.Listener listener) {
|
||||
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
|
||||
Assertions.checkState(playlistTracker == null);
|
||||
playlistTracker = new HlsPlaylistTracker(manifestUri, dataSourceFactory, eventDispatcher,
|
||||
minLoadableRetryCount, this);
|
||||
|
@ -19,6 +19,7 @@ import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.SystemClock;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
import com.google.android.exoplayer2.ParserException;
|
||||
import com.google.android.exoplayer2.Timeline;
|
||||
import com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener;
|
||||
@ -73,7 +74,7 @@ public final class SsMediaSource implements MediaSource,
|
||||
private final SsManifestParser manifestParser;
|
||||
private final ArrayList<SsMediaPeriod> mediaPeriods;
|
||||
|
||||
private MediaSource.Listener sourceListener;
|
||||
private Listener sourceListener;
|
||||
private DataSource manifestDataSource;
|
||||
private Loader manifestLoader;
|
||||
private LoaderErrorThrower manifestLoaderErrorThrower;
|
||||
@ -199,7 +200,7 @@ public final class SsMediaSource implements MediaSource,
|
||||
// MediaSource implementation.
|
||||
|
||||
@Override
|
||||
public void prepareSource(MediaSource.Listener listener) {
|
||||
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
|
||||
sourceListener = listener;
|
||||
if (manifest != null) {
|
||||
manifestLoaderErrorThrower = new LoaderErrorThrower.Dummy();
|
||||
|
@ -472,16 +472,6 @@ public final class SimpleExoPlayerView extends FrameLayout {
|
||||
return overlayFrameLayout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link SubtitleView}.
|
||||
*
|
||||
* @return The {@link SubtitleView}, or {@code null} if the layout has been customized and the
|
||||
* subtitle view is not present.
|
||||
*/
|
||||
public SubtitleView getSubtitleView() {
|
||||
return subtitleView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
if (!useController || player == null || ev.getActionMasked() != MotionEvent.ACTION_DOWN) {
|
||||
@ -504,11 +494,6 @@ public final class SimpleExoPlayerView extends FrameLayout {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
return useController ? controller.dispatchKeyEvent(event) : super.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
private void maybeShowController(boolean isForced) {
|
||||
if (!useController || player == null) {
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user