Skip to content

Commit

Permalink
Check device capabilities to display picture in picture button (#663)
Browse files Browse the repository at this point in the history
Co-authored-by: Gaëtan Muller <[email protected]>
  • Loading branch information
StaehliJ and MGaetan89 authored Jul 31, 2024
1 parent 8e65327 commit 883bc6f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.graphics.Color
import android.os.Build
Expand Down Expand Up @@ -108,7 +109,10 @@ class SimplePlayerActivity : ComponentActivity(), ServiceConnection {
}

private fun isPictureInPicturePossible(): Boolean {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)
}
return false
}

@Composable
Expand Down Expand Up @@ -144,6 +148,7 @@ class SimplePlayerActivity : ComponentActivity(), ServiceConnection {
.build()
enterPictureInPictureMode(params)
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
@Suppress("DEPRECATION")
enterPictureInPictureMode()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package ch.srgssr.pillarbox.demo.ui.showcases.integrations

import android.app.PictureInPictureParams
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.os.Build
import android.os.Bundle
Expand Down Expand Up @@ -34,7 +35,7 @@ import kotlinx.coroutines.launch
/**
* Media controller activity
*
* Using official guide for background playback at https://developer.android.com/guide/topics/media/media3/getting-started/playing-in-background
* Using official guides for background playback at https://developer.android.com/guide/topics/media/media3/getting-started/playing-in-background
*
* @constructor Create empty Media controller activity
*/
Expand Down Expand Up @@ -66,10 +67,16 @@ class MediaControllerActivity : ComponentActivity() {
}
}

private fun isPictureInPicturePossible(): Boolean {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)
}
return false
}

@Composable
private fun MainView(player: Player) {
val isPictureInPicturePossible = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
val pictureInPictureClick: (() -> Unit)? = if (isPictureInPicturePossible) this::startPictureInPicture else null
val pictureInPictureClick: (() -> Unit)? = if (isPictureInPicturePossible()) this::startPictureInPicture else null
val pictureInPicture by controllerViewModel.pictureInPictureEnabled.collectAsState()
DemoPlayerView(
player = player,
Expand All @@ -86,6 +93,7 @@ class MediaControllerActivity : ComponentActivity() {
.build()
enterPictureInPictureMode(params)
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
@Suppress("DEPRECATION")
enterPictureInPictureMode()
}
}
Expand Down

0 comments on commit 883bc6f

Please sign in to comment.