Search in sources :

Example 1 with Listener

use of com.google.android.exoplayer2.source.MediaSource.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);
    }
}
Also used : AudioProcessor(com.google.android.exoplayer2.audio.AudioProcessor) MediaCodecAudioRenderer(com.google.android.exoplayer2.audio.MediaCodecAudioRenderer) MediaCodecAudioRenderer(com.google.android.exoplayer2.audio.MediaCodecAudioRenderer) MetadataRenderer(com.google.android.exoplayer2.metadata.MetadataRenderer) MediaCodecVideoRenderer(com.google.android.exoplayer2.video.MediaCodecVideoRenderer) TextRenderer(com.google.android.exoplayer2.text.TextRenderer)

Example 2 with Listener

use of com.google.android.exoplayer2.source.MediaSource.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();
}
Also used : HlsPlaylistTracker(com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistTracker)

Example 3 with Listener

use of com.google.android.exoplayer2.source.MediaSource.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();
    }
}
Also used : LoaderErrorThrower(com.google.android.exoplayer2.upstream.LoaderErrorThrower) Loader(com.google.android.exoplayer2.upstream.Loader) Handler(android.os.Handler)

Example 4 with Listener

use of com.google.android.exoplayer2.source.MediaSource.Listener in project ExoPlayer by google.

the class ClippingMediaSourceTest method getClippedTimeline.

/**
   * Wraps the specified timeline in a {@link ClippingMediaSource} and returns the clipped timeline.
   */
private Timeline getClippedTimeline(Timeline timeline, long startMs, long endMs) {
    mockMediaSourceSourceWithTimeline(timeline);
    new ClippingMediaSource(mockMediaSource, startMs, endMs).prepareSource(null, true, new Listener() {

        @Override
        public void onSourceInfoRefreshed(Timeline timeline, Object manifest) {
            clippedTimeline = timeline;
        }
    });
    return clippedTimeline;
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) Listener(com.google.android.exoplayer2.source.MediaSource.Listener)

Example 5 with Listener

use of com.google.android.exoplayer2.source.MediaSource.Listener in project ExoPlayer by google.

the class SsMediaSource method prepareSource.

// MediaSource implementation.
@Override
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
    sourceListener = listener;
    if (manifest != null) {
        manifestLoaderErrorThrower = new LoaderErrorThrower.Dummy();
        processManifest();
    } else {
        manifestDataSource = manifestDataSourceFactory.createDataSource();
        manifestLoader = new Loader("Loader:Manifest");
        manifestLoaderErrorThrower = manifestLoader;
        manifestRefreshHandler = new Handler();
        startLoadingManifest();
    }
}
Also used : LoaderErrorThrower(com.google.android.exoplayer2.upstream.LoaderErrorThrower) Loader(com.google.android.exoplayer2.upstream.Loader) Handler(android.os.Handler)

Aggregations

Handler (android.os.Handler)2 Timeline (com.google.android.exoplayer2.Timeline)2 MediaCodecAudioRenderer (com.google.android.exoplayer2.audio.MediaCodecAudioRenderer)2 MetadataRenderer (com.google.android.exoplayer2.metadata.MetadataRenderer)2 TextRenderer (com.google.android.exoplayer2.text.TextRenderer)2 DataSourceException (com.google.android.exoplayer2.upstream.DataSourceException)2 Loader (com.google.android.exoplayer2.upstream.Loader)2 LoaderErrorThrower (com.google.android.exoplayer2.upstream.LoaderErrorThrower)2 MediaCodecVideoRenderer (com.google.android.exoplayer2.video.MediaCodecVideoRenderer)2 AudioProcessor (com.google.android.exoplayer2.audio.AudioProcessor)1 Listener (com.google.android.exoplayer2.source.MediaSource.Listener)1 HlsPlaylistTracker (com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistTracker)1 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 List (java.util.List)1 MediaType (okhttp3.MediaType)1 Request (okhttp3.Request)1