> Documentation index: https://developer.android.com/reference/llms.txt

# RtspMediaSource

Artifact: [androidx.media3:media3-exoplayer-rtsp](https://developer.android.com/jetpack/androidx/releases/media3.md.txt) [View Source](https://cs.android.com/search?q=file:androidx/media3/exoplayer/rtsp/RtspMediaSource.java+class:androidx.media3.exoplayer.rtsp.RtspMediaSource)

*** ** * ** ***


```
@UnstableApi
public final class RtspMediaSource extends BaseMediaSource
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.md.txt) |||
| ↳ | [androidx.media3.exoplayer.source.BaseMediaSource](https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource.md.txt) ||
|   | ↳ | [androidx.media3.exoplayer.rtsp.RtspMediaSource](https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtspMediaSource.md.txt) |

*** ** * ** ***

An Rtsp `MediaSource`

## Summary

| ### Nested types |
|---|
| `public final class RtspMediaSource.Factory implements MediaSourceFactory` Factory for `RtspMediaSource` |
| `public class RtspMediaSource.RtspPlaybackException extends IOException` Thrown when an exception or error is encountered during loading an RTSP stream. |
| `public final class RtspMediaSource.RtspUdpUnsupportedTransportException extends RtspMediaSource.RtspPlaybackException` Thrown when an RTSP Unsupported Transport error (461) is encountered during RTSP Setup. |

| ### Constants |
|---|---|
| `static final long` | `DEFAULT_TIMEOUT_MS = 8000` The default value for `setTimeoutMs`. |

| ### Public fields |
|---|---|
| `MediaItem` | `@GuardedBy(value = "this") mediaItem` |

| ### Public methods |
|---|---|
| `boolean` | `canUpdateMediaItem(MediaItem mediaItem)` Returns whether the `MediaItem` for this source can be updated with the provided item. |
| `MediaPeriod` | `createPeriod( MediaSource.MediaPeriodId id, Allocator allocator, long startPositionUs )` Returns a new `MediaPeriod` identified by `periodId`. |
| `synchronized MediaItem` | `getMediaItem()` Returns the `MediaItem` whose media is provided by the source. |
| `void` | `maybeThrowSourceInfoRefreshError()` Throws any pending error encountered while loading or refreshing source information. |
| `void` | `releasePeriod(MediaPeriod mediaPeriod)` Releases the period. |
| `synchronized void` | `updateMediaItem(MediaItem mediaItem)` Updates the `MediaItem` for this source. |

| ### Protected methods |
|---|---|
| `void` | `prepareSourceInternal(@Nullable TransferListener mediaTransferListener)` Starts source preparation and enables the source, see `prepareSource`. |
| `void` | `releaseSourceInternal()` Releases the source, see `releaseSource`. |

### Inherited fields

From [androidx.media3.exoplayer.source.BaseMediaSource](https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource.md.txt) `@Nullable BandwidthMeter` `bandwidthMeter` `@Nullable PlayerId` `playerId`

### Inherited methods

From [androidx.media3.exoplayer.source.BaseMediaSource](https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource.md.txt) `final void` `@UnstableApi
addDrmEventListener(
Handler handler,
DrmSessionEventListener eventListener
)`

Adds a `DrmSessionEventListener` to the list of listeners which are notified of DRM events for this media source.
`final void` `@UnstableApi
addEventListener(
Handler handler,
MediaSourceEventListener eventListener
)`

Adds a `MediaSourceEventListener` to the list of listeners which are notified of media source events.
`final DrmSessionEventListener.EventDispatcher` `createDrmEventDispatcher(
@Nullable MediaSource.MediaPeriodId mediaPeriodId
)`

Returns a `DrmSessionEventListener.EventDispatcher` which dispatches all events to the registered listeners with the specified `MediaPeriodId`
`final DrmSessionEventListener.EventDispatcher` `createDrmEventDispatcher(
int windowIndex,
@Nullable MediaSource.MediaPeriodId mediaPeriodId
)`

Returns a `DrmSessionEventListener.EventDispatcher` which dispatches all events to the registered listeners with the specified window index and `MediaPeriodId`.
`final MediaSourceEventListener.EventDispatcher` `createEventDispatcher(@Nullable MediaSource.MediaPeriodId mediaPeriodId)`

Returns a `MediaSourceEventListener.EventDispatcher` which dispatches all events to the registered listeners with the specified `MediaPeriodId`.
`final MediaSourceEventListener.EventDispatcher` `[createEventDispatcher](https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource.md.txt#createEventDispatcher(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,long))(
MediaSource.MediaPeriodId mediaPeriodId,
long mediaTimeOffsetMs
)`

**This method is deprecated.**

Use `createEventDispatcher` instead.

<br />

`final MediaSourceEventListener.EventDispatcher` `createEventDispatcher(
int windowIndex,
@Nullable MediaSource.MediaPeriodId mediaPeriodId
)`

Returns a `MediaSourceEventListener.EventDispatcher` which dispatches all events to the registered listeners with the specified window index and `MediaPeriodId`.
`final MediaSourceEventListener.EventDispatcher` `[createEventDispatcher](https://developer.android.com/reference/androidx/media3/exoplayer/source/BaseMediaSource.md.txt#createEventDispatcher(int,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,long))(
int windowIndex,
@Nullable MediaSource.MediaPeriodId mediaPeriodId,
long mediaTimeOffsetMs
)`

**This method is deprecated.**

Use `createEventDispatcher` instead.

<br />

`final void` `@UnstableApi
disable(MediaSource.MediaSourceCaller caller)`

Disables the source for the creation of `MediaPeriods`.
`void` `disableInternal()`

Disables the source, see `disable`.
`final void` `@UnstableApi
enable(MediaSource.MediaSourceCaller caller)`

Enables the source for the creation of `MediaPeriods`.
`void` `enableInternal()`

Enables the source, see `enable`.
`final BandwidthMeter` `getBandwidthMeter()`

Returns the `BandwidthMeter` that is used by this media source.
`final PlayerId` `getPlayerId()`

Returns the `PlayerId` of the player using this media source.
`final boolean` `isEnabled()`

Returns whether the source is enabled.
`final void` `@UnstableApi
prepareSource(
MediaSource.MediaSourceCaller caller,
PlayerId playerId,
BandwidthMeter bandwidthMeter
)`

Registers a `MediaSourceCaller`.
`final boolean` `prepareSourceCalled()`

Returns whether the source has `prepareSource` called.
`final void` `refreshSourceInfo(Timeline timeline)`

Updates timeline and manifest and notifies all listeners of the update.
`final void` `@UnstableApi
releaseSource(MediaSource.MediaSourceCaller caller)`

Unregisters a caller, and disables and releases the source if no longer required.
`final void` `@UnstableApi
removeDrmEventListener(DrmSessionEventListener eventListener)`

Removes a `DrmSessionEventListener` from the list of listeners which are notified of DRM events for this media source.
`final void` `@UnstableApi
removeEventListener(MediaSourceEventListener eventListener)`

Removes a `MediaSourceEventListener` from the list of listeners which are notified of media source events.
`final void` `setBandwidthMeter(BandwidthMeter bandwidthMeter)`

Sets the `BandwidthMeter` to be used by this media source.
`final void` `setPlayerId(PlayerId playerId)`

Sets the `PlayerId` of the player using this media source.
From [androidx.media3.exoplayer.source.MediaSource](https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.md.txt) `@Nullable Timeline` `@UnstableApi
getInitialTimeline()`

Returns the initial placeholder timeline that is returned immediately when the real timeline is not yet known, or null to let the player create an initial timeline.
`boolean` `@UnstableApi
isSingleWindow()`

Returns true if the media source is guaranteed to never have zero or more than one window.
`void` `@UnstableApi
[prepareSource](https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.md.txt#prepareSource(androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller,androidx.media3.datasource.TransferListener,androidx.media3.exoplayer.analytics.PlayerId))(
MediaSource.MediaSourceCaller caller,
@Nullable TransferListener mediaTransferListener,
PlayerId playerId
)`

**This method is deprecated.**

Use `prepareSource` instead.

<br />

## Constants

### DEFAULT_TIMEOUT_MS

```
public static final long DEFAULT_TIMEOUT_MS = 8000
```

The default value for `setTimeoutMs`.

## Public fields

### mediaItem

```
@GuardedBy(value = "this")
public MediaItem mediaItem
```

## Public methods

### canUpdateMediaItem

```
public boolean canUpdateMediaItem(MediaItem mediaItem)
```

Returns whether the `MediaItem` for this source can be updated with the provided item.

Should not be called directly from application code.

This method must be called on the application thread.

| Parameters |
|---|---|
| `MediaItem mediaItem` | The new `MediaItem`. |

| Returns |
|---|---|
| `boolean` | Whether the source can be updated using this item. |

### createPeriod

```
public MediaPeriod createPeriod(
    MediaSource.MediaPeriodId id,
    Allocator allocator,
    long startPositionUs
)
```

Returns a new `MediaPeriod` identified by `periodId`.

Should not be called directly from application code.

This method must be called on the playback thread and only if the source is enabled.

| Parameters |
|---|---|
| `MediaSource.MediaPeriodId id` | The identifier of the period. |
| `Allocator allocator` | An `Allocator` from which to obtain media buffer allocations. |
| `long startPositionUs` | The expected start position, in microseconds. |

| Returns |
|---|---|
| `MediaPeriod` | A new `MediaPeriod`. |

### getMediaItem

```
synchronized public MediaItem getMediaItem()
```

Returns the `MediaItem` whose media is provided by the source.

Should not be called directly from application code.

This method must be called on the application thread.

### maybeThrowSourceInfoRefreshError

```
public void maybeThrowSourceInfoRefreshError()
```

Throws any pending error encountered while loading or refreshing source information.

Should not be called directly from application code.

This method must be called on the playback thread and only after `prepareSource`.

### releasePeriod

```
public void releasePeriod(MediaPeriod mediaPeriod)
```

Releases the period.

Should not be called directly from application code.

This method must be called on the playback thread.

| Parameters |
|---|---|
| `MediaPeriod mediaPeriod` | The period to release. |

### updateMediaItem

```
synchronized public void updateMediaItem(MediaItem mediaItem)
```

Updates the `MediaItem` for this source.

Should not be called directly from application code.

This method must be called on the playback thread and only if `canUpdateMediaItem` returns `true` for the new `MediaItem`.

| Parameters |
|---|---|
| `MediaItem mediaItem` | The new `MediaItem`. |

## Protected methods

### prepareSourceInternal

```
protected void prepareSourceInternal(@Nullable TransferListener mediaTransferListener)
```

Starts source preparation and enables the source, see `prepareSource`. This method is called at most once until the next call to `releaseSourceInternal`.

This method is called on the playback thread.

| Parameters |
|---|---|
| `@Nullable TransferListener mediaTransferListener` | The transfer listener which should be informed of any media data transfers. May be null if no listener is available. Note that this listener should usually be only informed of transfers related to the media loads and not of auxiliary loads for manifests and other data. |

### releaseSourceInternal

```
protected void releaseSourceInternal()
```

Releases the source, see `releaseSource`. This method is called exactly once after each call to `prepareSourceInternal`.

This method is called on the playback thread.