resume playback on bluetooth headset connected (wo static broadcast rcv)
This commit is contained in:
parent
018d2ecf0c
commit
f88713544c
@ -3,8 +3,6 @@ apply plugin: 'com.android.application'
|
||||
android {
|
||||
compileSdkVersion 32
|
||||
|
||||
compileSdkVersion 32 // rootProject.ext.compileSdkVersion
|
||||
|
||||
defaultConfig {
|
||||
applicationId "ch.blinkenlights.android.vanilla"
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
|
@ -30,12 +30,15 @@ THE SOFTWARE.
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
|
||||
<!-- This is needed for isWiredHeadsetOn() to work in some cases. (bug?) -->
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||
<!-- Playlist shortcuts -->
|
||||
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
|
||||
|
||||
<!-- Needed for resume playback on bluetooth headset connected feature -->
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
|
||||
<!-- Allow us to query plugins -->
|
||||
<queries>
|
||||
<intent>
|
||||
|
@ -26,11 +26,15 @@ package ch.blinkenlights.android.vanilla;
|
||||
import ch.blinkenlights.android.medialibrary.MediaLibrary;
|
||||
import ch.blinkenlights.android.medialibrary.LibraryObserver;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Notification;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.app.backup.BackupManager;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothHeadset;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
@ -437,6 +441,7 @@ public final class PlaybackService extends Service
|
||||
*/
|
||||
private BastpUtil mBastpUtil;
|
||||
|
||||
@SuppressLint("InvalidWakeLockTag")
|
||||
@Override
|
||||
public void onCreate()
|
||||
{
|
||||
@ -496,6 +501,7 @@ public final class PlaybackService extends Service
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
|
||||
filter.addAction(Intent.ACTION_SCREEN_ON);
|
||||
filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
|
||||
registerReceiver(mReceiver, filter);
|
||||
|
||||
MediaLibrary.registerLibraryObserver(mObserver);
|
||||
@ -1162,7 +1168,7 @@ public final class PlaybackService extends Service
|
||||
|
||||
long[] androidIds = MediaUtils.getAndroidMediaIds(getApplicationContext(), song);
|
||||
if (mStockBroadcast) {
|
||||
Intent intent = new Intent("com.android.music.playstatechanged");
|
||||
Intent intent = new Intent("com.android.music.playstatechanged"); // TODO: Scrobbler interface
|
||||
intent.putExtra("playing", (mState & FLAG_PLAYING) != 0);
|
||||
intent.putExtra("track", song.title);
|
||||
intent.putExtra("album", song.album);
|
||||
@ -1479,6 +1485,22 @@ public final class PlaybackService extends Service
|
||||
}
|
||||
} else if (Intent.ACTION_SCREEN_ON.equals(action)) {
|
||||
userActionTriggered();
|
||||
} else if (BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED.equals(action)) {
|
||||
// Resume playback on bluetooth headset connected
|
||||
// TODO: Resume playback only if playback was paused by BECOMING NOISY
|
||||
int state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1);
|
||||
int prevState = intent.getIntExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, -1);
|
||||
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||
|
||||
if (state == BluetoothProfile.STATE_CONNECTED) {
|
||||
// Move to -2.8 secs on resume
|
||||
int deltedPosition = getPosition() - 2800;
|
||||
if (deltedPosition > 0) {
|
||||
seekToPosition(deltedPosition);
|
||||
}
|
||||
|
||||
play();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user