[Android] Auto connect to renderer if only 1 is available
Geoffrey Métais
git at videolan.org
Mon Jan 22 17:01:12 CET 2018
vlc-android | branch: chromecast | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Jan 22 17:00:22 2018 +0100| [84a347bd8faddae5c3de3327fe5c5095dbfeebc3] | committer: Geoffrey Métais
Auto connect to renderer if only 1 is available
> https://code.videolan.org/videolan/vlc-android/commit/84a347bd8faddae5c3de3327fe5c5095dbfeebc3
---
vlc-android/res/values/strings.xml | 1 +
vlc-android/src/org/videolan/vlc/gui/ContentActivity.java | 15 ++++++++++++---
.../src/org/videolan/vlc/gui/dialogs/RenderersDialog.kt | 4 ++++
3 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 5fb5340e6..0648952be 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -377,6 +377,7 @@
<string name="casting_quality_low">Low</string>
<string name="casting_quality_lowcpu">Lowest</string>
<string name="cast_performance_warning">Casting this video requires conversion. This conversion can use all the available power and could quickly drain your battery.</string>
+ <string name="casting_connected_renderer">Connected to renderer \'%1$s\'</string>
<string name="extensions_prefs_category">Extensions</string>
<string name="extensions_enable_category">Chose extensions to enable</string>
diff --git a/vlc-android/src/org/videolan/vlc/gui/ContentActivity.java b/vlc-android/src/org/videolan/vlc/gui/ContentActivity.java
index 195943fe6..8ce7662ba 100644
--- a/vlc-android/src/org/videolan/vlc/gui/ContentActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/ContentActivity.java
@@ -32,6 +32,7 @@ import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.widget.SearchView;
+import android.support.v7.widget.SnapHelper;
import android.view.DragAndDropPermissions;
import android.view.DragEvent;
import android.view.Menu;
@@ -46,6 +47,7 @@ import org.videolan.vlc.RendererDelegate;
import org.videolan.vlc.gui.audio.EqualizerFragment;
import org.videolan.vlc.gui.browser.ExtensionBrowser;
import org.videolan.vlc.gui.dialogs.RenderersDialog;
+import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.interfaces.Filterable;
import org.videolan.vlc.media.MediaUtils;
@@ -111,8 +113,8 @@ public class ContentActivity extends AudioPlayerContainerActivity implements Sea
}
else
menu.findItem(R.id.ml_menu_filter).setVisible(false);
- menu.findItem(R.id.ml_menu_renderers).setVisible(showRenderers);
- menu.findItem(R.id.ml_menu_renderers).setIcon(RendererDelegate.INSTANCE.getSelectedRenderer() == null ? R.drawable.ic_am_renderer_normal_w : R.drawable.ic_am_renderer_on_w);
+ menu.findItem(R.id.ml_menu_renderers).setVisible(showRenderers);
+ menu.findItem(R.id.ml_menu_renderers).setIcon(RendererDelegate.INSTANCE.getSelectedRenderer() == null ? R.drawable.ic_am_renderer_normal_w : R.drawable.ic_am_renderer_on_w);
return super.onCreateOptionsMenu(menu);
}
@@ -142,7 +144,14 @@ public class ContentActivity extends AudioPlayerContainerActivity implements Sea
startActivity(new Intent(Intent.ACTION_SEARCH, null, this, SearchActivity.class));
return true;
case R.id.ml_menu_renderers:
- if (getSupportFragmentManager().findFragmentByTag("renderers") == null)
+ if (mService != null && mService.hasRenderer()
+ && RendererDelegate.INSTANCE.getRenderers().size() == 1) {
+ final RendererItem renderer = RendererDelegate.INSTANCE.getRenderers().get(0);
+ RendererDelegate.INSTANCE.selectRenderer(renderer);
+ mService.setRenderer(renderer);
+ final View v = findViewById(R.id.audio_player_container);
+ if (v != null) UiTools.snacker(v, getString(R.string.casting_connected_renderer, renderer.displayName));
+ } else if (getSupportFragmentManager().findFragmentByTag("renderers") == null)
new RenderersDialog().show(getSupportFragmentManager(), "renderers");
return true;
default:
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/RenderersDialog.kt b/vlc-android/src/org/videolan/vlc/gui/dialogs/RenderersDialog.kt
index 140ac1cd5..6fbc30293 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/RenderersDialog.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/RenderersDialog.kt
@@ -36,6 +36,7 @@ import org.videolan.vlc.databinding.ItemRendererBinding
import org.videolan.vlc.gui.DiffUtilAdapter
import org.videolan.vlc.gui.PlaybackServiceFragment
import org.videolan.vlc.gui.helpers.SelectorViewHolder
+import org.videolan.vlc.gui.helpers.UiTools
class RenderersDialog : DialogFragment(), RendererDelegate.RendererListener, PlaybackService.Client.Callback {
@@ -117,6 +118,9 @@ class RenderersDialog : DialogFragment(), RendererDelegate.RendererListener, Pla
fun connect(item: RendererItem?) {
RendererDelegate.selectRenderer(item)
mService?.setRenderer(item)
+ if (item !== null) activity?.window?.findViewById<View>(R.id.audio_player_container)?.let {
+ UiTools.snacker(it, getString(R.string.casting_connected_renderer, item.displayName))
+ }
dismiss()
}
}
More information about the Android
mailing list