Added loadErrorNotification to SingleSampleSource.

Also hooked up DemoPlayer to ExtractorSampleSource events.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=117809051
This commit is contained in:
olly 2016-03-22 04:01:04 -07:00 committed by Oliver Woodman
parent 27ab1a2e65
commit a49c8dc86d
3 changed files with 44 additions and 1 deletions

View File

@ -26,6 +26,7 @@ import com.google.android.exoplayer.MediaCodecSelector;
import com.google.android.exoplayer.MediaCodecTrackRenderer.DecoderInitializationException; import com.google.android.exoplayer.MediaCodecTrackRenderer.DecoderInitializationException;
import com.google.android.exoplayer.MediaCodecVideoTrackRenderer; import com.google.android.exoplayer.MediaCodecVideoTrackRenderer;
import com.google.android.exoplayer.SampleSource; import com.google.android.exoplayer.SampleSource;
import com.google.android.exoplayer.SingleSampleSource;
import com.google.android.exoplayer.TimeRange; import com.google.android.exoplayer.TimeRange;
import com.google.android.exoplayer.TrackRenderer; import com.google.android.exoplayer.TrackRenderer;
import com.google.android.exoplayer.audio.AudioCapabilities; import com.google.android.exoplayer.audio.AudioCapabilities;
@ -33,6 +34,7 @@ import com.google.android.exoplayer.audio.AudioTrack;
import com.google.android.exoplayer.chunk.ChunkSampleSource; import com.google.android.exoplayer.chunk.ChunkSampleSource;
import com.google.android.exoplayer.dash.DashChunkSource; import com.google.android.exoplayer.dash.DashChunkSource;
import com.google.android.exoplayer.drm.StreamingDrmSessionManager; import com.google.android.exoplayer.drm.StreamingDrmSessionManager;
import com.google.android.exoplayer.extractor.ExtractorSampleSource;
import com.google.android.exoplayer.hls.HlsSampleSource; import com.google.android.exoplayer.hls.HlsSampleSource;
import com.google.android.exoplayer.metadata.MetadataTrackRenderer; import com.google.android.exoplayer.metadata.MetadataTrackRenderer;
import com.google.android.exoplayer.metadata.MetadataTrackRenderer.MetadataRenderer; import com.google.android.exoplayer.metadata.MetadataTrackRenderer.MetadataRenderer;
@ -64,6 +66,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
*/ */
public class DemoPlayer implements ExoPlayer.Listener, DefaultTrackSelector.EventListener, public class DemoPlayer implements ExoPlayer.Listener, DefaultTrackSelector.EventListener,
ChunkSampleSource.EventListener, HlsSampleSource.EventListener, ChunkSampleSource.EventListener, HlsSampleSource.EventListener,
ExtractorSampleSource.EventListener, SingleSampleSource.EventListener,
DefaultBandwidthMeter.EventListener, MediaCodecVideoTrackRenderer.EventListener, DefaultBandwidthMeter.EventListener, MediaCodecVideoTrackRenderer.EventListener,
MediaCodecAudioTrackRenderer.EventListener, StreamingDrmSessionManager.EventListener, MediaCodecAudioTrackRenderer.EventListener, StreamingDrmSessionManager.EventListener,
DashChunkSource.EventListener, TextRenderer, MetadataRenderer<List<Id3Frame>>, DashChunkSource.EventListener, TextRenderer, MetadataRenderer<List<Id3Frame>>,

View File

@ -51,7 +51,7 @@ public class ExtractorSourceBuilder implements SourceBuilder {
DataSource dataSource = new DefaultUriDataSource(context, player.getBandwidthMeter(), DataSource dataSource = new DefaultUriDataSource(context, player.getBandwidthMeter(),
userAgent); userAgent);
return new ExtractorSampleSource(uri, dataSource, allocator, return new ExtractorSampleSource(uri, dataSource, allocator,
BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE); BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE, player.getMainHandler(), player, 0);
} }
} }

View File

@ -22,6 +22,7 @@ import com.google.android.exoplayer.upstream.Loader.Loadable;
import com.google.android.exoplayer.util.Assertions; import com.google.android.exoplayer.util.Assertions;
import android.net.Uri; import android.net.Uri;
import android.os.Handler;
import android.os.SystemClock; import android.os.SystemClock;
import java.io.IOException; import java.io.IOException;
@ -33,6 +34,21 @@ import java.util.Arrays;
public final class SingleSampleSource implements SampleSource, TrackStream, Loader.Callback, public final class SingleSampleSource implements SampleSource, TrackStream, Loader.Callback,
Loadable { Loadable {
/**
* Interface definition for a callback to be notified of {@link SingleSampleSource} events.
*/
public interface EventListener {
/**
* Invoked when an error occurs loading media data.
*
* @param sourceId The id of the reporting {@link SampleSource}.
* @param e The cause of the failure.
*/
void onLoadError(int sourceId, IOException e);
}
/** /**
* The default minimum number of times to retry loading data prior to failing. * The default minimum number of times to retry loading data prior to failing.
*/ */
@ -53,6 +69,9 @@ public final class SingleSampleSource implements SampleSource, TrackStream, Load
private final long durationUs; private final long durationUs;
private final int minLoadableRetryCount; private final int minLoadableRetryCount;
private final TrackGroupArray tracks; private final TrackGroupArray tracks;
private final Handler eventHandler;
private final EventListener eventListener;
private final int eventSourceId;
private int state; private int state;
private byte[] sampleData; private byte[] sampleData;
@ -71,11 +90,20 @@ public final class SingleSampleSource implements SampleSource, TrackStream, Load
public SingleSampleSource(Uri uri, DataSource dataSource, Format format, long durationUs, public SingleSampleSource(Uri uri, DataSource dataSource, Format format, long durationUs,
int minLoadableRetryCount) { int minLoadableRetryCount) {
this(uri, dataSource, format, durationUs, minLoadableRetryCount, null, null, 0);
}
public SingleSampleSource(Uri uri, DataSource dataSource, Format format, long durationUs,
int minLoadableRetryCount, Handler eventHandler, EventListener eventListener,
int eventSourceId) {
this.uri = uri; this.uri = uri;
this.dataSource = dataSource; this.dataSource = dataSource;
this.format = format; this.format = format;
this.durationUs = durationUs; this.durationUs = durationUs;
this.minLoadableRetryCount = minLoadableRetryCount; this.minLoadableRetryCount = minLoadableRetryCount;
this.eventHandler = eventHandler;
this.eventListener = eventListener;
this.eventSourceId = eventSourceId;
tracks = new TrackGroupArray(new TrackGroup(format)); tracks = new TrackGroupArray(new TrackGroup(format));
sampleData = new byte[INITIAL_SAMPLE_SIZE]; sampleData = new byte[INITIAL_SAMPLE_SIZE];
} }
@ -224,6 +252,7 @@ public final class SingleSampleSource implements SampleSource, TrackStream, Load
currentLoadableException = e; currentLoadableException = e;
currentLoadableExceptionCount++; currentLoadableExceptionCount++;
currentLoadableExceptionTimestamp = SystemClock.elapsedRealtime(); currentLoadableExceptionTimestamp = SystemClock.elapsedRealtime();
notifyLoadError(e);
maybeStartLoading(); maybeStartLoading();
} }
@ -260,4 +289,15 @@ public final class SingleSampleSource implements SampleSource, TrackStream, Load
} }
} }
private void notifyLoadError(final IOException e) {
if (eventHandler != null && eventListener != null) {
eventHandler.post(new Runnable() {
@Override
public void run() {
eventListener.onLoadError(eventSourceId, e);
}
});
}
}
} }