Skip to content

Commit

Permalink
quick and dirty fix for pause on detach on Android API >= 26
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanArmbrust committed Dec 25, 2017
1 parent 0a5823b commit 914d166
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions app/src/main/java/com/naman14/timber/MusicService.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,15 @@ else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
filter.addAction(PREVIOUS_FORCE_ACTION);
filter.addAction(REPEAT_ACTION);
filter.addAction(SHUFFLE_ACTION);
filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
filter.addAction(Intent.ACTION_SCREEN_ON);
// Attach the broadcast listener
registerReceiver(mIntentReceiver, filter);


Receiver mReceiver = new Receiver();
registerReceiver(mReceiver, filter);

mMediaStoreObserver = new MediaStoreObserver(mPlayerHandler);
getContentResolver().registerContentObserver(
MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true, mMediaStoreObserver);
Expand Down Expand Up @@ -2852,4 +2858,17 @@ public void run() {
}
}

private class Receiver extends BroadcastReceiver {
@Override
public void onReceive(Context content, Intent intent)
{
String action = intent.getAction();
if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(action)) {
if (PreferencesUtility.getInstance(content).pauseEnabledOnDetach()) {
pause();
}
}
}
}

}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'io.fabric.tools:gradle:1.+'

// NOTE: Do not place your application dependencies here; they belong
Expand Down

0 comments on commit 914d166

Please sign in to comment.