Search in sources :

Example 96 with Nullable

use of androidx.annotation.Nullable in project ExoPlayer by google.

the class Util method inferContentType.

/**
 * Makes a best guess to infer the {@link ContentType} from a file name.
 *
 * @param fileName Name of the file. It can include the path of the file.
 * @return The content type.
 */
@ContentType
public static int inferContentType(String fileName) {
    fileName = Ascii.toLowerCase(fileName);
    if (fileName.endsWith(".mpd")) {
        return C.TYPE_DASH;
    } else if (fileName.endsWith(".m3u8")) {
        return C.TYPE_HLS;
    }
    Matcher ismMatcher = ISM_URL_PATTERN.matcher(fileName);
    if (ismMatcher.matches()) {
        @Nullable String extensions = ismMatcher.group(2);
        if (extensions != null) {
            if (extensions.contains(ISM_DASH_FORMAT_EXTENSION)) {
                return C.TYPE_DASH;
            } else if (extensions.contains(ISM_HLS_FORMAT_EXTENSION)) {
                return C.TYPE_HLS;
            }
        }
        return C.TYPE_SS;
    }
    return C.TYPE_OTHER;
}
Also used : Matcher(java.util.regex.Matcher) Nullable(androidx.annotation.Nullable) ContentType(com.google.android.exoplayer2.C.ContentType)

Example 97 with Nullable

use of androidx.annotation.Nullable in project ExoPlayer by google.

the class Cue method fromBundle.

private static final Cue fromBundle(Bundle bundle) {
    Builder builder = new Builder();
    @Nullable CharSequence text = bundle.getCharSequence(keyForField(FIELD_TEXT));
    if (text != null) {
        builder.setText(text);
    }
    @Nullable Alignment textAlignment = (Alignment) bundle.getSerializable(keyForField(FIELD_TEXT_ALIGNMENT));
    if (textAlignment != null) {
        builder.setTextAlignment(textAlignment);
    }
    @Nullable Alignment multiRowAlignment = (Alignment) bundle.getSerializable(keyForField(FIELD_MULTI_ROW_ALIGNMENT));
    if (multiRowAlignment != null) {
        builder.setMultiRowAlignment(multiRowAlignment);
    }
    @Nullable Bitmap bitmap = bundle.getParcelable(keyForField(FIELD_BITMAP));
    if (bitmap != null) {
        builder.setBitmap(bitmap);
    }
    if (bundle.containsKey(keyForField(FIELD_LINE)) && bundle.containsKey(keyForField(FIELD_LINE_TYPE))) {
        builder.setLine(bundle.getFloat(keyForField(FIELD_LINE)), bundle.getInt(keyForField(FIELD_LINE_TYPE)));
    }
    if (bundle.containsKey(keyForField(FIELD_LINE_ANCHOR))) {
        builder.setLineAnchor(bundle.getInt(keyForField(FIELD_LINE_ANCHOR)));
    }
    if (bundle.containsKey(keyForField(FIELD_POSITION))) {
        builder.setPosition(bundle.getFloat(keyForField(FIELD_POSITION)));
    }
    if (bundle.containsKey(keyForField(FIELD_POSITION_ANCHOR))) {
        builder.setPositionAnchor(bundle.getInt(keyForField(FIELD_POSITION_ANCHOR)));
    }
    if (bundle.containsKey(keyForField(FIELD_TEXT_SIZE)) && bundle.containsKey(keyForField(FIELD_TEXT_SIZE_TYPE))) {
        builder.setTextSize(bundle.getFloat(keyForField(FIELD_TEXT_SIZE)), bundle.getInt(keyForField(FIELD_TEXT_SIZE_TYPE)));
    }
    if (bundle.containsKey(keyForField(FIELD_SIZE))) {
        builder.setSize(bundle.getFloat(keyForField(FIELD_SIZE)));
    }
    if (bundle.containsKey(keyForField(FIELD_BITMAP_HEIGHT))) {
        builder.setBitmapHeight(bundle.getFloat(keyForField(FIELD_BITMAP_HEIGHT)));
    }
    if (bundle.containsKey(keyForField(FIELD_WINDOW_COLOR))) {
        builder.setWindowColor(bundle.getInt(keyForField(FIELD_WINDOW_COLOR)));
    }
    if (!bundle.getBoolean(keyForField(FIELD_WINDOW_COLOR_SET), /* defaultValue= */
    false)) {
        builder.clearWindowColor();
    }
    if (bundle.containsKey(keyForField(FIELD_VERTICAL_TYPE))) {
        builder.setVerticalType(bundle.getInt(keyForField(FIELD_VERTICAL_TYPE)));
    }
    if (bundle.containsKey(keyForField(FIELD_SHEAR_DEGREES))) {
        builder.setShearDegrees(bundle.getFloat(keyForField(FIELD_SHEAR_DEGREES)));
    }
    return builder.build();
}
Also used : Alignment(android.text.Layout.Alignment) Bitmap(android.graphics.Bitmap) Nullable(androidx.annotation.Nullable)

Example 98 with Nullable

use of androidx.annotation.Nullable in project ExoPlayer by google.

the class MediaMetricsListener method getErrorInfo.

private static ErrorInfo getErrorInfo(PlaybackException error, Context context, boolean lastIoErrorForManifest) {
    if (error.errorCode == PlaybackException.ERROR_CODE_REMOTE_ERROR) {
        return new ErrorInfo(PlaybackErrorEvent.ERROR_PLAYER_REMOTE, /* subErrorCode= */
        0);
    }
    // Unpack the PlaybackException.
    // TODO(b/190203080): Use error codes instead of the Exception's cause where possible.
    boolean isRendererExoPlaybackException = false;
    int rendererFormatSupport = C.FORMAT_UNSUPPORTED_TYPE;
    if (error instanceof ExoPlaybackException) {
        ExoPlaybackException exoPlaybackException = (ExoPlaybackException) error;
        isRendererExoPlaybackException = exoPlaybackException.type == ExoPlaybackException.TYPE_RENDERER;
        rendererFormatSupport = exoPlaybackException.rendererFormatSupport;
    }
    Throwable cause = checkNotNull(error.getCause());
    if (cause instanceof IOException) {
        if (cause instanceof HttpDataSource.InvalidResponseCodeException) {
            int responseCode = ((HttpDataSource.InvalidResponseCodeException) cause).responseCode;
            return new ErrorInfo(PlaybackErrorEvent.ERROR_IO_BAD_HTTP_STATUS, /* subErrorCode= */
            responseCode);
        } else if (cause instanceof HttpDataSource.InvalidContentTypeException || cause instanceof ParserException) {
            return new ErrorInfo(lastIoErrorForManifest ? PlaybackErrorEvent.ERROR_PARSING_MANIFEST_MALFORMED : PlaybackErrorEvent.ERROR_PARSING_CONTAINER_MALFORMED, /* subErrorCode= */
            0);
        } else if (cause instanceof HttpDataSource.HttpDataSourceException || cause instanceof UdpDataSource.UdpDataSourceException) {
            if (NetworkTypeObserver.getInstance(context).getNetworkType() == C.NETWORK_TYPE_OFFLINE) {
                return new ErrorInfo(PlaybackErrorEvent.ERROR_IO_NETWORK_UNAVAILABLE, /* subErrorCode= */
                0);
            } else {
                @Nullable Throwable detailedCause = cause.getCause();
                if (detailedCause instanceof UnknownHostException) {
                    return new ErrorInfo(PlaybackErrorEvent.ERROR_IO_DNS_FAILED, /* subErrorCode= */
                    0);
                } else if (detailedCause instanceof SocketTimeoutException) {
                    return new ErrorInfo(PlaybackErrorEvent.ERROR_IO_CONNECTION_TIMEOUT, /* subErrorCode= */
                    0);
                } else if (cause instanceof HttpDataSource.HttpDataSourceException && ((HttpDataSource.HttpDataSourceException) cause).type == HttpDataSource.HttpDataSourceException.TYPE_OPEN) {
                    return new ErrorInfo(PlaybackErrorEvent.ERROR_IO_NETWORK_CONNECTION_FAILED, /* subErrorCode= */
                    0);
                } else {
                    return new ErrorInfo(PlaybackErrorEvent.ERROR_IO_CONNECTION_CLOSED, /* subErrorCode= */
                    0);
                }
            }
        } else if (error.errorCode == PlaybackException.ERROR_CODE_BEHIND_LIVE_WINDOW) {
            return new ErrorInfo(PlaybackErrorEvent.ERROR_PLAYER_BEHIND_LIVE_WINDOW, /* subErrorCode= */
            0);
        } else if (cause instanceof DrmSession.DrmSessionException) {
            // Unpack DrmSessionException.
            cause = checkNotNull(cause.getCause());
            if (Util.SDK_INT >= 21 && cause instanceof MediaDrm.MediaDrmStateException) {
                String diagnosticsInfo = ((MediaDrm.MediaDrmStateException) cause).getDiagnosticInfo();
                int subErrorCode = Util.getErrorCodeFromPlatformDiagnosticsInfo(diagnosticsInfo);
                int errorCode = getDrmErrorCode(subErrorCode);
                return new ErrorInfo(errorCode, subErrorCode);
            } else if (Util.SDK_INT >= 23 && cause instanceof MediaDrmResetException) {
                return new ErrorInfo(PlaybackErrorEvent.ERROR_DRM_SYSTEM_ERROR, /* subErrorCode= */
                0);
            } else if (Util.SDK_INT >= 18 && cause instanceof NotProvisionedException) {
                return new ErrorInfo(PlaybackErrorEvent.ERROR_DRM_PROVISIONING_FAILED, /* subErrorCode= */
                0);
            } else if (Util.SDK_INT >= 18 && cause instanceof DeniedByServerException) {
                return new ErrorInfo(PlaybackErrorEvent.ERROR_DRM_DEVICE_REVOKED, /* subErrorCode= */
                0);
            } else if (cause instanceof UnsupportedDrmException) {
                return new ErrorInfo(PlaybackErrorEvent.ERROR_DRM_SCHEME_UNSUPPORTED, /* subErrorCode= */
                0);
            } else if (cause instanceof DefaultDrmSessionManager.MissingSchemeDataException) {
                return new ErrorInfo(PlaybackErrorEvent.ERROR_DRM_CONTENT_ERROR, /* subErrorCode= */
                0);
            } else {
                return new ErrorInfo(PlaybackErrorEvent.ERROR_DRM_OTHER, /* subErrorCode= */
                0);
            }
        } else if (cause instanceof FileDataSource.FileDataSourceException && cause.getCause() instanceof FileNotFoundException) {
            @Nullable Throwable notFoundCause = checkNotNull(cause.getCause()).getCause();
            if (Util.SDK_INT >= 21 && notFoundCause instanceof ErrnoException && ((ErrnoException) notFoundCause).errno == OsConstants.EACCES) {
                return new ErrorInfo(PlaybackErrorEvent.ERROR_IO_NO_PERMISSION, /* subErrorCode= */
                0);
            } else {
                return new ErrorInfo(PlaybackErrorEvent.ERROR_IO_FILE_NOT_FOUND, /* subErrorCode= */
                0);
            }
        } else {
            return new ErrorInfo(PlaybackErrorEvent.ERROR_IO_OTHER, /* subErrorCode= */
            0);
        }
    } else if (isRendererExoPlaybackException && (rendererFormatSupport == C.FORMAT_UNSUPPORTED_TYPE || rendererFormatSupport == C.FORMAT_UNSUPPORTED_SUBTYPE)) {
        return new ErrorInfo(PlaybackErrorEvent.ERROR_DECODING_FORMAT_UNSUPPORTED, /* subErrorCode= */
        0);
    } else if (isRendererExoPlaybackException && rendererFormatSupport == C.FORMAT_EXCEEDS_CAPABILITIES) {
        return new ErrorInfo(PlaybackErrorEvent.ERROR_DECODING_FORMAT_EXCEEDS_CAPABILITIES, /* subErrorCode= */
        0);
    } else if (isRendererExoPlaybackException && rendererFormatSupport == C.FORMAT_UNSUPPORTED_DRM) {
        return new ErrorInfo(PlaybackErrorEvent.ERROR_DRM_SCHEME_UNSUPPORTED, /* subErrorCode= */
        0);
    } else if (cause instanceof MediaCodecRenderer.DecoderInitializationException) {
        @Nullable String diagnosticsInfo = ((MediaCodecRenderer.DecoderInitializationException) cause).diagnosticInfo;
        int subErrorCode = Util.getErrorCodeFromPlatformDiagnosticsInfo(diagnosticsInfo);
        return new ErrorInfo(PlaybackErrorEvent.ERROR_DECODER_INIT_FAILED, subErrorCode);
    } else if (cause instanceof MediaCodecDecoderException) {
        @Nullable String diagnosticsInfo = ((MediaCodecDecoderException) cause).diagnosticInfo;
        int subErrorCode = Util.getErrorCodeFromPlatformDiagnosticsInfo(diagnosticsInfo);
        return new ErrorInfo(PlaybackErrorEvent.ERROR_DECODING_FAILED, subErrorCode);
    } else if (cause instanceof OutOfMemoryError) {
        return new ErrorInfo(PlaybackErrorEvent.ERROR_DECODING_FAILED, /* subErrorCode= */
        0);
    } else if (cause instanceof AudioSink.InitializationException) {
        int subErrorCode = ((AudioSink.InitializationException) cause).audioTrackState;
        return new ErrorInfo(PlaybackErrorEvent.ERROR_AUDIO_TRACK_INIT_FAILED, subErrorCode);
    } else if (cause instanceof AudioSink.WriteException) {
        int subErrorCode = ((AudioSink.WriteException) cause).errorCode;
        return new ErrorInfo(PlaybackErrorEvent.ERROR_AUDIO_TRACK_WRITE_FAILED, subErrorCode);
    } else if (Util.SDK_INT >= 16 && cause instanceof MediaCodec.CryptoException) {
        int subErrorCode = ((MediaCodec.CryptoException) cause).getErrorCode();
        int errorCode = getDrmErrorCode(subErrorCode);
        return new ErrorInfo(errorCode, subErrorCode);
    } else {
        return new ErrorInfo(PlaybackErrorEvent.ERROR_PLAYER_OTHER, /* subErrorCode= */
        0);
    }
}
Also used : AudioSink(com.google.android.exoplayer2.audio.AudioSink) DefaultDrmSessionManager(com.google.android.exoplayer2.drm.DefaultDrmSessionManager) FileNotFoundException(java.io.FileNotFoundException) MediaDrm(android.media.MediaDrm) MediaCodec(android.media.MediaCodec) HttpDataSource(com.google.android.exoplayer2.upstream.HttpDataSource) NotProvisionedException(android.media.NotProvisionedException) UnsupportedDrmException(com.google.android.exoplayer2.drm.UnsupportedDrmException) ParserException(com.google.android.exoplayer2.ParserException) UnknownHostException(java.net.UnknownHostException) MediaDrmResetException(android.media.MediaDrmResetException) ExoPlaybackException(com.google.android.exoplayer2.ExoPlaybackException) IOException(java.io.IOException) SuppressLint(android.annotation.SuppressLint) DeniedByServerException(android.media.DeniedByServerException) SocketTimeoutException(java.net.SocketTimeoutException) ErrnoException(android.system.ErrnoException) UdpDataSource(com.google.android.exoplayer2.upstream.UdpDataSource) MediaCodecDecoderException(com.google.android.exoplayer2.mediacodec.MediaCodecDecoderException) Nullable(androidx.annotation.Nullable)

Example 99 with Nullable

use of androidx.annotation.Nullable in project ExoPlayer by google.

the class MediaMetricsListener method onVideoSizeChanged.

@Override
public void onVideoSizeChanged(EventTime eventTime, VideoSize videoSize) {
    @Nullable PendingFormatUpdate pendingVideoFormat = this.pendingVideoFormat;
    if (pendingVideoFormat != null && pendingVideoFormat.format.height == Format.NO_VALUE) {
        Format formatWithHeightAndWidth = pendingVideoFormat.format.buildUpon().setWidth(videoSize.width).setHeight(videoSize.height).build();
        this.pendingVideoFormat = new PendingFormatUpdate(formatWithHeightAndWidth, pendingVideoFormat.selectionReason, pendingVideoFormat.sessionId);
    }
}
Also used : Format(com.google.android.exoplayer2.Format) Nullable(androidx.annotation.Nullable)

Example 100 with Nullable

use of androidx.annotation.Nullable in project ExoPlayer by google.

the class MediaCodecAudioRenderer method onInputFormatChanged.

@Override
@Nullable
protected DecoderReuseEvaluation onInputFormatChanged(FormatHolder formatHolder) throws ExoPlaybackException {
    @Nullable DecoderReuseEvaluation evaluation = super.onInputFormatChanged(formatHolder);
    eventDispatcher.inputFormatChanged(formatHolder.format, evaluation);
    return evaluation;
}
Also used : DecoderReuseEvaluation(com.google.android.exoplayer2.decoder.DecoderReuseEvaluation) Nullable(androidx.annotation.Nullable) Nullable(androidx.annotation.Nullable)

Aggregations

Nullable (androidx.annotation.Nullable)1124 View (android.view.View)188 Bundle (android.os.Bundle)111 IOException (java.io.IOException)99 NonNull (androidx.annotation.NonNull)96 ArrayList (java.util.ArrayList)95 Context (android.content.Context)93 TextView (android.widget.TextView)92 Cursor (android.database.Cursor)71 SuppressLint (android.annotation.SuppressLint)69 Uri (android.net.Uri)66 RecyclerView (androidx.recyclerview.widget.RecyclerView)59 List (java.util.List)58 ViewGroup (android.view.ViewGroup)56 Test (org.junit.Test)55 Intent (android.content.Intent)53 Recipient (org.thoughtcrime.securesms.recipients.Recipient)52 R (org.thoughtcrime.securesms.R)46 LayoutInflater (android.view.LayoutInflater)45 ImageView (android.widget.ImageView)43