# CloudMediaProvider.CloudMediaSurfaceController

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Also in[R Extensions 3](https://developer.android.com/sdkExtensions)

# CloudMediaSurfaceController

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/provider/CloudMediaProvider.CloudMediaSurfaceController "View this page in Java")  

```
abstract class CloudMediaSurfaceController
```

|---|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                                                                     ||
| ↳ | [android.provider.CloudMediaProvider.CloudMediaSurfaceController](https://developer.android.com/reference/kotlin/android/provider/CloudMediaProvider.CloudMediaSurfaceController#) |

Manages rendering the preview of media items on given instances of[Surface](https://developer.android.com/reference/kotlin/android/view/Surface.html#).

The methods of this class are meant to be asynchronous, and should not block by performing any heavy operation.

Note that a single CloudMediaSurfaceController instance would be responsible for rendering multiple media items associated with multiple surfaces.

## Summary

|                                                                                    Public constructors                                                                                    ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [CloudMediaSurfaceController](https://developer.android.com/reference/kotlin/android/provider/CloudMediaProvider.CloudMediaSurfaceController#CloudMediaSurfaceController())`()` <br /> |

|                                                                                                                                                                                                                                                                                                                                                                                                       Public methods                                                                                                                                                                                                                                                                                                                                                                                                       ||
|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onConfigChange](https://developer.android.com/reference/kotlin/android/provider/CloudMediaProvider.CloudMediaSurfaceController#onConfigChange(android.os.Bundle))`(`config:` `[Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)`)` Changes the configuration parameters for the CloudMediaSurfaceController.                                                                                                                                                                                                                                                                                                                                                                                         |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onDestroy](https://developer.android.com/reference/kotlin/android/provider/CloudMediaProvider.CloudMediaSurfaceController#onDestroy())`()` Indicates destruction of this CloudMediaSurfaceController object.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onMediaPause](https://developer.android.com/reference/kotlin/android/provider/CloudMediaProvider.CloudMediaSurfaceController#onMediaPause(kotlin.Int))`(`surfaceId:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Pauses the playback of the media associated with the given surface id.                                                                                                                                                                                                                                                                                                                                                                                                          |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onMediaPlay](https://developer.android.com/reference/kotlin/android/provider/CloudMediaProvider.CloudMediaSurfaceController#onMediaPlay(kotlin.Int))`(`surfaceId:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Start playing the preview of the media associated with the given surface id.                                                                                                                                                                                                                                                                                                                                                                                                      |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onMediaSeekTo](https://developer.android.com/reference/kotlin/android/provider/CloudMediaProvider.CloudMediaSurfaceController#onMediaSeekTo(kotlin.Int,%20kotlin.Long))`(`surfaceId:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `timestampMillis:` `[Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`)` Seeks the media associated with the given surface id to specified timestamp.                                                                                                                                                                                                                                                                                |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onPlayerCreate](https://developer.android.com/reference/kotlin/android/provider/CloudMediaProvider.CloudMediaSurfaceController#onPlayerCreate())`()` Creates any player resource(s) needed for rendering.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onPlayerRelease](https://developer.android.com/reference/kotlin/android/provider/CloudMediaProvider.CloudMediaSurfaceController#onPlayerRelease())`()` Releases any player resource(s) used for rendering.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onSurfaceChanged](https://developer.android.com/reference/kotlin/android/provider/CloudMediaProvider.CloudMediaSurfaceController#onSurfaceChanged(kotlin.Int,%20kotlin.Int,%20kotlin.Int,%20kotlin.Int))`(`surfaceId:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `format:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `width:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `height:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Indicates structural changes (format or size) in the[Surface](https://developer.android.com/reference/kotlin/android/view/Surface.html#)for rendering. |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onSurfaceCreated](https://developer.android.com/reference/kotlin/android/provider/CloudMediaProvider.CloudMediaSurfaceController#onSurfaceCreated(kotlin.Int,%20android.view.Surface,%20kotlin.String))`(`surfaceId:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `surface:` `[Surface](https://developer.android.com/reference/kotlin/android/view/Surface.html#)`, `mediaId:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`)` Indicates creation of the given[Surface](https://developer.android.com/reference/kotlin/android/view/Surface.html#)with given`surfaceId`for rendering the preview of a media item with given`mediaId`.                       |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onSurfaceDestroyed](https://developer.android.com/reference/kotlin/android/provider/CloudMediaProvider.CloudMediaSurfaceController#onSurfaceDestroyed(kotlin.Int))`(`surfaceId:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Indicates destruction of a[Surface](https://developer.android.com/reference/kotlin/android/view/Surface.html#)with given`surfaceId`.                                                                                                                                                                                                                                                                                                                                |

## Public constructors

### CloudMediaSurfaceController

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Also in[R Extensions 3](https://developer.android.com/sdkExtensions)  

```
CloudMediaSurfaceController()
```

## Public methods

### onConfigChange

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Also in[R Extensions 3](https://developer.android.com/sdkExtensions)  

```
abstract fun onConfigChange(config: Bundle): Unit
```

Changes the configuration parameters for the CloudMediaSurfaceController.

|                                                                                                                                                                                                                                                                                                                     Parameters                                                                                                                                                                                                                                                                                                                     ||
|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `config` | [Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#):the updated config to change to. This can include config changes for the following: - [CloudMediaProviderContract.EXTRA_LOOPING_PLAYBACK_ENABLED](https://developer.android.com/reference/kotlin/android/provider/CloudMediaProviderContract#EXTRA_LOOPING_PLAYBACK_ENABLED:kotlin.String) - [CloudMediaProviderContract.EXTRA_SURFACE_CONTROLLER_AUDIO_MUTE_ENABLED](https://developer.android.com/reference/kotlin/android/provider/CloudMediaProviderContract#EXTRA_SURFACE_CONTROLLER_AUDIO_MUTE_ENABLED:kotlin.String) This value cannot be`null`. |

### onDestroy

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Also in[R Extensions 3](https://developer.android.com/sdkExtensions)  

```
abstract fun onDestroy(): Unit
```

Indicates destruction of this CloudMediaSurfaceController object.

This CloudMediaSurfaceController object should no longer be in use after this method has been called.

Note that it is possible for this method to be called directly without[onPlayerRelease](https://developer.android.com/reference/kotlin/android/provider/CloudMediaProvider.CloudMediaSurfaceController#onPlayerRelease())being called, hence you should release any resources associated with this CloudMediaSurfaceController object, or perform any cleanup required in this method.  

### onMediaPause

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Also in[R Extensions 3](https://developer.android.com/sdkExtensions)  

```
abstract fun onMediaPause(surfaceId: Int): Unit
```

Pauses the playback of the media associated with the given surface id.

|                                                                                                        Parameters                                                                                                         ||
|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `surfaceId` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):id which uniquely identifies the[Surface](https://developer.android.com/reference/kotlin/android/view/Surface.html#)for rendering |

### onMediaPlay

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Also in[R Extensions 3](https://developer.android.com/sdkExtensions)  

```
abstract fun onMediaPlay(surfaceId: Int): Unit
```

Start playing the preview of the media associated with the given surface id. If playback had previously been paused, playback will continue from where it was paused. If playback had been stopped, or never started before, playback will start at the beginning.

|                                                                                                        Parameters                                                                                                         ||
|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `surfaceId` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):id which uniquely identifies the[Surface](https://developer.android.com/reference/kotlin/android/view/Surface.html#)for rendering |

### onMediaSeekTo

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Also in[R Extensions 3](https://developer.android.com/sdkExtensions)  

```
abstract fun onMediaSeekTo(
    surfaceId: Int, 
    timestampMillis: Long
): Unit
```

Seeks the media associated with the given surface id to specified timestamp.

|                                                                                                           Parameters                                                                                                            ||
|-------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `surfaceId`       | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):id which uniquely identifies the[Surface](https://developer.android.com/reference/kotlin/android/view/Surface.html#)for rendering |
| `timestampMillis` | [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html):the timestamp in milliseconds from the start to seek to Value is a non-negative duration in milliseconds.                       |

### onPlayerCreate

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Also in[R Extensions 3](https://developer.android.com/sdkExtensions)  

```
abstract fun onPlayerCreate(): Unit
```

Creates any player resource(s) needed for rendering.  

### onPlayerRelease

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Also in[R Extensions 3](https://developer.android.com/sdkExtensions)  

```
abstract fun onPlayerRelease(): Unit
```

Releases any player resource(s) used for rendering.  

### onSurfaceChanged

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Also in[R Extensions 3](https://developer.android.com/sdkExtensions)  

```
abstract fun onSurfaceChanged(
    surfaceId: Int, 
    format: Int, 
    width: Int, 
    height: Int
): Unit
```

Indicates structural changes (format or size) in the[Surface](https://developer.android.com/reference/kotlin/android/view/Surface.html#)for rendering.

This method is always called at least once, after[onSurfaceCreated](https://developer.android.com/reference/kotlin/android/provider/CloudMediaProvider.CloudMediaSurfaceController#onSurfaceCreated(kotlin.Int,%20android.view.Surface,%20kotlin.String)).

|                                                                                                        Parameters                                                                                                         ||
|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `surfaceId` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):id which uniquely identifies the[Surface](https://developer.android.com/reference/kotlin/android/view/Surface.html#)for rendering |
| `format`    | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the new[PixelFormat](https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#)of the surface             |
| `width`     | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the new width of the[Surface](https://developer.android.com/reference/kotlin/android/view/Surface.html#)                          |
| `height`    | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the new height of the[Surface](https://developer.android.com/reference/kotlin/android/view/Surface.html#)                         |

**See Also**

- [android.view.SurfaceHolder.Callback#surfaceChanged(SurfaceHolder, int, int, int)](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder.Callback.html#surfaceChanged(android.view.SurfaceHolder,%20kotlin.Int,%20kotlin.Int,%20kotlin.Int))  

### onSurfaceCreated

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Also in[R Extensions 3](https://developer.android.com/sdkExtensions)  

```
abstract fun onSurfaceCreated(
    surfaceId: Int, 
    surface: Surface, 
    mediaId: String
): Unit
```

Indicates creation of the given[Surface](https://developer.android.com/reference/kotlin/android/view/Surface.html#)with given`surfaceId`for rendering the preview of a media item with given`mediaId`.

This is called immediately after the surface is first created. Implementations of this should start up whatever rendering code they desire.

Note that the given media item remains associated with the given surface id till the[Surface](https://developer.android.com/reference/kotlin/android/view/Surface.html#)is destroyed.

|                                                                                                                                 Parameters                                                                                                                                  ||
|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `surfaceId` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):id which uniquely identifies the[Surface](https://developer.android.com/reference/kotlin/android/view/Surface.html#)for rendering                                                   |
| `surface`   | [Surface](https://developer.android.com/reference/kotlin/android/view/Surface.html#):instance of the[Surface](https://developer.android.com/reference/kotlin/android/view/Surface.html#)on which the media item should be rendered This value cannot be`null`. |
| `mediaId`   | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):id which uniquely identifies the media to be rendered This value cannot be`null`.                                                                                             |

**See Also**

- [android.view.SurfaceHolder.Callback#surfaceCreated(SurfaceHolder)](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder.Callback.html#surfaceCreated(android.view.SurfaceHolder))  

### onSurfaceDestroyed

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Also in[R Extensions 3](https://developer.android.com/sdkExtensions)  

```
abstract fun onSurfaceDestroyed(surfaceId: Int): Unit
```

Indicates destruction of a[Surface](https://developer.android.com/reference/kotlin/android/view/Surface.html#)with given`surfaceId`.

This is called immediately before a surface is being destroyed. After returning from this call, you should no longer try to access this surface.

|                                                                                                        Parameters                                                                                                         ||
|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `surfaceId` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):id which uniquely identifies the[Surface](https://developer.android.com/reference/kotlin/android/view/Surface.html#)for rendering |

**See Also**

- [android.view.SurfaceHolder.Callback#surfaceDestroyed(SurfaceHolder)](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder.Callback.html#surfaceDestroyed(android.view.SurfaceHolder))