Search in sources :

Example 1 with FrameworkMediaCrypto

use of com.google.android.exoplayer2.drm.FrameworkMediaCrypto 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 FrameworkMediaCrypto

use of com.google.android.exoplayer2.drm.FrameworkMediaCrypto in project ExoPlayer by google.

the class PlayerActivity method initializePlayer.

// Internal methods
private void initializePlayer() {
    Intent intent = getIntent();
    boolean needNewPlayer = player == null;
    if (needNewPlayer) {
        boolean preferExtensionDecoders = intent.getBooleanExtra(PREFER_EXTENSION_DECODERS, false);
        UUID drmSchemeUuid = intent.hasExtra(DRM_SCHEME_UUID_EXTRA) ? UUID.fromString(intent.getStringExtra(DRM_SCHEME_UUID_EXTRA)) : null;
        DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = null;
        if (drmSchemeUuid != null) {
            String drmLicenseUrl = intent.getStringExtra(DRM_LICENSE_URL);
            String[] keyRequestPropertiesArray = intent.getStringArrayExtra(DRM_KEY_REQUEST_PROPERTIES);
            try {
                drmSessionManager = buildDrmSessionManager(drmSchemeUuid, drmLicenseUrl, keyRequestPropertiesArray);
            } catch (UnsupportedDrmException e) {
                int errorStringId = Util.SDK_INT < 18 ? R.string.error_drm_not_supported : (e.reason == UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME ? R.string.error_drm_unsupported_scheme : R.string.error_drm_unknown);
                showToast(errorStringId);
                return;
            }
        }
        @SimpleExoPlayer.ExtensionRendererMode int extensionRendererMode = ((DemoApplication) getApplication()).useExtensionRenderers() ? (preferExtensionDecoders ? SimpleExoPlayer.EXTENSION_RENDERER_MODE_PREFER : SimpleExoPlayer.EXTENSION_RENDERER_MODE_ON) : SimpleExoPlayer.EXTENSION_RENDERER_MODE_OFF;
        TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
        trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
        trackSelectionHelper = new TrackSelectionHelper(trackSelector, videoTrackSelectionFactory);
        player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, new DefaultLoadControl(), drmSessionManager, extensionRendererMode);
        player.addListener(this);
        eventLogger = new EventLogger(trackSelector);
        player.addListener(eventLogger);
        player.setAudioDebugListener(eventLogger);
        player.setVideoDebugListener(eventLogger);
        player.setMetadataOutput(eventLogger);
        simpleExoPlayerView.setPlayer(player);
        player.setPlayWhenReady(shouldAutoPlay);
        debugViewHelper = new DebugTextViewHelper(player, debugTextView);
        debugViewHelper.start();
    }
    if (needNewPlayer || needRetrySource) {
        String action = intent.getAction();
        Uri[] uris;
        String[] extensions;
        if (ACTION_VIEW.equals(action)) {
            uris = new Uri[] { intent.getData() };
            extensions = new String[] { intent.getStringExtra(EXTENSION_EXTRA) };
        } else if (ACTION_VIEW_LIST.equals(action)) {
            String[] uriStrings = intent.getStringArrayExtra(URI_LIST_EXTRA);
            uris = new Uri[uriStrings.length];
            for (int i = 0; i < uriStrings.length; i++) {
                uris[i] = Uri.parse(uriStrings[i]);
            }
            extensions = intent.getStringArrayExtra(EXTENSION_LIST_EXTRA);
            if (extensions == null) {
                extensions = new String[uriStrings.length];
            }
        } else {
            showToast(getString(R.string.unexpected_intent_action, action));
            return;
        }
        if (Util.maybeRequestReadExternalStoragePermission(this, uris)) {
            // The player will be reinitialized if the permission is granted.
            return;
        }
        MediaSource[] mediaSources = new MediaSource[uris.length];
        for (int i = 0; i < uris.length; i++) {
            mediaSources[i] = buildMediaSource(uris[i], extensions[i]);
        }
        MediaSource mediaSource = mediaSources.length == 1 ? mediaSources[0] : new ConcatenatingMediaSource(mediaSources);
        boolean haveResumePosition = resumeWindow != C.INDEX_UNSET;
        if (haveResumePosition) {
            player.seekTo(resumeWindow, resumePosition);
        }
        player.prepare(mediaSource, !haveResumePosition, false);
        needRetrySource = false;
        updateButtonVisibilities();
    }
}
Also used : DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) ExoPlayerFactory(com.google.android.exoplayer2.ExoPlayerFactory) Intent(android.content.Intent) Uri(android.net.Uri) DefaultLoadControl(com.google.android.exoplayer2.DefaultLoadControl) DebugTextViewHelper(com.google.android.exoplayer2.ui.DebugTextViewHelper) FrameworkMediaCrypto(com.google.android.exoplayer2.drm.FrameworkMediaCrypto) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) DashMediaSource(com.google.android.exoplayer2.source.dash.DashMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) SsMediaSource(com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource) HlsMediaSource(com.google.android.exoplayer2.source.hls.HlsMediaSource) ExtractorMediaSource(com.google.android.exoplayer2.source.ExtractorMediaSource) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) UnsupportedDrmException(com.google.android.exoplayer2.drm.UnsupportedDrmException) UUID(java.util.UUID) TrackSelection(com.google.android.exoplayer2.trackselection.TrackSelection) AdaptiveTrackSelection(com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection)

Example 3 with FrameworkMediaCrypto

use of com.google.android.exoplayer2.drm.FrameworkMediaCrypto in project ExoPlayer by google.

the class ExoHostedTest method onStart.

// HostedTest implementation
@Override
public final void onStart(HostActivity host, Surface surface) {
    // Build the player.
    DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    trackSelector = buildTrackSelector(host, bandwidthMeter);
    String userAgent = "ExoPlayerPlaybackTests";
    DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = buildDrmSessionManager(userAgent);
    player = buildExoPlayer(host, surface, trackSelector, drmSessionManager);
    player.prepare(buildSource(host, Util.getUserAgent(host, userAgent), bandwidthMeter));
    player.addListener(this);
    player.setAudioDebugListener(this);
    player.setVideoDebugListener(this);
    player.setPlayWhenReady(true);
    actionHandler = new Handler();
    // Schedule any pending actions.
    if (pendingSchedule != null) {
        pendingSchedule.start(player, trackSelector, actionHandler);
        pendingSchedule = null;
    }
}
Also used : DefaultBandwidthMeter(com.google.android.exoplayer2.upstream.DefaultBandwidthMeter) FrameworkMediaCrypto(com.google.android.exoplayer2.drm.FrameworkMediaCrypto) Handler(android.os.Handler)

Example 4 with FrameworkMediaCrypto

use of com.google.android.exoplayer2.drm.FrameworkMediaCrypto in project ExoPlayer by google.

the class ExoHostedTest method buildExoPlayer.

@SuppressWarnings("unused")
protected SimpleExoPlayer buildExoPlayer(HostActivity host, Surface surface, MappingTrackSelector trackSelector, DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
    SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(host, trackSelector, new DefaultLoadControl(), drmSessionManager, SimpleExoPlayer.EXTENSION_RENDERER_MODE_OFF, 0);
    player.setVideoSurface(surface);
    return player;
}
Also used : SimpleExoPlayer(com.google.android.exoplayer2.SimpleExoPlayer) DefaultLoadControl(com.google.android.exoplayer2.DefaultLoadControl)

Example 5 with FrameworkMediaCrypto

use of com.google.android.exoplayer2.drm.FrameworkMediaCrypto in project ExoPlayer by google.

the class SimpleExoPlayer method buildVideoRenderers.

/**
   * Builds video 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 allowedVideoJoiningTimeMs The maximum duration in milliseconds for which video renderers
   *     can attempt to seamlessly join an ongoing playback.
   * @param out An array to which the built renderers should be appended.
   */
protected void buildVideoRenderers(Context context, Handler mainHandler, DrmSessionManager<FrameworkMediaCrypto> drmSessionManager, @ExtensionRendererMode int extensionRendererMode, VideoRendererEventListener eventListener, long allowedVideoJoiningTimeMs, ArrayList<Renderer> out) {
    out.add(new MediaCodecVideoRenderer(context, MediaCodecSelector.DEFAULT, allowedVideoJoiningTimeMs, drmSessionManager, false, mainHandler, eventListener, MAX_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFY));
    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.vp9.LibvpxVideoRenderer");
        Constructor<?> constructor = clazz.getConstructor(boolean.class, long.class, Handler.class, VideoRendererEventListener.class, int.class);
        Renderer renderer = (Renderer) constructor.newInstance(true, allowedVideoJoiningTimeMs, mainHandler, componentListener, MAX_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFY);
        out.add(extensionRendererIndex++, renderer);
        Log.i(TAG, "Loaded LibvpxVideoRenderer.");
    } catch (ClassNotFoundException e) {
    // Expected if the app was built without the extension.
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : MediaCodecVideoRenderer(com.google.android.exoplayer2.video.MediaCodecVideoRenderer) 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)

Aggregations

DefaultLoadControl (com.google.android.exoplayer2.DefaultLoadControl)2 MediaCodecAudioRenderer (com.google.android.exoplayer2.audio.MediaCodecAudioRenderer)2 FrameworkMediaCrypto (com.google.android.exoplayer2.drm.FrameworkMediaCrypto)2 MetadataRenderer (com.google.android.exoplayer2.metadata.MetadataRenderer)2 TextRenderer (com.google.android.exoplayer2.text.TextRenderer)2 MediaCodecVideoRenderer (com.google.android.exoplayer2.video.MediaCodecVideoRenderer)2 Intent (android.content.Intent)1 Uri (android.net.Uri)1 Handler (android.os.Handler)1 ExoPlayerFactory (com.google.android.exoplayer2.ExoPlayerFactory)1 SimpleExoPlayer (com.google.android.exoplayer2.SimpleExoPlayer)1 AudioProcessor (com.google.android.exoplayer2.audio.AudioProcessor)1 UnsupportedDrmException (com.google.android.exoplayer2.drm.UnsupportedDrmException)1 DefaultExtractorsFactory (com.google.android.exoplayer2.extractor.DefaultExtractorsFactory)1 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)1 ExtractorMediaSource (com.google.android.exoplayer2.source.ExtractorMediaSource)1 MediaSource (com.google.android.exoplayer2.source.MediaSource)1 DashMediaSource (com.google.android.exoplayer2.source.dash.DashMediaSource)1 HlsMediaSource (com.google.android.exoplayer2.source.hls.HlsMediaSource)1 SsMediaSource (com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource)1