Added setting to disable Now Playing List sending for incompatible bluetooth devices

This commit is contained in:
Nite 2021-09-17 16:45:33 +02:00
parent 8ab903c7d2
commit 77f857b1c6
No known key found for this signature in database
GPG Key ID: 1D1AD59B1C6386C1
5 changed files with 39 additions and 13 deletions

View File

@ -119,6 +119,7 @@ public final class Constants
public static final String PREFERENCES_KEY_DISC_SORT = "discAndTrackSort"; public static final String PREFERENCES_KEY_DISC_SORT = "discAndTrackSort";
public static final String PREFERENCES_KEY_SEND_BLUETOOTH_NOTIFICATIONS = "sendBluetoothNotifications"; public static final String PREFERENCES_KEY_SEND_BLUETOOTH_NOTIFICATIONS = "sendBluetoothNotifications";
public static final String PREFERENCES_KEY_SEND_BLUETOOTH_ALBUM_ART = "sendBluetoothAlbumArt"; public static final String PREFERENCES_KEY_SEND_BLUETOOTH_ALBUM_ART = "sendBluetoothAlbumArt";
public static final String PREFERENCES_KEY_DISABLE_SEND_NOW_PLAYING_LIST = "disableNowPlayingListSending";
public static final String PREFERENCES_KEY_VIEW_REFRESH = "viewRefresh"; public static final String PREFERENCES_KEY_VIEW_REFRESH = "viewRefresh";
public static final String PREFERENCES_KEY_ASK_FOR_SHARE_DETAILS = "sharingAlwaysAskForDetails"; public static final String PREFERENCES_KEY_ASK_FOR_SHARE_DETAILS = "sharingAlwaysAskForDetails";
public static final String PREFERENCES_KEY_DEFAULT_SHARE_DESCRIPTION = "sharingDefaultDescription"; public static final String PREFERENCES_KEY_DEFAULT_SHARE_DESCRIPTION = "sharingDefaultDescription";

View File

@ -43,7 +43,7 @@ class MediaSessionHandler : KoinComponent {
private val applicationContext by inject<Context>() private val applicationContext by inject<Context>()
private var referenceCount: Int = 0 private var referenceCount: Int = 0
private var cachedPlaylist: Iterable<MusicDirectory.Entry>? = null private var cachedPlaylist: List<MediaSessionCompat.QueueItem>? = null
private var playbackPositionDelayCount: Int = 0 private var playbackPositionDelayCount: Int = 0
private var cachedPosition: Long = 0 private var cachedPosition: Long = 0
@ -160,7 +160,7 @@ class MediaSessionHandler : KoinComponent {
// It seems to be the best practice to set this to true for the lifetime of the session // It seems to be the best practice to set this to true for the lifetime of the session
mediaSession?.isActive = true mediaSession?.isActive = true
if (cachedPlaylist != null) updateMediaSessionQueue(cachedPlaylist!!) if (cachedPlaylist != null) setMediaSessionQueue(cachedPlaylist)
Timber.i("MediaSessionHandler.initialize Media Session created") Timber.i("MediaSessionHandler.initialize Media Session created")
} }
@ -245,7 +245,11 @@ class MediaSessionHandler : KoinComponent {
playbackStateBuilder.setActions(playbackActions!!) playbackStateBuilder.setActions(playbackActions!!)
cachedPlayingIndex = currentPlayingIndex cachedPlayingIndex = currentPlayingIndex
if (currentPlayingIndex != null) setMediaSessionQueue(cachedPlaylist)
if (
currentPlayingIndex != null && cachedPlaylist != null &&
!Util.getShouldDisableNowPlayingListSending()
)
playbackStateBuilder.setActiveQueueItemId(currentPlayingIndex) playbackStateBuilder.setActiveQueueItemId(currentPlayingIndex)
// Save the playback state // Save the playback state
@ -254,18 +258,21 @@ class MediaSessionHandler : KoinComponent {
fun updateMediaSessionQueue(playlist: Iterable<MusicDirectory.Entry>) { fun updateMediaSessionQueue(playlist: Iterable<MusicDirectory.Entry>) {
// This call is cached because Downloader may initialize earlier than the MediaSession // This call is cached because Downloader may initialize earlier than the MediaSession
cachedPlaylist = playlist cachedPlaylist = playlist.mapIndexed { id, song ->
MediaSessionCompat.QueueItem(
Util.getMediaDescriptionForEntry(song),
id.toLong()
)
}
setMediaSessionQueue(cachedPlaylist)
}
private fun setMediaSessionQueue(queue: List<MediaSessionCompat.QueueItem>?) {
if (mediaSession == null) return if (mediaSession == null) return
if (Util.getShouldDisableNowPlayingListSending()) return
mediaSession?.setQueueTitle(applicationContext.getString(R.string.button_bar_now_playing)) mediaSession?.setQueueTitle(applicationContext.getString(R.string.button_bar_now_playing))
mediaSession?.setQueue( mediaSession?.setQueue(queue)
playlist.mapIndexed { id, song ->
MediaSessionCompat.QueueItem(
Util.getMediaDescriptionForEntry(song),
id.toLong()
)
}
)
} }
fun updateMediaSessionPlaybackPosition(playbackPosition: Long) { fun updateMediaSessionPlaybackPosition(playbackPosition: Long) {
@ -285,7 +292,10 @@ class MediaSessionHandler : KoinComponent {
playbackStateBuilder.setState(playbackState!!, playbackPosition, 1.0f) playbackStateBuilder.setState(playbackState!!, playbackPosition, 1.0f)
playbackStateBuilder.setActions(playbackActions!!) playbackStateBuilder.setActions(playbackActions!!)
if (cachedPlayingIndex != null) if (
cachedPlayingIndex != null && cachedPlaylist != null &&
!Util.getShouldDisableNowPlayingListSending()
)
playbackStateBuilder.setActiveQueueItemId(cachedPlayingIndex!!) playbackStateBuilder.setActiveQueueItemId(cachedPlayingIndex!!)
mediaSession?.setPlaybackState(playbackStateBuilder.build()) mediaSession?.setPlaybackState(playbackStateBuilder.build())

View File

@ -1097,6 +1097,13 @@ object Util {
return preferences.getBoolean(Constants.PREFERENCES_KEY_SEND_BLUETOOTH_ALBUM_ART, true) return preferences.getBoolean(Constants.PREFERENCES_KEY_SEND_BLUETOOTH_ALBUM_ART, true)
} }
fun getShouldDisableNowPlayingListSending(): Boolean {
val preferences = getPreferences()
return preferences.getBoolean(
Constants.PREFERENCES_KEY_DISABLE_SEND_NOW_PLAYING_LIST, false
)
}
@JvmStatic @JvmStatic
fun getViewRefreshInterval(): Int { fun getViewRefreshInterval(): Int {
val preferences = getPreferences() val preferences = getPreferences()

View File

@ -284,6 +284,8 @@
<string name="settings.search_title">Search Settings</string> <string name="settings.search_title">Search Settings</string>
<string name="settings.send_bluetooth_album_art_summary">Send album art over Bluetooth (May cause Bluetooth notifications to fail)</string> <string name="settings.send_bluetooth_album_art_summary">Send album art over Bluetooth (May cause Bluetooth notifications to fail)</string>
<string name="settings.send_bluetooth_album_art">Album Art Over Bluetooth</string> <string name="settings.send_bluetooth_album_art">Album Art Over Bluetooth</string>
<string name="settings.disable_send_now_playing_list_summary">Now Playing List won\'t be sent to connected devices. This may restore compatibility with AVRCP 1.3 devices, when current track display is not updated</string>
<string name="settings.disable_send_now_playing_list">Disable sending of Now Playing List</string>
<string name="settings.send_bluetooth_notification_summary">Send playback notifications via Bluetooth</string> <string name="settings.send_bluetooth_notification_summary">Send playback notifications via Bluetooth</string>
<string name="settings.send_bluetooth_notification">Send Bluetooth Notification</string> <string name="settings.send_bluetooth_notification">Send Bluetooth Notification</string>
<string name="settings.server_manage_servers">Manage Servers</string> <string name="settings.server_manage_servers">Manage Servers</string>

View File

@ -179,6 +179,12 @@
a:summary="@string/settings.send_bluetooth_album_art_summary" a:summary="@string/settings.send_bluetooth_album_art_summary"
a:title="@string/settings.send_bluetooth_album_art" a:title="@string/settings.send_bluetooth_album_art"
app:iconSpaceReserved="false"/> app:iconSpaceReserved="false"/>
<CheckBoxPreference
a:defaultValue="false"
a:key="disableNowPlayingListSending"
a:summary="@string/settings.disable_send_now_playing_list_summary"
a:title="@string/settings.disable_send_now_playing_list"
app:iconSpaceReserved="false"/>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
a:title="@string/settings.sharing_title" a:title="@string/settings.sharing_title"