Search in sources :

Example 16 with PlaybackException

use of androidx.media3.common.PlaybackException in project media by androidx.

the class DefaultAnalyticsCollector method onPlayerErrorChanged.

@Override
public void onPlayerErrorChanged(@Nullable PlaybackException error) {
    EventTime eventTime = getEventTimeForErrorEvent(error);
    sendEvent(eventTime, AnalyticsListener.EVENT_PLAYER_ERROR, listener -> listener.onPlayerErrorChanged(eventTime, error));
}
Also used : EventTime(androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime)

Example 17 with PlaybackException

use of androidx.media3.common.PlaybackException in project media by androidx.

the class MediaMetricsListener method maybeReportPlaybackError.

private void maybeReportPlaybackError(long realtimeMs) {
    @Nullable PlaybackException error = pendingPlayerError;
    if (error == null) {
        return;
    }
    ErrorInfo errorInfo = getErrorInfo(error, context, /* lastIoErrorForManifest= */
    ioErrorType == C.DATA_TYPE_MANIFEST);
    playbackSession.reportPlaybackErrorEvent(new PlaybackErrorEvent.Builder().setTimeSinceCreatedMillis(realtimeMs - startTimeMs).setErrorCode(errorInfo.errorCode).setSubErrorCode(errorInfo.subErrorCode).setException(error).build());
    reportedEventsForCurrentSession = true;
    pendingPlayerError = null;
}
Also used : ExoPlaybackException(androidx.media3.exoplayer.ExoPlaybackException) PlaybackException(androidx.media3.common.PlaybackException) Nullable(androidx.annotation.Nullable)

Example 18 with PlaybackException

use of androidx.media3.common.PlaybackException in project media by androidx.

the class RtspMediaPeriod method retryWithRtpTcp.

private void retryWithRtpTcp() {
    rtspClient.retryWithRtpTcp();
    @Nullable RtpDataChannel.Factory fallbackRtpDataChannelFactory = rtpDataChannelFactory.createFallbackDataChannelFactory();
    if (fallbackRtpDataChannelFactory == null) {
        playbackException = new RtspPlaybackException("No fallback data channel factory for TCP retry");
        return;
    }
    ArrayList<RtspLoaderWrapper> newLoaderWrappers = new ArrayList<>(rtspLoaderWrappers.size());
    ArrayList<RtpLoadInfo> newSelectedLoadInfos = new ArrayList<>(selectedLoadInfos.size());
    // newLoaderWrappers' elements and orders must match those of rtspLoaderWrappers'.
    for (int i = 0; i < rtspLoaderWrappers.size(); i++) {
        RtspLoaderWrapper loaderWrapper = rtspLoaderWrappers.get(i);
        if (!loaderWrapper.canceled) {
            RtspLoaderWrapper newLoaderWrapper = new RtspLoaderWrapper(loaderWrapper.loadInfo.mediaTrack, /* trackId= */
            i, fallbackRtpDataChannelFactory);
            newLoaderWrappers.add(newLoaderWrapper);
            newLoaderWrapper.startLoading();
            if (selectedLoadInfos.contains(loaderWrapper.loadInfo)) {
                newSelectedLoadInfos.add(newLoaderWrapper.loadInfo);
            }
        } else {
            newLoaderWrappers.add(loaderWrapper);
        }
    }
    // Switch to new LoaderWrappers.
    ImmutableList<RtspLoaderWrapper> oldRtspLoaderWrappers = ImmutableList.copyOf(rtspLoaderWrappers);
    rtspLoaderWrappers.clear();
    rtspLoaderWrappers.addAll(newLoaderWrappers);
    selectedLoadInfos.clear();
    selectedLoadInfos.addAll(newSelectedLoadInfos);
    // active sample queues.
    for (int i = 0; i < oldRtspLoaderWrappers.size(); i++) {
        oldRtspLoaderWrappers.get(i).cancelLoad();
    }
}
Also used : RtspPlaybackException(androidx.media3.exoplayer.rtsp.RtspMediaSource.RtspPlaybackException) ArrayList(java.util.ArrayList) Nullable(androidx.annotation.Nullable)

Example 19 with PlaybackException

use of androidx.media3.common.PlaybackException in project media by androidx.

the class RtspPlaybackTest method prepare_noSupportedTrack_throwsPreparationError.

@Test
public void prepare_noSupportedTrack_throwsPreparationError() throws Exception {
    try (RtspServer rtspServer = new RtspServer(new ResponseProvider(clock, ImmutableList.of(mp4aLatmRtpPacketStreamDump), fakeRtpDataChannel))) {
        ExoPlayer player = createExoPlayer(rtspServer.startAndGetPortNumber(), rtpDataChannelFactory);
        AtomicReference<Throwable> playbackError = new AtomicReference<>();
        player.prepare();
        player.addListener(new Listener() {

            @Override
            public void onPlayerError(PlaybackException error) {
                playbackError.set(error);
            }
        });
        RobolectricUtil.runMainLooperUntil(() -> playbackError.get() != null);
        player.release();
        assertThat(playbackError.get()).hasCauseThat().hasMessageThat().contains("No playable track.");
    }
}
Also used : PlaybackException(androidx.media3.common.PlaybackException) Listener(androidx.media3.common.Player.Listener) AtomicReference(java.util.concurrent.atomic.AtomicReference) ExoPlayer(androidx.media3.exoplayer.ExoPlayer) Test(org.junit.Test)

Example 20 with PlaybackException

use of androidx.media3.common.PlaybackException in project media by androidx.

the class MediaCodecRenderer method render.

@Override
public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
    if (pendingOutputEndOfStream) {
        pendingOutputEndOfStream = false;
        processEndOfStream();
    }
    if (pendingPlaybackException != null) {
        ExoPlaybackException playbackException = pendingPlaybackException;
        pendingPlaybackException = null;
        throw playbackException;
    }
    try {
        if (outputStreamEnded) {
            renderToEndOfStream();
            return;
        }
        if (inputFormat == null && !readSourceOmittingSampleData(FLAG_REQUIRE_FORMAT)) {
            // We still don't have a format and can't make progress without one.
            return;
        }
        // We have a format.
        maybeInitCodecOrBypass();
        if (bypassEnabled) {
            TraceUtil.beginSection("bypassRender");
            while (bypassRender(positionUs, elapsedRealtimeUs)) {
            }
            TraceUtil.endSection();
        } else if (codec != null) {
            long renderStartTimeMs = SystemClock.elapsedRealtime();
            TraceUtil.beginSection("drainAndFeed");
            while (drainOutputBuffer(positionUs, elapsedRealtimeUs) && shouldContinueRendering(renderStartTimeMs)) {
            }
            while (feedInputBuffer() && shouldContinueRendering(renderStartTimeMs)) {
            }
            TraceUtil.endSection();
        } else {
            decoderCounters.skippedInputBufferCount += skipSource(positionUs);
            // We need to read any format changes despite not having a codec so that drmSession can be
            // updated, and so that we have the most recent format should the codec be initialized. We
            // may also reach the end of the stream. FLAG_PEEK is used because we don't want to advance
            // the source further than skipSource has already done.
            readSourceOmittingSampleData(FLAG_PEEK);
        }
        decoderCounters.ensureUpdated();
    } catch (IllegalStateException e) {
        if (isMediaCodecException(e)) {
            onCodecError(e);
            boolean isRecoverable = Util.SDK_INT >= 21 && isRecoverableMediaCodecExceptionV21(e);
            if (isRecoverable) {
                releaseCodec();
            }
            throw createRendererException(createDecoderException(e, getCodecInfo()), inputFormat, isRecoverable, PlaybackException.ERROR_CODE_DECODING_FAILED);
        }
        throw e;
    }
}
Also used : ExoPlaybackException(androidx.media3.exoplayer.ExoPlaybackException)

Aggregations

PlaybackException (androidx.media3.common.PlaybackException)20 Test (org.junit.Test)12 Nullable (androidx.annotation.Nullable)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 LargeTest (androidx.test.filters.LargeTest)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 Bundle (android.os.Bundle)5 Player (androidx.media3.common.Player)5 MediaItem (androidx.media3.common.MediaItem)4 ExoPlaybackException (androidx.media3.exoplayer.ExoPlaybackException)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Timeline (androidx.media3.common.Timeline)3 MediaControllerCompat (android.support.v4.media.session.MediaControllerCompat)2 PlaybackStateCompat (android.support.v4.media.session.PlaybackStateCompat)2 AudioAttributes (androidx.media3.common.AudioAttributes)2 DeviceInfo (androidx.media3.common.DeviceInfo)2 MediaMetadata (androidx.media3.common.MediaMetadata)2 PlaybackParameters (androidx.media3.common.PlaybackParameters)2 PositionInfo (androidx.media3.common.Player.PositionInfo)2 State (androidx.media3.common.Player.State)2