Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data class AudioContextAndroid(
val stayAwake: Boolean,
val contentType: Int,
val usageType: Int,
val audioFocus: Int?,
val audioFocus: Int,
val audioMode: Int,
) {
@SuppressLint("InlinedApi") // we are just using numerical constants
Expand All @@ -23,7 +23,7 @@ data class AudioContextAndroid(
stayAwake = false,
contentType = CONTENT_TYPE_MUSIC,
usageType = USAGE_MEDIA,
audioFocus = null,
audioFocus = AudioManager.AUDIOFOCUS_GAIN,
audioMode = AudioManager.MODE_NORMAL,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ private fun MethodCall.audioContext(): AudioContextAndroid {
stayAwake = argument<Boolean>("stayAwake") ?: error("stayAwake is required"),
contentType = argument<Int>("contentType") ?: error("contentType is required"),
usageType = argument<Int>("usageType") ?: error("usageType is required"),
audioFocus = argument<Int>("audioFocus"),
audioFocus = argument<Int>("audioFocus") ?: error("audioFocus is required"),
audioMode = argument<Int>("audioMode") ?: error("audioMode is required"),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FocusManager(
get() = player.audioManager

fun maybeRequestAudioFocus(andThen: () -> Unit) {
if (context.audioFocus == null) {
if (context.audioFocus == AudioManager.AUDIOFOCUS_NONE) {
andThen()
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
newRequestAudioFocus(andThen)
Expand All @@ -30,7 +30,7 @@ class FocusManager(
}

fun handleStop() {
if (context.audioFocus != null) {
if (context.audioFocus != AudioManager.AUDIOFOCUS_NONE) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
audioFocusRequest?.let { audioManager.abandonAudioFocusRequest(it) }
} else {
Expand Down Expand Up @@ -72,4 +72,4 @@ class FocusManager(
andThen()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ class WrappedPlayer internal constructor(
if (context == audioContext) {
return
}
if (context.audioFocus != null && audioContext.audioFocus == null) {
if (context.audioFocus != AudioManager.AUDIOFOCUS_NONE
&& audioContext.audioFocus == AudioManager.AUDIOFOCUS_NONE) {
focusManager.handleStop()
}
this.context = audioContext.copy()
Expand Down
Loading