use of com.google.android.exoplayer2.Player.Listener in project ExoPlayer by google.
the class SimpleExoPlayer method buildAudioRenderers.
/**
* Builds audio renderers for use by the player.
*
* @param context The {@link Context} associated with the player.
* @param mainHandler A handler associated with the main thread's looper.
* @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the player will
* not be used for DRM protected playbacks.
* @param extensionRendererMode The extension renderer mode.
* @param eventListener An event listener.
* @param audioProcessors An array of {@link AudioProcessor}s that will process PCM audio buffers
* before output. May be empty.
* @param out An array to which the built renderers should be appended.
*/
protected void buildAudioRenderers(Context context, Handler mainHandler, DrmSessionManager<FrameworkMediaCrypto> drmSessionManager, @ExtensionRendererMode int extensionRendererMode, AudioRendererEventListener eventListener, AudioProcessor[] audioProcessors, ArrayList<Renderer> out) {
out.add(new MediaCodecAudioRenderer(MediaCodecSelector.DEFAULT, drmSessionManager, true, mainHandler, eventListener, AudioCapabilities.getCapabilities(context), audioProcessors));
if (extensionRendererMode == EXTENSION_RENDERER_MODE_OFF) {
return;
}
int extensionRendererIndex = out.size();
if (extensionRendererMode == EXTENSION_RENDERER_MODE_PREFER) {
extensionRendererIndex--;
}
try {
Class<?> clazz = Class.forName("com.google.android.exoplayer2.ext.opus.LibopusAudioRenderer");
Constructor<?> constructor = clazz.getConstructor(Handler.class, AudioRendererEventListener.class, AudioProcessor[].class);
Renderer renderer = (Renderer) constructor.newInstance(mainHandler, componentListener, audioProcessors);
out.add(extensionRendererIndex++, renderer);
Log.i(TAG, "Loaded LibopusAudioRenderer.");
} catch (ClassNotFoundException e) {
// Expected if the app was built without the extension.
} catch (Exception e) {
throw new RuntimeException(e);
}
try {
Class<?> clazz = Class.forName("com.google.android.exoplayer2.ext.flac.LibflacAudioRenderer");
Constructor<?> constructor = clazz.getConstructor(Handler.class, AudioRendererEventListener.class, AudioProcessor[].class);
Renderer renderer = (Renderer) constructor.newInstance(mainHandler, componentListener, audioProcessors);
out.add(extensionRendererIndex++, renderer);
Log.i(TAG, "Loaded LibflacAudioRenderer.");
} catch (ClassNotFoundException e) {
// Expected if the app was built without the extension.
} catch (Exception e) {
throw new RuntimeException(e);
}
try {
Class<?> clazz = Class.forName("com.google.android.exoplayer2.ext.ffmpeg.FfmpegAudioRenderer");
Constructor<?> constructor = clazz.getConstructor(Handler.class, AudioRendererEventListener.class, AudioProcessor[].class);
Renderer renderer = (Renderer) constructor.newInstance(mainHandler, componentListener, audioProcessors);
out.add(extensionRendererIndex++, renderer);
Log.i(TAG, "Loaded FfmpegAudioRenderer.");
} catch (ClassNotFoundException e) {
// Expected if the app was built without the extension.
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.google.android.exoplayer2.Player.Listener in project ExoPlayer by google.
the class HlsMediaSource method prepareSource.
@Override
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
Assertions.checkState(playlistTracker == null);
playlistTracker = new HlsPlaylistTracker(manifestUri, dataSourceFactory, eventDispatcher, minLoadableRetryCount, this);
sourceListener = listener;
playlistTracker.start();
}
use of com.google.android.exoplayer2.Player.Listener in project ExoPlayer by google.
the class DashMediaSource method prepareSource.
// MediaSource implementation.
@Override
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
sourceListener = listener;
if (sideloadedManifest) {
loaderErrorThrower = new LoaderErrorThrower.Dummy();
processManifest(false);
} else {
dataSource = manifestDataSourceFactory.createDataSource();
loader = new Loader("Loader:DashMediaSource");
loaderErrorThrower = loader;
handler = new Handler();
startLoadingManifest();
}
}
use of com.google.android.exoplayer2.Player.Listener in project HybridMediaPlayer by mkaflowski.
the class ExoMediaPlayer method setDataSource.
public void setDataSource(List<MediaSourceInfo> normalSources, List<MediaSourceInfo> castSources, CastContext castContext) {
String userAgent = Util.getUserAgent(context, "yourApplicationName");
DefaultHttpDataSourceFactory httpDataSourceFactory = new DefaultHttpDataSourceFactory(userAgent, null, /* listener */
DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS, DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, true);
// Produces DataSource instances through which media data is loaded.
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, null, httpDataSourceFactory);
// Produces Extractor instances for parsing the media data.
ExtractorsFactory extractorsFactory = new SeekableExtractorsFactory();
MediaSource[] sources = new MediaSource[normalSources.size()];
for (int i = 0; i < normalSources.size(); i++) {
// This is the MediaSource representing the media to be played.
sources[i] = new ExtractorMediaSource(Uri.parse(normalSources.get(i).getUrl()), dataSourceFactory, extractorsFactory, null, null);
}
exoMediaSource = new ConcatenatingMediaSource(sources);
setCastMediaSourceInfoList(castSources);
prepare();
if (castContext != null) {
castPlayer = new CastPlayer(castContext);
castPlayer.setSessionAvailabilityListener(this);
castPlayer.addListener(new MyPlayerEventListener(castPlayer));
}
init();
}
use of com.google.android.exoplayer2.Player.Listener in project ExoPlayer by google.
the class IcyDataSource method readMetadata.
/**
* Reads an ICY stream metadata block, passing it to {@link #listener} unless the block is empty.
*
* @return True if the block was extracted, including if its length byte indicated a length of
* zero. False if the end of the stream was reached.
* @throws IOException If an error occurs reading from the wrapped {@link DataSource}.
*/
private boolean readMetadata() throws IOException {
int bytesRead = upstream.read(metadataLengthByteHolder, 0, 1);
if (bytesRead == C.RESULT_END_OF_INPUT) {
return false;
}
int metadataLength = (metadataLengthByteHolder[0] & 0xFF) << 4;
if (metadataLength == 0) {
return true;
}
int offset = 0;
int lengthRemaining = metadataLength;
byte[] metadata = new byte[metadataLength];
while (lengthRemaining > 0) {
bytesRead = upstream.read(metadata, offset, lengthRemaining);
if (bytesRead == C.RESULT_END_OF_INPUT) {
return false;
}
offset += bytesRead;
lengthRemaining -= bytesRead;
}
// Discard trailing zero bytes.
while (metadataLength > 0 && metadata[metadataLength - 1] == 0) {
metadataLength--;
}
if (metadataLength > 0) {
listener.onIcyMetadata(new ParsableByteArray(metadata, metadataLength));
}
return true;
}
Aggregations