use the proper way of stopping the music service

This commit is contained in:
tibbi 2020-05-30 15:50:43 +02:00
parent c8530ea110
commit 5d76833145
4 changed files with 5 additions and 7 deletions

View file

@ -123,7 +123,6 @@
<action android:name="com.simplemobiletools.musicplayer.action.REMOVE_CURRENT_SONG"/>
<action android:name="com.simplemobiletools.musicplayer.action.REMOVE_SONG_IDS"/>
<action android:name="com.simplemobiletools.musicplayer.action.BROADCAST_STATUS"/>
<action android:name="com.simplemobiletools.musicplayer.action.STOP_SERVICE"/>
</intent-filter>
</service>

View file

@ -32,7 +32,6 @@ const val REMOVE_CURRENT_SONG = PATH + "REMOVE_CURRENT_SONG"
const val REMOVE_SONG_IDS = PATH + "REMOVE_SONG_IDS"
const val BROADCAST_STATUS = PATH + "BROADCAST_STATUS"
const val NOTIFICATION_DISMISSED = PATH + "NOTIFICATION_DISMISSED"
const val STOP_SERVICE = PATH + "STOP_SERVICE"
const val NEW_SONG = "NEW_SONG"
const val IS_PLAYING = "IS_PLAYING"

View file

@ -3,11 +3,12 @@ package com.simplemobiletools.musicplayer.receivers
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.simplemobiletools.musicplayer.extensions.sendIntent
import com.simplemobiletools.musicplayer.helpers.STOP_SERVICE
import com.simplemobiletools.musicplayer.services.MusicService
class NotificationDismissedReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
context.sendIntent(STOP_SERVICE)
Intent(context, MusicService::class.java).apply {
context.stopService(this)
}
}
}

View file

@ -131,7 +131,7 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
}
val action = intent.action
if (isOreoPlus() && action != NEXT && action != PREVIOUS && action != PLAYPAUSE && action != STOP_SERVICE) {
if (isOreoPlus() && action != NEXT && action != PREVIOUS && action != PLAYPAUSE) {
setupFakeNotification()
}
@ -158,7 +158,6 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
START_SLEEP_TIMER -> startSleepTimer()
STOP_SLEEP_TIMER -> stopSleepTimer()
BROADCAST_STATUS -> broadcastPlayerStatus()
STOP_SERVICE -> stopSelf()
}
MediaButtonReceiver.handleIntent(mMediaSession!!, intent)