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)
|
initChannels(this)
|
||||||
|
|
||||||
HandlerThread("Analysis service handler", Process.THREAD_PRIORITY_BACKGROUND).apply {
|
HandlerThread("Analysis service handler", Process.THREAD_PRIORITY_BACKGROUND).apply {
|
||||||
|
@ -44,6 +45,9 @@ class AnalysisService : Service() {
|
||||||
serviceLooper = looper
|
serviceLooper = looper
|
||||||
serviceHandler = ServiceHandler(looper)
|
serviceHandler = ServiceHandler(looper)
|
||||||
}
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(LOG_TAG, "failed to initialize service", e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
|
|
@ -35,6 +35,15 @@ class MediaSessionHandler(private val context: Context, private val mediaCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
fun dispose() {
|
fun dispose() {
|
||||||
|
unregisterNoisyAudioReceiver()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun registerNoisyAudioReceiver() {
|
||||||
|
context.registerReceiver(noisyAudioReceiver, IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY))
|
||||||
|
isNoisyAudioReceiverRegistered = true
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun unregisterNoisyAudioReceiver() {
|
||||||
if (isNoisyAudioReceiverRegistered) {
|
if (isNoisyAudioReceiverRegistered) {
|
||||||
context.unregisterReceiver(noisyAudioReceiver)
|
context.unregisterReceiver(noisyAudioReceiver)
|
||||||
isNoisyAudioReceiverRegistered = false
|
isNoisyAudioReceiverRegistered = false
|
||||||
|
@ -70,7 +79,7 @@ class MediaSessionHandler(private val context: Context, private val mediaCommand
|
||||||
STATE_PAUSED -> PlaybackStateCompat.STATE_PAUSED
|
STATE_PAUSED -> PlaybackStateCompat.STATE_PAUSED
|
||||||
STATE_PLAYING -> PlaybackStateCompat.STATE_PLAYING
|
STATE_PLAYING -> PlaybackStateCompat.STATE_PLAYING
|
||||||
else -> {
|
else -> {
|
||||||
result.error("update-state", "unknown state=$stateString", null)
|
result.error("updateSession-state", "unknown state=$stateString", null)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,6 +102,7 @@ class MediaSessionHandler(private val context: Context, private val mediaCommand
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
FlutterUtils.runOnUiThread {
|
FlutterUtils.runOnUiThread {
|
||||||
|
try {
|
||||||
if (session == null) {
|
if (session == null) {
|
||||||
val mbrIntent = MediaButtonReceiver.buildMediaButtonPendingIntent(context, PlaybackStateCompat.ACTION_PLAY_PAUSE)
|
val mbrIntent = MediaButtonReceiver.buildMediaButtonPendingIntent(context, PlaybackStateCompat.ACTION_PLAY_PAUSE)
|
||||||
val mbrName = ComponentName(context, MediaButtonReceiver::class.java)
|
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
|
val isPlaying = state == PlaybackStateCompat.STATE_PLAYING
|
||||||
if (!wasPlaying && isPlaying) {
|
if (!wasPlaying && isPlaying) {
|
||||||
context.registerReceiver(noisyAudioReceiver, IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY))
|
registerNoisyAudioReceiver()
|
||||||
isNoisyAudioReceiverRegistered = true
|
|
||||||
} else if (wasPlaying && !isPlaying) {
|
} else if (wasPlaying && !isPlaying) {
|
||||||
context.unregisterReceiver(noisyAudioReceiver)
|
unregisterNoisyAudioReceiver()
|
||||||
isNoisyAudioReceiverRegistered = false
|
|
||||||
}
|
}
|
||||||
wasPlaying = isPlaying
|
wasPlaying = isPlaying
|
||||||
}
|
|
||||||
|
|
||||||
result.success(null)
|
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) {
|
private fun releaseSession(@Suppress("unused_parameter") call: MethodCall, result: MethodChannel.Result) {
|
||||||
|
|
Loading…
Reference in a new issue