[Android] Apply Chromecast options to LibVLC

Geoffrey Métais git at videolan.org
Thu Jan 25 10:32:37 CET 2018


vlc-android | branch: chromecast | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jan 23 10:51:43 2018 +0100| [582da694623746b5da5c1353727cf61716f2fe2b] | committer: Geoffrey Métais

Apply Chromecast options to LibVLC

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

 .../vlc/gui/preferences/PreferencesCasting.kt         | 19 ++++++++++++++++++-
 vlc-android/src/org/videolan/vlc/util/VLCOptions.java | 10 +++++++---
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesCasting.kt b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesCasting.kt
index 2137dbced..2d15c34cf 100644
--- a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesCasting.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesCasting.kt
@@ -22,11 +22,28 @@
  */
 package org.videolan.vlc.gui.preferences
 
+import android.content.SharedPreferences
+import android.os.Bundle
 import org.videolan.vlc.R
+import org.videolan.vlc.util.VLCInstance
 
-class PreferencesCasting : BasePreferenceFragment() {
+class PreferencesCasting : BasePreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener {
 
     override fun getTitleId() = R.string.casting_category
 
     override fun getXml() = R.xml.preferences_casting
+
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+        preferenceScreen.sharedPreferences.registerOnSharedPreferenceChangeListener(this)
+    }
+
+    override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
+        when (key) {
+            "casting_passthrough", "casting_quality" -> {
+                VLCInstance.restart()
+                (activity as? PreferencesActivity)?.restartMediaPlayer()
+            }
+        }
+    }
 }
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/util/VLCOptions.java b/vlc-android/src/org/videolan/vlc/util/VLCOptions.java
index 572bdb265..f5f44d21f 100644
--- a/vlc-android/src/org/videolan/vlc/util/VLCOptions.java
+++ b/vlc-android/src/org/videolan/vlc/util/VLCOptions.java
@@ -31,10 +31,10 @@ import org.videolan.libvlc.MediaPlayer;
 import org.videolan.libvlc.util.AndroidUtil;
 import org.videolan.libvlc.util.HWDecoderUtil;
 import org.videolan.libvlc.util.VLCUtil;
+import org.videolan.medialibrary.media.MediaWrapper;
 import org.videolan.vlc.R;
 import org.videolan.vlc.RendererDelegate;
 import org.videolan.vlc.VLCApplication;
-import org.videolan.medialibrary.media.MediaWrapper;
 
 import java.io.File;
 import java.util.ArrayList;
@@ -126,7 +126,11 @@ public class VLCOptions {
         options.add("--keystore-file");
         options.add(new File(context.getDir("keystore", Context.MODE_PRIVATE), "file").getAbsolutePath());
 
+        //Chromecast
         options.add(verboseMode ? "-vv" : "-v");
+        if (pref.getBoolean("casting_passthrough", true)) options.add("--sout-chromecast-audio-passthrough");
+        else options.add("--no-sout-chromecast-audio-passthrough");
+        options.add("--sout-chromecast-conversion-quality="+pref.getString("casting_quality", "2"));
 
         return options;
     }
@@ -204,8 +208,8 @@ public class VLCOptions {
         if (prefs.getBoolean("media_fast_seek", false)) media.addOption(":input-fast-seek");
 
         if (RendererDelegate.INSTANCE.getSelectedRenderer() != null) {
-            media.addOption(":sout-chromecast-audio-passthrough="+pref.getBoolean("casting_passthrough", true));
-            media.addOption(":sout-chromecast-conversion-quality="+pref.getString("casting_quality", "2"));
+            media.addOption(":sout-chromecast-audio-passthrough="+prefs.getBoolean("casting_passthrough", true));
+            media.addOption(":sout-chromecast-conversion-quality="+prefs.getString("casting_quality", "2"));
         }
     }
 



More information about the Android mailing list