This commit is contained in:
bvp 2018-02-25 20:07:26 +03:00
parent 5b31bc0d81
commit 1a99e16af7
No known key found for this signature in database
GPG key ID: B26BFEB096ABCEA5
2 changed files with 4 additions and 0 deletions

View file

@ -3,6 +3,7 @@ package com.simplemobiletools.musicplayer.receivers
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.media.AudioManager
import com.simplemobiletools.musicplayer.extensions.sendIntent
import com.simplemobiletools.musicplayer.helpers.PAUSE
@ -15,6 +16,8 @@ class HeadsetPlugReceiver : BroadcastReceiver() {
if (state == 0) {
context.sendIntent(PAUSE)
}
} else if (intent.action == AudioManager.ACTION_AUDIO_BECOMING_NOISY) {
context.sendIntent(PAUSE)
}
}
}

View file

@ -648,6 +648,7 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
if (isPlaying) {
val filter = IntentFilter(Intent.ACTION_HEADSET_PLUG)
filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY)
registerReceiver(mHeadsetPlugReceiver, filter)
} else {
try {