Search in sources :

Example 1 with EventListener

use of com.google.android.exoplayer2.source.ads.AdsLoader.EventListener 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 EventListener

use of com.google.android.exoplayer2.source.ads.AdsLoader.EventListener in project android-player-samples by BrightcoveOS.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    brightcoveVideoView.getEventEmitter().on(EventType.DID_SET_SOURCE, new EventListener() {

        @Override
        public void processEvent(Event event) {
            ExoPlayerVideoDisplayComponent exoPlayerVideoDisplayComponent = (ExoPlayerVideoDisplayComponent) brightcoveVideoView.getVideoDisplay();
            exoPlayerVideoDisplayComponent.setMetadataListener(new ExoPlayerVideoDisplayComponent.MetadataListener() {

                @Override
                public void onMetadata(Metadata metadata) {
                    for (int i = 0; i < metadata.length(); i++) {
                        Metadata.Entry entry = metadata.get(i);
                        if (entry instanceof Id3Frame) {
                            Id3Frame id3Frame = (Id3Frame) entry;
                            Log.v(TAG, "id3 Frame id: " + id3Frame.id);
                        }
                    }
                }
            });
        }
    });
    Video video = Video.createVideo("https://s3.amazonaws.com/as-zencoder/hls-timed-metadata/test.m3u8", DeliveryType.HLS);
    video.getProperties().put(Video.Fields.PUBLISHER_ID, "5420904993001");
    brightcoveVideoView.add(video);
    brightcoveVideoView.start();
    // Log whether or not instance state in non-null.
    if (savedInstanceState != null) {
        Log.v(TAG, "Restoring saved position");
    } else {
        Log.v(TAG, "No saved state");
    }
}
Also used : Video(com.brightcove.player.model.Video) Metadata(com.google.android.exoplayer2.metadata.Metadata) Event(com.brightcove.player.event.Event) EventListener(com.brightcove.player.event.EventListener) Id3Frame(com.google.android.exoplayer2.metadata.id3.Id3Frame) ExoPlayerVideoDisplayComponent(com.brightcove.player.display.ExoPlayerVideoDisplayComponent)

Example 3 with EventListener

use of com.google.android.exoplayer2.source.ads.AdsLoader.EventListener in project android-app by LISTEN-moe.

the class StreamPlayer method init.

private void init() {
    // In case there's already an instance somehow
    releasePlayer();
    final DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, userAgent);
    final ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
    final MediaSource streamSource = new ExtractorMediaSource(Uri.parse(streamUrl), dataSourceFactory, extractorsFactory, null, null);
    player = ExoPlayerFactory.newSimpleInstance(context, new DefaultTrackSelector());
    player.prepare(streamSource);
    player.addListener(eventListener);
    player.setVolume(1f);
    final AudioAttributes audioAttributes = new AudioAttributes.Builder().setContentType(CONTENT_TYPE_MUSIC).setUsage(USAGE_MEDIA).build();
    player.setAudioAttributes(audioAttributes);
}
Also used : DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) ExtractorMediaSource(com.google.android.exoplayer2.source.ExtractorMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) ExtractorsFactory(com.google.android.exoplayer2.extractor.ExtractorsFactory) DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) DefaultDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultDataSourceFactory) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) ExtractorMediaSource(com.google.android.exoplayer2.source.ExtractorMediaSource) AudioAttributes(com.google.android.exoplayer2.audio.AudioAttributes) DataSource(com.google.android.exoplayer2.upstream.DataSource)

Example 4 with EventListener

use of com.google.android.exoplayer2.source.ads.AdsLoader.EventListener in project ExoPlayer by google.

the class MediaSourceList method prepareChildSource.

private void prepareChildSource(MediaSourceHolder holder) {
    MediaSource mediaSource = holder.mediaSource;
    MediaSource.MediaSourceCaller caller = (source, timeline) -> mediaSourceListInfoListener.onPlaylistUpdateRequested();
    ForwardingEventListener eventListener = new ForwardingEventListener(holder);
    childSources.put(holder, new MediaSourceAndListener(mediaSource, caller, eventListener));
    mediaSource.addEventListener(Util.createHandlerForCurrentOrMainLooper(), eventListener);
    mediaSource.addDrmEventListener(Util.createHandlerForCurrentOrMainLooper(), eventListener);
    mediaSource.prepareSource(caller, mediaTransferListener, playerId);
}
Also used : DefaultShuffleOrder(com.google.android.exoplayer2.source.ShuffleOrder.DefaultShuffleOrder) Util(com.google.android.exoplayer2.util.Util) LoadEventInfo(com.google.android.exoplayer2.source.LoadEventInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PlayerId(com.google.android.exoplayer2.analytics.PlayerId) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) Log(com.google.android.exoplayer2.util.Log) Handler(android.os.Handler) MediaPeriod(com.google.android.exoplayer2.source.MediaPeriod) Map(java.util.Map) ShuffleOrder(com.google.android.exoplayer2.source.ShuffleOrder) MediaSourceEventListener(com.google.android.exoplayer2.source.MediaSourceEventListener) MediaSource(com.google.android.exoplayer2.source.MediaSource) Allocator(com.google.android.exoplayer2.upstream.Allocator) TransferListener(com.google.android.exoplayer2.upstream.TransferListener) IdentityHashMap(java.util.IdentityHashMap) Iterator(java.util.Iterator) Set(java.util.Set) IOException(java.io.IOException) Math.min(java.lang.Math.min) DrmSession(com.google.android.exoplayer2.drm.DrmSession) List(java.util.List) Nullable(androidx.annotation.Nullable) MaskingMediaPeriod(com.google.android.exoplayer2.source.MaskingMediaPeriod) MaskingMediaSource(com.google.android.exoplayer2.source.MaskingMediaSource) Math.max(java.lang.Math.max) MediaLoadData(com.google.android.exoplayer2.source.MediaLoadData) AnalyticsCollector(com.google.android.exoplayer2.analytics.AnalyticsCollector) Assertions(com.google.android.exoplayer2.util.Assertions) MediaSource(com.google.android.exoplayer2.source.MediaSource) MaskingMediaSource(com.google.android.exoplayer2.source.MaskingMediaSource)

Example 5 with EventListener

use of com.google.android.exoplayer2.source.ads.AdsLoader.EventListener in project ExoPlayer by google.

the class ImaAdsLoader method start.

@Override
public void start(AdsMediaSource adsMediaSource, DataSpec adTagDataSpec, Object adsId, AdViewProvider adViewProvider, EventListener eventListener) {
    checkState(wasSetPlayerCalled, "Set player using adsLoader.setPlayer before preparing the player.");
    if (adTagLoaderByAdsMediaSource.isEmpty()) {
        player = nextPlayer;
        @Nullable Player player = this.player;
        if (player == null) {
            return;
        }
        player.addListener(playerListener);
    }
    @Nullable AdTagLoader adTagLoader = adTagLoaderByAdsId.get(adsId);
    if (adTagLoader == null) {
        requestAds(adTagDataSpec, adsId, adViewProvider.getAdViewGroup());
        adTagLoader = adTagLoaderByAdsId.get(adsId);
    }
    adTagLoaderByAdsMediaSource.put(adsMediaSource, checkNotNull(adTagLoader));
    adTagLoader.addListenerWithAdView(eventListener, adViewProvider);
    maybeUpdateCurrentAdTagLoader();
}
Also used : Player(com.google.android.exoplayer2.Player) VideoAdPlayer(com.google.ads.interactivemedia.v3.api.player.VideoAdPlayer) Nullable(androidx.annotation.Nullable)

Aggregations

DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)18 Test (org.junit.Test)18 FakeSampleStream (com.google.android.exoplayer2.testutil.FakeSampleStream)17 DefaultAllocator (com.google.android.exoplayer2.upstream.DefaultAllocator)16 Nullable (androidx.annotation.Nullable)12 Collections (java.util.Collections)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 List (java.util.List)6 Before (org.junit.Before)6 Context (android.content.Context)5 Intent (android.content.Intent)5 SurfaceTexture (android.graphics.SurfaceTexture)5 Uri (android.net.Uri)5 ShadowLooper (org.robolectric.shadows.ShadowLooper)5 ValueAnimator (android.animation.ValueAnimator)4 SuppressLint (android.annotation.SuppressLint)4 ActivityNotFoundException (android.content.ActivityNotFoundException)4 Color (android.graphics.Color)4 PorterDuff (android.graphics.PorterDuff)4