[Android] Allow setting the audio delay for bluetooth in the delay dialog

Nicolas Pomepuy git at videolan.org
Tue May 18 04:56:13 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon May 17 12:24:22 2021 +0200| [f0578a341f9e0974f698bf93afd861371f070cc9] | committer: Nicolas Pomepuy

Allow setting the audio delay for bluetooth in the delay dialog

Fixes #1997

> https://code.videolan.org/videolan/vlc-android/commit/f0578a341f9e0974f698bf93afd861371f070cc9
---

 application/resources/src/main/res/values/strings.xml    |  3 ++-
 .../vlc-android/res/layout/player_overlay_settings.xml   | 15 +++++++++++++++
 .../src/org/videolan/vlc/gui/video/VideoDelayDelegate.kt | 16 ++++++++++------
 3 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 7fc004cd9..c42e34767 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -514,7 +514,7 @@
     <string name="download_subtitles">Download subtitles</string>
     <string name="browse_folder">Browse folder</string>
     <string name="listen">Listen</string>
-    <string name="save_bluetooth_delay">save delay for bluetooth device</string>
+    <string name="apply_to_bt">Apply to bluetooth device</string>
     <string name="episodes">episodes</string>
     <string name="movies">movies</string>
     <string name="videos">videos</string>
@@ -787,6 +787,7 @@
     <string name="prefersmbv1_summary">Uncheck this setting if you have some difficulties browsing your SMB server</string>
     <string name="apply_to_all">Apply to all videos</string>
     <string name="audio_delay_global">Audio delay set to %s ms for all videos</string>
+    <string name="audio_delay_bt">Audio delay set to %s ms for the bluetooth device</string>
     <string name="warning_stream_speed">Increasing playback speed over 1 for streams may cause stuttering</string>
     <string name="go_to_folder">Browse parent</string>
     <string name="no_sub_renderer">Subtitles are not yet supported while casting</string>
diff --git a/application/vlc-android/res/layout/player_overlay_settings.xml b/application/vlc-android/res/layout/player_overlay_settings.xml
index 615182b91..f4121f406 100644
--- a/application/vlc-android/res/layout/player_overlay_settings.xml
+++ b/application/vlc-android/res/layout/player_overlay_settings.xml
@@ -148,5 +148,20 @@
             app:layout_constraintStart_toStartOf="parent"
             app:layout_constraintTop_toBottomOf="@id/delay_reset_button" />
 
+    <com.google.android.material.button.MaterialButton
+            android:id="@+id/delay_apply_bt"
+            style="@style/Widget.MaterialComponents.Button.TextButton.Dialog.Icon"
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            android:layout_margin="0dp"
+            android:nextFocusLeft="@+id/delay_second_button"
+            android:text="@string/apply_to_bt"
+            android:textColor="@color/white"
+            app:backgroundTint="@color/player_delay_button_background_tint"
+            app:iconTint="@color/grey400transparent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toBottomOf="@id/delay_apply_all" />
+
 
 </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoDelayDelegate.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoDelayDelegate.kt
index 0c8d5fb22..29b13c162 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoDelayDelegate.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoDelayDelegate.kt
@@ -78,6 +78,7 @@ class VideoDelayDelegate(private val player: VideoPlayerActivity) : View.OnClick
     private lateinit var delayTitle: TextView
     private lateinit var delayContainer: View
     private lateinit var delayApplyAll: MaterialButton
+    private lateinit var delayApplyBt: MaterialButton
 
     /**
      * Instantiate all the views, set their click listeners and shows the view.
@@ -100,6 +101,7 @@ class VideoDelayDelegate(private val player: VideoPlayerActivity) : View.OnClick
             delayTitle = player.findViewById(R.id.delay_title)
             delayContainer = player.findViewById(R.id.delay_container)
             delayApplyAll = player.findViewById(R.id.delay_apply_all)
+            delayApplyBt = player.findViewById(R.id.delay_apply_bt)
         }
         delayFirstButton.text = if (playbackSetting == IPlaybackSettingsController.DelayState.AUDIO) player.getString(R.string.audio_delay_start) else player.getString(R.string.subtitle_delay_first)
         delaySecondButton.text = if (playbackSetting == IPlaybackSettingsController.DelayState.AUDIO) player.getString(R.string.audio_delay_end) else player.getString(R.string.subtitle_delay_end)
@@ -109,6 +111,7 @@ class VideoDelayDelegate(private val player: VideoPlayerActivity) : View.OnClick
         delaySecondButton.setOnClickListener(this)
         delayResetButton.setOnClickListener(this)
         delayApplyAll.setOnClickListener(this)
+        delayApplyBt.setOnClickListener(this)
         playbackSettingMinus.setOnTouchListener(OnRepeatListenerTouch(this))
         playbackSettingPlus.setOnTouchListener(OnRepeatListenerTouch(this))
         playbackSettingMinus.setOnKeyListener(OnRepeatListenerKey(this))
@@ -117,6 +120,7 @@ class VideoDelayDelegate(private val player: VideoPlayerActivity) : View.OnClick
         playbackSettingPlus.setVisible()
         delayFirstButton.setVisible()
         delaySecondButton.setVisible()
+        if (playbackSetting == IPlaybackSettingsController.DelayState.AUDIO && (player.audiomanager.isBluetoothA2dpOn || player.audiomanager.isBluetoothScoOn)) delayApplyBt.setVisible() else delayApplyBt.setGone()
         playbackSettingPlus.requestFocus()
         initPlaybackSettingInfo()
         if (playbackSetting == IPlaybackSettingsController.DelayState.AUDIO) delayApplyAll.setVisible() else delayApplyAll.setGone()
@@ -180,6 +184,12 @@ class VideoDelayDelegate(private val player: VideoPlayerActivity) : View.OnClick
                     UiTools.snacker(player, player.getString(R.string.audio_delay_global, "${it.audioDelay / 1000L}"))
                 }
             }
+            R.id.delay_apply_bt -> {
+                player.service?.let {
+                    Settings.getInstance(player).putSingle(KEY_BLUETOOTH_DELAY, it.audioDelay)
+                    UiTools.snacker(player, player.getString(R.string.audio_delay_bt, "${it.audioDelay / 1000L}"))
+                }
+            }
 
         }
     }
@@ -238,12 +248,6 @@ class VideoDelayDelegate(private val player: VideoPlayerActivity) : View.OnClick
         if (playbackSetting == IPlaybackSettingsController.DelayState.OFF) return
         player.service?.let { service ->
             service.saveMediaMeta()
-            if (playbackSetting == IPlaybackSettingsController.DelayState.AUDIO && (player.audiomanager.isBluetoothA2dpOn || player.audiomanager.isBluetoothScoOn)) {
-                val msg = "${player.getString(R.string.audio_delay)}\n${service.audioDelay / 1000L} ms"
-                val sb = Snackbar.make(delayInfo, msg, Snackbar.LENGTH_LONG)
-                sb.setAction(R.string.save_bluetooth_delay, btSaveListener)
-                sb.show()
-            }
             playbackSetting = IPlaybackSettingsController.DelayState.OFF
             playbackSettingMinus.setOnClickListener(null)
             playbackSettingPlus.setOnClickListener(null)



More information about the Android mailing list