Search in sources :

Example 16 with ExoPlaybackException

use of com.google.android.exoplayer2.ExoPlaybackException in project ExoPlayer by google.

the class SimpleDecoderAudioRenderer method maybeInitDecoder.

private void maybeInitDecoder() throws ExoPlaybackException {
    if (decoder != null) {
        return;
    }
    drmSession = pendingDrmSession;
    ExoMediaCrypto mediaCrypto = null;
    if (drmSession != null) {
        @DrmSession.State int drmSessionState = drmSession.getState();
        if (drmSessionState == DrmSession.STATE_ERROR) {
            throw ExoPlaybackException.createForRenderer(drmSession.getError(), getIndex());
        } else if (drmSessionState == DrmSession.STATE_OPENED || drmSessionState == DrmSession.STATE_OPENED_WITH_KEYS) {
            mediaCrypto = drmSession.getMediaCrypto();
        } else {
            // The drm session isn't open yet.
            return;
        }
    }
    try {
        long codecInitializingTimestamp = SystemClock.elapsedRealtime();
        TraceUtil.beginSection("createAudioDecoder");
        decoder = createDecoder(inputFormat, mediaCrypto);
        TraceUtil.endSection();
        long codecInitializedTimestamp = SystemClock.elapsedRealtime();
        eventDispatcher.decoderInitialized(decoder.getName(), codecInitializedTimestamp, codecInitializedTimestamp - codecInitializingTimestamp);
        decoderCounters.decoderInitCount++;
    } catch (AudioDecoderException e) {
        throw ExoPlaybackException.createForRenderer(e, getIndex());
    }
}
Also used : ExoMediaCrypto(com.google.android.exoplayer2.drm.ExoMediaCrypto)

Example 17 with ExoPlaybackException

use of com.google.android.exoplayer2.ExoPlaybackException in project ExoPlayer by google.

the class SimpleDecoderAudioRenderer method onEnabled.

@Override
protected void onEnabled(boolean joining) throws ExoPlaybackException {
    decoderCounters = new DecoderCounters();
    eventDispatcher.enabled(decoderCounters);
    int tunnelingAudioSessionId = getConfiguration().tunnelingAudioSessionId;
    if (tunnelingAudioSessionId != C.AUDIO_SESSION_ID_UNSET) {
        audioTrack.enableTunnelingV21(tunnelingAudioSessionId);
    } else {
        audioTrack.disableTunneling();
    }
}
Also used : DecoderCounters(com.google.android.exoplayer2.decoder.DecoderCounters)

Example 18 with ExoPlaybackException

use of com.google.android.exoplayer2.ExoPlaybackException in project ExoPlayer by google.

the class SimpleDecoderAudioRenderer method onInputFormatChanged.

private void onInputFormatChanged(Format newFormat) throws ExoPlaybackException {
    Format oldFormat = inputFormat;
    inputFormat = newFormat;
    boolean drmInitDataChanged = !Util.areEqual(inputFormat.drmInitData, oldFormat == null ? null : oldFormat.drmInitData);
    if (drmInitDataChanged) {
        if (inputFormat.drmInitData != null) {
            if (drmSessionManager == null) {
                throw ExoPlaybackException.createForRenderer(new IllegalStateException("Media requires a DrmSessionManager"), getIndex());
            }
            pendingDrmSession = drmSessionManager.acquireSession(Looper.myLooper(), inputFormat.drmInitData);
            if (pendingDrmSession == drmSession) {
                drmSessionManager.releaseSession(pendingDrmSession);
            }
        } else {
            pendingDrmSession = null;
        }
    }
    if (decoderReceivedBuffers) {
        // Signal end of stream and wait for any final output buffers before re-initialization.
        decoderReinitializationState = REINITIALIZATION_STATE_SIGNAL_END_OF_STREAM;
    } else {
        // There aren't any final output buffers, so release the decoder immediately.
        releaseDecoder();
        maybeInitDecoder();
        audioTrackNeedsConfigure = true;
    }
    eventDispatcher.inputFormatChanged(newFormat);
}
Also used : Format(com.google.android.exoplayer2.Format)

Example 19 with ExoPlaybackException

use of com.google.android.exoplayer2.ExoPlaybackException in project react-native-video by react-native-community.

the class ReactExoplayerView method onPlayerError.

@Override
public void onPlayerError(ExoPlaybackException e) {
    String errorString = null;
    if (e.type == ExoPlaybackException.TYPE_RENDERER) {
        Exception cause = e.getRendererException();
        if (cause instanceof MediaCodecRenderer.DecoderInitializationException) {
            // Special case for decoder initialization failures.
            MediaCodecRenderer.DecoderInitializationException decoderInitializationException = (MediaCodecRenderer.DecoderInitializationException) cause;
            if (decoderInitializationException.decoderName == null) {
                if (decoderInitializationException.getCause() instanceof MediaCodecUtil.DecoderQueryException) {
                    errorString = getResources().getString(R.string.error_querying_decoders);
                } else if (decoderInitializationException.secureDecoderRequired) {
                    errorString = getResources().getString(R.string.error_no_secure_decoder, decoderInitializationException.mimeType);
                } else {
                    errorString = getResources().getString(R.string.error_no_decoder, decoderInitializationException.mimeType);
                }
            } else {
                errorString = getResources().getString(R.string.error_instantiating_decoder, decoderInitializationException.decoderName);
            }
        }
    }
    if (errorString != null) {
        eventEmitter.error(errorString, e);
    }
    playerNeedsSource = true;
}
Also used : ExoPlaybackException(com.google.android.exoplayer2.ExoPlaybackException) MediaCodecRenderer(com.google.android.exoplayer2.mediacodec.MediaCodecRenderer)

Aggregations

Format (com.google.android.exoplayer2.Format)4 ExoPlaybackException (com.google.android.exoplayer2.ExoPlaybackException)3 TrackSelection (com.google.android.exoplayer2.trackselection.TrackSelection)3 DecoderCounters (com.google.android.exoplayer2.decoder.DecoderCounters)2 ExoMediaCrypto (com.google.android.exoplayer2.drm.ExoMediaCrypto)2 DecoderQueryException (com.google.android.exoplayer2.mediacodec.MediaCodecUtil.DecoderQueryException)2 SampleStream (com.google.android.exoplayer2.source.SampleStream)2 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)2 Point (android.graphics.Point)1 CodecException (android.media.MediaCodec.CodecException)1 CryptoException (android.media.MediaCodec.CryptoException)1 MediaCrypto (android.media.MediaCrypto)1 MediaFormat (android.media.MediaFormat)1 ExoPlayerMessage (com.google.android.exoplayer2.ExoPlayer.ExoPlayerMessage)1 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)1 RendererConfiguration (com.google.android.exoplayer2.RendererConfiguration)1 FrameworkMediaCrypto (com.google.android.exoplayer2.drm.FrameworkMediaCrypto)1 UnsupportedDrmException (com.google.android.exoplayer2.drm.UnsupportedDrmException)1 MediaCodecRenderer (com.google.android.exoplayer2.mediacodec.MediaCodecRenderer)1 DecoderInitializationException (com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.DecoderInitializationException)1