Skip to content

Commit

Permalink
fix(player): release MediaSession when the player is released
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaultBee committed Jun 10, 2024
1 parent 5ccfec3 commit 63cc92a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import java.io.IOException
* @param initialAutoplay initial autoplay: true to play the video immediately, false otherwise
* @param listener a [ApiVideoPlayerController.Listener] to listen to player events
* @param looper the looper where call to the player are executed. By default, it is the current looper or the main looper.
* @param notificationController the [ApiVideoPlayerNotificationController] to use. It will be released when calling [release].
*/
fun ApiVideoPlayerController(
context: Context,
Expand Down Expand Up @@ -78,6 +79,7 @@ fun ApiVideoPlayerController(
* @param listener the [ApiVideoPlayerController.Listener] to listen to player events
* @param playerView the player view
* @param looper the looper where call to the player are executed. By default, it is the current looper or the main looper.
* @param notificationController the [ApiVideoPlayerNotificationController] to use. It will be released when calling [release].
*/
fun ApiVideoPlayerController(
context: Context,
Expand Down Expand Up @@ -110,6 +112,7 @@ fun ApiVideoPlayerController(
* @param listener the [ApiVideoPlayerController.Listener] to listen to player events
* @param playerView the [PlayerView] to use to display the player
* @param looper the looper where call to the player are executed. By default, it is the current looper or the main looper.
* @param notificationController the [ApiVideoPlayerNotificationController] to use. It will be released when calling [release].
*/
fun ApiVideoPlayerController(
context: Context,
Expand Down Expand Up @@ -145,6 +148,7 @@ fun ApiVideoPlayerController(
* @param listener the [ApiVideoPlayerController.Listener] to listen to player events
* @param surfaceView the [SurfaceView] to use to display the video
* @param looper the looper where call to the player are executed. By default, it is the current looper or the main looper.
* @param notificationController the [ApiVideoPlayerNotificationController] to use. It will be released when calling [release].
*/
fun ApiVideoPlayerController(
context: Context,
Expand Down Expand Up @@ -180,6 +184,7 @@ fun ApiVideoPlayerController(
* @param listener the [ApiVideoPlayerController.Listener] to listen to player events
* @param surface the [Surface] to use to display the video
* @param looper the looper where call to the player are executed. By default, it is the current looper or the main looper.
* @param notificationController the [ApiVideoPlayerNotificationController] to use. It will be released when calling [release].
*/
fun ApiVideoPlayerController(
context: Context,
Expand Down Expand Up @@ -211,6 +216,7 @@ fun ApiVideoPlayerController(
*
* @param context the application context
* @param looper the looper where call to the player are executed. By default, it is the current looper or the main looper.
* @param notificationController the [ApiVideoPlayerNotificationController] to use. It will be released when calling [release].
* @constructor Creates a new controller without a view.
*/
class ApiVideoPlayerController(
Expand All @@ -226,6 +232,7 @@ class ApiVideoPlayerController(
* @param context the application context
* @param playerView the [PlayerView] to use to display the player
* @param looper the looper where call to the player are executed. By default, it is the current looper or the main looper.
* @param notificationController the [ApiVideoPlayerNotificationController] to use. It will be released when calling [release].
*/
constructor(
context: Context,
Expand Down Expand Up @@ -655,6 +662,7 @@ class ApiVideoPlayerController(
notificationController?.hideNotification()
exoplayer.removeAnalyticsListener(exoplayerListener)
analyticsListener?.let { exoplayer.removeAnalyticsListener(it) }
notificationController?.release()
exoplayer.release()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ constructor(
playerNotificationManager.setPlayer(player)
}

fun release() {
mediaSession.release()
}

companion object {
private const val TAG = "PlayerNotificationController"
private const val DEFAULT_NOTIFICATION_ID = 3333
Expand Down

0 comments on commit 63cc92a

Please sign in to comment.