Merge pull request #116 from bvp/master

fixed #115
This commit is contained in:
Tibor Kaputa 2018-02-25 23:44:30 +01:00 committed by GitHub
commit 8bb59c6128
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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 {