Package com.google.android.exoplayer2.source

## Class CompositeMediaSource<T>

- java.lang.Object
- - com.google.android.exoplayer2.source.BaseMediaSource
  - - com.google.android.exoplayer2.source.CompositeMediaSource<T>

- Type Parameters:
    `T` - The type of the id used to identify prepared child sources.
  All Implemented Interfaces:
    `MediaSource`
  Direct Known Subclasses:
    `AdsMediaSource`, `ClippingMediaSource`, `ConcatenatingMediaSource`, `LoopingMediaSource`, `MaskingMediaSource`, `MergingMediaSource`

      public abstract class CompositeMediaSource<T>
      extends BaseMediaSource

  Composite `MediaSource` consisting of multiple child sources.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface com.google.android.exoplayer2.source.MediaSource

      `MediaSource.MediaPeriodId, MediaSource.MediaSourceCaller`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor | Description
    --- | --- | ---
    `protected` | `CompositeMediaSource()` | Creates composite media source without child sources.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `protected void` | `disableChildSource​(T id)` | Disables a child source.
    `protected void` | `disableInternal()` | Disables the source, see `BaseMediaSource.disable(MediaSourceCaller)`.
    `protected void` | `enableChildSource​(T id)` | Enables a child source.
    `protected void` | `enableInternal()` | Enables the source, see `BaseMediaSource.enable(MediaSourceCaller)`.
    `protected MediaSource.MediaPeriodId` | `getMediaPeriodIdForChildMediaPeriodId​(T id, MediaSource.MediaPeriodId mediaPeriodId)` | Returns the `MediaSource.MediaPeriodId` in the composite source corresponding to the specified `MediaSource.MediaPeriodId` in a child source.
    `protected long` | `getMediaTimeForChildMediaTime​(T id, long mediaTimeMs)` | Returns the media time in the `MediaPeriod` of the composite source corresponding to the specified media time in the `MediaPeriod` of the child source.
    `protected int` | `getWindowIndexForChildWindowIndex​(T id, int windowIndex)` | Returns the window index in the composite source corresponding to the specified window index in a child source.
    `void` | `maybeThrowSourceInfoRefreshError()` | Throws any pending error encountered while loading or refreshing source information.
    `protected abstract void` | `onChildSourceInfoRefreshed​(T id, MediaSource mediaSource, Timeline timeline)` | Called when the source info of a child source has been refreshed.
    `protected void` | `prepareChildSource​(T id, MediaSource mediaSource)` | Prepares a child source.
    `protected void` | `prepareSourceInternal​(TransferListener mediaTransferListener)` | Starts source preparation and enables the source, see `BaseMediaSource.prepareSource(MediaSourceCaller, TransferListener)`.
    `protected void` | `releaseChildSource​(T id)` | Releases a child source.
    `protected void` | `releaseSourceInternal()` | Releases the source, see `BaseMediaSource.releaseSource(MediaSourceCaller)`.

    - ### Methods inherited from class com.google.android.exoplayer2.source.BaseMediaSource

      `addDrmEventListener, addEventListener, createDrmEventDispatcher, createDrmEventDispatcher, createEventDispatcher, createEventDispatcher, createEventDispatcher, disable, enable, isEnabled, prepareSource, refreshSourceInfo, releaseSource, removeDrmEventListener, removeEventListener`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface com.google.android.exoplayer2.source.MediaSource

      `createPeriod, getInitialTimeline, getMediaItem, isSingleWindow, releasePeriod`

- - ### Constructor Detail

    - #### CompositeMediaSource

          protected CompositeMediaSource()

      Creates composite media source without child sources.

  - ### Method Detail

    - #### prepareSourceInternal

          @CallSuper
          protected void prepareSourceInternal​(@Nullable
                                               TransferListener mediaTransferListener)

      Description copied from class: `BaseMediaSource`
      Starts source preparation and enables the source, see `BaseMediaSource.prepareSource(MediaSourceCaller, TransferListener)`. This method is called at most once until the next call to `BaseMediaSource.releaseSourceInternal()`.
      Specified by:
        `prepareSourceInternal` in class `BaseMediaSource`
      Parameters:
        `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.

    - #### maybeThrowSourceInfoRefreshError

          @CallSuper
          public void maybeThrowSourceInfoRefreshError()
                                                throws IOException

      Description copied from interface: `MediaSource`
      Throws any pending error encountered while loading or refreshing source information.

      Should not be called directly from application code.

      Must only be called after `MediaSource.prepareSource(MediaSourceCaller, TransferListener)`.

      Throws:
        `IOException`

    - #### enableInternal

          @CallSuper
          protected void enableInternal()

      Description copied from class: `BaseMediaSource`
      Enables the source, see `BaseMediaSource.enable(MediaSourceCaller)`.
      Overrides:
        `enableInternal` in class `BaseMediaSource`

    - #### disableInternal

          @CallSuper
          protected void disableInternal()

      Description copied from class: `BaseMediaSource`
      Disables the source, see `BaseMediaSource.disable(MediaSourceCaller)`.
      Overrides:
        `disableInternal` in class `BaseMediaSource`

    - #### releaseSourceInternal

          @CallSuper
          protected void releaseSourceInternal()

      Description copied from class: `BaseMediaSource`
      Releases the source, see `BaseMediaSource.releaseSource(MediaSourceCaller)`. This method is called exactly once after each call to `BaseMediaSource.prepareSourceInternal(TransferListener)`.
      Specified by:
        `releaseSourceInternal` in class `BaseMediaSource`

    - #### onChildSourceInfoRefreshed

          protected abstract void onChildSourceInfoRefreshed​(T id,
                                                             MediaSource mediaSource,
                                                             Timeline timeline)

      Called when the source info of a child source has been refreshed.
      Parameters:
        `id` - The unique id used to prepare the child source.
        `mediaSource` - The child source whose source info has been refreshed.
        `timeline` - The timeline of the child source.

    - #### prepareChildSource

          protected final void prepareChildSource​(T id,
                                                  MediaSource mediaSource)

      Prepares a child source.

      `onChildSourceInfoRefreshed(Object, MediaSource, Timeline)` will be called when the child source updates its timeline with the same `id` passed to this method.

      Any child sources that aren't explicitly released with `releaseChildSource(Object)` will be released in `releaseSourceInternal()`.

      Parameters:
        `id` - A unique id to identify the child source preparation. Null is allowed as an id.
        `mediaSource` - The child `MediaSource`.

    - #### enableChildSource

          protected final void enableChildSource​(T id)

      Enables a child source.
      Parameters:
        `id` - The unique id used to prepare the child source.

    - #### disableChildSource

          protected final void disableChildSource​(T id)

      Disables a child source.
      Parameters:
        `id` - The unique id used to prepare the child source.

    - #### releaseChildSource

          protected final void releaseChildSource​(T id)

      Releases a child source.
      Parameters:
        `id` - The unique id used to prepare the child source.

    - #### getWindowIndexForChildWindowIndex

          protected int getWindowIndexForChildWindowIndex​(T id,
                                                          int windowIndex)

      Returns the window index in the composite source corresponding to the specified window index in a child source. The default implementation does not change the window index.
      Parameters:
        `id` - The unique id used to prepare the child source.
        `windowIndex` - A window index of the child source.
      Returns:
        The corresponding window index in the composite source.

    - #### getMediaPeriodIdForChildMediaPeriodId

          @Nullable
          protected MediaSource.MediaPeriodId getMediaPeriodIdForChildMediaPeriodId​(T id,
                                                                                    MediaSource.MediaPeriodId mediaPeriodId)

      Returns the `MediaSource.MediaPeriodId` in the composite source corresponding to the specified `MediaSource.MediaPeriodId` in a child source. The default implementation does not change the media period id.
      Parameters:
        `id` - The unique id used to prepare the child source.
        `mediaPeriodId` - A `MediaSource.MediaPeriodId` of the child source.
      Returns:
        The corresponding `MediaSource.MediaPeriodId` in the composite source. Null if no corresponding media period id can be determined.

    - #### getMediaTimeForChildMediaTime

          protected long getMediaTimeForChildMediaTime​(T id,
                                                       long mediaTimeMs)

      Returns the media time in the `MediaPeriod` of the composite source corresponding to the specified media time in the `MediaPeriod` of the child source. The default implementation does not change the media time.
      Parameters:
        `id` - The unique id used to prepare the child source.
        `mediaTimeMs` - A media time in the `MediaPeriod` of the child source, in milliseconds.
      Returns:
        The corresponding media time in the `MediaPeriod` of the composite source, in milliseconds.