Fix pausing playback on disconnect on API 26+

This commit is contained in:
Andrew Rabert 2018-03-24 13:35:51 -04:00
parent 13b35c5e4e
commit cab37665c6
3 changed files with 14 additions and 6 deletions

View File

@ -1,6 +1,10 @@
Changelog Changelog
========= =========
## Next
* Fix pausing playback on disconnect on API 26+
## Version 0.2.4 ## Version 0.2.4
_2018-03-24_ _2018-03-24_
* Fix launch crash on Lollipop and earlier (added READ_PHONE_STATE for API <= 22) [#23](https://github.com/nvllsvm/Audinaut/issues/23) * Fix launch crash on Lollipop and earlier (added READ_PHONE_STATE for API <= 22) [#23](https://github.com/nvllsvm/Audinaut/issues/23)

View File

@ -104,12 +104,6 @@
</intent-filter> </intent-filter>
</receiver> </receiver>
<receiver android:name="net.nullsum.audinaut.receiver.AudioNoisyReceiver">
<intent-filter android:priority="999">
<action android:name="android.media.AUDIO_BECOMING_NOISY" />
</intent-filter>
</receiver>
<receiver android:name="net.nullsum.audinaut.receiver.A2dpIntentReceiver"> <receiver android:name="net.nullsum.audinaut.receiver.A2dpIntentReceiver">
<intent-filter> <intent-filter>
<action android:name="android.music.playstatusrequest"/> <action android:name="android.music.playstatusrequest"/>

View File

@ -35,6 +35,7 @@ import net.nullsum.audinaut.audiofx.EqualizerController;
import net.nullsum.audinaut.domain.MusicDirectory; import net.nullsum.audinaut.domain.MusicDirectory;
import net.nullsum.audinaut.domain.PlayerState; import net.nullsum.audinaut.domain.PlayerState;
import net.nullsum.audinaut.domain.RepeatMode; import net.nullsum.audinaut.domain.RepeatMode;
import net.nullsum.audinaut.receiver.AudioNoisyReceiver;
import net.nullsum.audinaut.receiver.MediaButtonIntentReceiver; import net.nullsum.audinaut.receiver.MediaButtonIntentReceiver;
import net.nullsum.audinaut.util.BufferProxy; import net.nullsum.audinaut.util.BufferProxy;
import net.nullsum.audinaut.util.Constants; import net.nullsum.audinaut.util.Constants;
@ -63,6 +64,7 @@ import android.content.ComponentCallbacks2;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.media.AudioManager; import android.media.AudioManager;
import android.media.MediaPlayer; import android.media.MediaPlayer;
@ -157,6 +159,8 @@ public class DownloadService extends Service {
private long subtractNextPosition = 0; private long subtractNextPosition = 0;
private int subtractPosition = 0; private int subtractPosition = 0;
private AudioNoisyReceiver audioNoisyReceiver = new AudioNoisyReceiver();
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
@ -239,6 +243,10 @@ public class DownloadService extends Service {
instance = this; instance = this;
shufflePlayBuffer = new ShufflePlayBuffer(this); shufflePlayBuffer = new ShufflePlayBuffer(this);
lifecycleSupport.onCreate(); lifecycleSupport.onCreate();
IntentFilter filter = new IntentFilter();
filter.addAction("android.media.AUDIO_BECOMING_NOISY");
registerReceiver(audioNoisyReceiver, filter);
} }
@Override @Override
@ -308,6 +316,8 @@ public class DownloadService extends Service {
} }
Notifications.hidePlayingNotification(this, this, handler); Notifications.hidePlayingNotification(this, this, handler);
Notifications.hideDownloadingNotification(this, this, handler); Notifications.hideDownloadingNotification(this, this, handler);
unregisterReceiver(audioNoisyReceiver);
} }
public static DownloadService getInstance() { public static DownloadService getInstance() {