minor fixes
This commit is contained in:
parent
d319794a50
commit
6a8cc1ba0c
2 changed files with 49 additions and 34 deletions
|
@ -37,6 +37,7 @@ class AnalysisService : Service() {
|
|||
}
|
||||
}
|
||||
|
||||
try {
|
||||
initChannels(this)
|
||||
|
||||
HandlerThread("Analysis service handler", Process.THREAD_PRIORITY_BACKGROUND).apply {
|
||||
|
@ -44,6 +45,9 @@ class AnalysisService : Service() {
|
|||
serviceLooper = looper
|
||||
serviceHandler = ServiceHandler(looper)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(LOG_TAG, "failed to initialize service", e)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
|
|
@ -35,6 +35,15 @@ class MediaSessionHandler(private val context: Context, private val mediaCommand
|
|||
}
|
||||
|
||||
fun dispose() {
|
||||
unregisterNoisyAudioReceiver()
|
||||
}
|
||||
|
||||
private fun registerNoisyAudioReceiver() {
|
||||
context.registerReceiver(noisyAudioReceiver, IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY))
|
||||
isNoisyAudioReceiverRegistered = true
|
||||
}
|
||||
|
||||
private fun unregisterNoisyAudioReceiver() {
|
||||
if (isNoisyAudioReceiverRegistered) {
|
||||
context.unregisterReceiver(noisyAudioReceiver)
|
||||
isNoisyAudioReceiverRegistered = false
|
||||
|
@ -70,7 +79,7 @@ class MediaSessionHandler(private val context: Context, private val mediaCommand
|
|||
STATE_PAUSED -> PlaybackStateCompat.STATE_PAUSED
|
||||
STATE_PLAYING -> PlaybackStateCompat.STATE_PLAYING
|
||||
else -> {
|
||||
result.error("update-state", "unknown state=$stateString", null)
|
||||
result.error("updateSession-state", "unknown state=$stateString", null)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -93,6 +102,7 @@ class MediaSessionHandler(private val context: Context, private val mediaCommand
|
|||
.build()
|
||||
|
||||
FlutterUtils.runOnUiThread {
|
||||
try {
|
||||
if (session == null) {
|
||||
val mbrIntent = MediaButtonReceiver.buildMediaButtonPendingIntent(context, PlaybackStateCompat.ACTION_PLAY_PAUSE)
|
||||
val mbrName = ComponentName(context, MediaButtonReceiver::class.java)
|
||||
|
@ -116,16 +126,17 @@ class MediaSessionHandler(private val context: Context, private val mediaCommand
|
|||
|
||||
val isPlaying = state == PlaybackStateCompat.STATE_PLAYING
|
||||
if (!wasPlaying && isPlaying) {
|
||||
context.registerReceiver(noisyAudioReceiver, IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY))
|
||||
isNoisyAudioReceiverRegistered = true
|
||||
registerNoisyAudioReceiver()
|
||||
} else if (wasPlaying && !isPlaying) {
|
||||
context.unregisterReceiver(noisyAudioReceiver)
|
||||
isNoisyAudioReceiverRegistered = false
|
||||
unregisterNoisyAudioReceiver()
|
||||
}
|
||||
wasPlaying = isPlaying
|
||||
}
|
||||
|
||||
result.success(null)
|
||||
} catch (e: Exception) {
|
||||
result.error("updateSession-exception", e.message, e.stackTraceToString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun releaseSession(@Suppress("unused_parameter") call: MethodCall, result: MethodChannel.Result) {
|
||||
|
|
Loading…
Reference in a new issue