public class

DataSourceException

extends java.io.IOException

 java.lang.Object

↳java.lang.Throwable

↳java.lang.Exception

↳java.io.IOException

↳androidx.media3.datasource.DataSourceException

Subclasses:

HttpDataSource.HttpDataSourceException, HttpDataSource.CleartextNotPermittedException, HttpDataSource.InvalidContentTypeException, HttpDataSource.InvalidResponseCodeException, UdpDataSource.UdpDataSourceException, FileDataSource.FileDataSourceException, AssetDataSource.AssetDataSourceException, HttpEngineDataSource.OpenException, ContentDataSource.ContentDataSourceException, RawResourceDataSource.RawResourceDataSourceException, CronetDataSource.OpenException

Gradle dependencies

compile group: 'androidx.media3', name: 'media3-datasource', version: '1.5.0-alpha01'

  • groupId: androidx.media3
  • artifactId: media3-datasource
  • version: 1.5.0-alpha01

Artifact androidx.media3:media3-datasource:1.5.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

Used to specify reason of a DataSource error.

Summary

Fields
public static final intPOSITION_OUT_OF_RANGE

Indicates that the starting position of the request was outside the bounds of the data.

public final intreason

The reason of this DataSourceException, should be one of the ERROR_CODE_IO_* in .

Constructors
publicDataSourceException(int reason)

Constructs a DataSourceException.

publicDataSourceException(java.lang.String message, int reason)

Constructs a DataSourceException.

publicDataSourceException(java.lang.String message, java.lang.Throwable cause, int reason)

Constructs a DataSourceException.

publicDataSourceException(java.lang.Throwable cause, int reason)

Constructs a DataSourceException.

Methods
public static booleanisCausedByPositionOutOfRange(java.io.IOException e)

Returns whether the given java.io.IOException was caused by a DataSourceException whose DataSourceException.reason is PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE in its cause stack.

from java.lang.ThrowableaddSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Fields

public static final int POSITION_OUT_OF_RANGE

Deprecated: Use PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE.

Indicates that the starting position of the request was outside the bounds of the data.

public final int reason

The reason of this DataSourceException, should be one of the ERROR_CODE_IO_* in .

Constructors

public DataSourceException(int reason)

Constructs a DataSourceException.

Parameters:

reason: Reason of the error, should be one of the ERROR_CODE_IO_* in .

public DataSourceException(java.lang.Throwable cause, int reason)

Constructs a DataSourceException.

Parameters:

cause: The error cause.
reason: Reason of the error, should be one of the ERROR_CODE_IO_* in .

public DataSourceException(java.lang.String message, int reason)

Constructs a DataSourceException.

Parameters:

message: The error message.
reason: Reason of the error, should be one of the ERROR_CODE_IO_* in .

public DataSourceException(java.lang.String message, java.lang.Throwable cause, int reason)

Constructs a DataSourceException.

Parameters:

message: The error message.
cause: The error cause.
reason: Reason of the error, should be one of the ERROR_CODE_IO_* in .

Methods

public static boolean isCausedByPositionOutOfRange(java.io.IOException e)

Returns whether the given java.io.IOException was caused by a DataSourceException whose DataSourceException.reason is PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE in its cause stack.

Source

/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package androidx.media3.datasource;

import androidx.annotation.Nullable;
import androidx.media3.common.PlaybackException;
import androidx.media3.common.util.UnstableApi;
import java.io.IOException;

/** Used to specify reason of a DataSource error. */
public class DataSourceException extends IOException {

  /**
   * Returns whether the given {@link IOException} was caused by a {@link DataSourceException} whose
   * {@link #reason} is {@link PlaybackException#ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE} in its
   * cause stack.
   */
  @UnstableApi
  public static boolean isCausedByPositionOutOfRange(IOException e) {
    @Nullable Throwable cause = e;
    while (cause != null) {
      if (cause instanceof DataSourceException) {
        int reason = ((DataSourceException) cause).reason;
        if (reason == PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE) {
          return true;
        }
      }
      cause = cause.getCause();
    }
    return false;
  }

  /**
   * Indicates that the {@link DataSpec#position starting position} of the request was outside the
   * bounds of the data.
   *
   * @deprecated Use {@link PlaybackException#ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE}.
   */
  @UnstableApi @Deprecated
  public static final int POSITION_OUT_OF_RANGE =
      PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE;

  /**
   * The reason of this {@link DataSourceException}, should be one of the {@code ERROR_CODE_IO_*} in
   * {@link PlaybackException.ErrorCode}.
   */
  public final @PlaybackException.ErrorCode int reason;

  /**
   * Constructs a DataSourceException.
   *
   * @param reason Reason of the error, should be one of the {@code ERROR_CODE_IO_*} in {@link
   *     PlaybackException.ErrorCode}.
   */
  @UnstableApi
  public DataSourceException(@PlaybackException.ErrorCode int reason) {
    this.reason = reason;
  }

  /**
   * Constructs a DataSourceException.
   *
   * @param cause The error cause.
   * @param reason Reason of the error, should be one of the {@code ERROR_CODE_IO_*} in {@link
   *     PlaybackException.ErrorCode}.
   */
  @UnstableApi
  public DataSourceException(@Nullable Throwable cause, @PlaybackException.ErrorCode int reason) {
    super(cause);
    this.reason = reason;
  }

  /**
   * Constructs a DataSourceException.
   *
   * @param message The error message.
   * @param reason Reason of the error, should be one of the {@code ERROR_CODE_IO_*} in {@link
   *     PlaybackException.ErrorCode}.
   */
  @UnstableApi
  public DataSourceException(@Nullable String message, @PlaybackException.ErrorCode int reason) {
    super(message);
    this.reason = reason;
  }

  /**
   * Constructs a DataSourceException.
   *
   * @param message The error message.
   * @param cause The error cause.
   * @param reason Reason of the error, should be one of the {@code ERROR_CODE_IO_*} in {@link
   *     PlaybackException.ErrorCode}.
   */
  @UnstableApi
  public DataSourceException(
      @Nullable String message,
      @Nullable Throwable cause,
      @PlaybackException.ErrorCode int reason) {
    super(message, cause);
    this.reason = reason;
  }
}