diff --git a/fermata/src/main/java/me/aap/fermata/ui/activity/VoiceCommandHandler.java b/fermata/src/main/java/me/aap/fermata/ui/activity/VoiceCommandHandler.java index fa539ae9..b00010c6 100644 --- a/fermata/src/main/java/me/aap/fermata/ui/activity/VoiceCommandHandler.java +++ b/fermata/src/main/java/me/aap/fermata/ui/activity/VoiceCommandHandler.java @@ -21,6 +21,10 @@ import me.aap.fermata.R; import me.aap.fermata.addon.AddonManager; +import me.aap.fermata.media.engine.MediaEngine; +import me.aap.fermata.media.engine.MediaEngineManager; +import me.aap.fermata.media.engine.SubtitleStreamInfo; +import me.aap.fermata.media.service.MediaSessionCallback; import me.aap.fermata.ui.fragment.FavoritesFragment; import me.aap.fermata.ui.fragment.MainActivityFragment; import me.aap.fermata.ui.fragment.MediaLibFragment; @@ -44,6 +48,10 @@ class VoiceCommandHandler { private final Pattern aStop; private final Pattern aPlay; private final Pattern aPlayFavorites; + private final Pattern aSubOn; + private final Pattern aSubOff; + private final Pattern aSubChange; + private final Pattern aAudioChange; private final Pattern lFolders; private final Pattern lFavorites; private final Pattern lPlaylists; @@ -68,6 +76,10 @@ class VoiceCommandHandler { aStop = compile(res, R.string.vcmd_action_stop); aPlay = compile(res, R.string.vcmd_action_play); aPlayFavorites = compile(res, R.string.vcmd_action_play_favorites); + aSubOn = compile(res, R.string.vcmd_action_sub_on); + aSubOff = compile(res, R.string.vcmd_action_sub_off); + aSubChange = compile(res, R.string.vcmd_action_sub_change); + aAudioChange = compile(res, R.string.vcmd_action_audio_change); lFolders = compile(res, R.string.vcmd_location_folders); lFavorites = compile(res, R.string.vcmd_location_favorites); lPlaylists = compile(res, R.string.vcmd_location_playlists); @@ -113,6 +125,33 @@ public boolean handle(String cmd) { return true; } + MediaSessionCallback cb = activity.getMediaSessionCallback(); + MediaEngineManager mgr = cb.getEngineManager(); + MediaEngine eng; + + if (mgr.isVlcPlayerSupported() && ((eng = cb.getEngine()) != null)) { + if (aSubOn.matcher(cmd).matches()) { + if (eng.getCurrentSubtitleStreamInfo() != null) return true; + List sub = eng.getSubtitleStreamInfo(); + if (!sub.isEmpty()) eng.setCurrentSubtitleStream(sub.get(0)); + return true; + } + if (aSubOff.matcher(cmd).matches()) { + eng.setCurrentSubtitleStream(null); + return true; + } + if (aSubChange.matcher(cmd).matches()) { + eng.setCurrentSubtitleStream(next(eng.getSubtitleStreamInfo(), + eng.getCurrentSubtitleStreamInfo())); + return true; + } + if (aAudioChange.matcher(cmd).matches()) { + eng.setCurrentAudioStream(next(eng.getAudioStreamInfo(), + eng.getCurrentAudioStreamInfo())); + return true; + } + } + Matcher m; PatternCompat ff = null; if ((m = cFF.matcher(cmd)).matches()) ff = cFF; @@ -273,4 +312,9 @@ private int toNum(String n) { } return -1; } + + private static T next(List l, T t) { + int idx = l.indexOf(t); + return (idx < 0) ? t : l.get((++idx == l.size()) ? 0 : idx); + } } diff --git a/fermata/src/main/java/me/aap/fermata/ui/fragment/SettingsFragment.java b/fermata/src/main/java/me/aap/fermata/ui/fragment/SettingsFragment.java index 87a23adf..4db6a259 100644 --- a/fermata/src/main/java/me/aap/fermata/ui/fragment/SettingsFragment.java +++ b/fermata/src/main/java/me/aap/fermata/ui/fragment/SettingsFragment.java @@ -439,7 +439,6 @@ private PreferenceViewAdapter createAdapter() { addSubtitlePrefs(sub2, mediaPrefs, isCar); if (!a.isCarActivity()) { - ChangeableCondition vcEnabled = PrefCondition.create(a.getPrefs(), VOICE_CONTROl_ENABLED); sub1 = set.subSet(o -> o.title = R.string.voice_control); sub1.addBooleanPref(o -> { o.title = R.string.enable; @@ -451,28 +450,28 @@ private PreferenceViewAdapter createAdapter() { o.subtitle = R.string.voice_control_sub_long; o.pref = VOICE_CONTROl_FB; o.store = a.getPrefs(); - o.visibility = vcEnabled; + o.visibility = PrefCondition.create(a.getPrefs(), VOICE_CONTROl_ENABLED); }); sub1.addBooleanPref(o -> { o.title = R.string.voice_control_menu; o.subtitle = R.string.voice_control_sub_long; o.pref = VOICE_CONTROl_M; o.store = a.getPrefs(); - o.visibility = vcEnabled; + o.visibility = PrefCondition.create(a.getPrefs(), VOICE_CONTROl_ENABLED); }); sub1.addBooleanPref(o -> { o.title = R.string.voice_control_next; o.subtitle = R.string.voice_control_sub_double; o.pref = NEXT_VOICE_CONTROl; o.store = a.getPlaybackControlPrefs(); - o.visibility = vcEnabled; + o.visibility = PrefCondition.create(a.getPrefs(), VOICE_CONTROl_ENABLED); }); sub1.addBooleanPref(o -> { o.title = R.string.voice_control_prev; o.subtitle = R.string.voice_control_sub_double; o.pref = PREV_VOICE_CONTROl; o.store = a.getPlaybackControlPrefs(); - o.visibility = vcEnabled; + o.visibility = PrefCondition.create(a.getPrefs(), VOICE_CONTROl_ENABLED); }); sub1.addStringPref(o -> { o.title = R.string.voice_control_subst; @@ -481,7 +480,7 @@ private PreferenceViewAdapter createAdapter() { o.pref = VOICE_CONTROL_SUBST; o.store = a.getPrefs(); o.maxLines = 10; - o.visibility = vcEnabled; + o.visibility = PrefCondition.create(a.getPrefs(), VOICE_CONTROl_ENABLED); }); } diff --git a/fermata/src/main/res/values-ru/voice_cmd.xml b/fermata/src/main/res/values-ru/voice_cmd.xml index 32dede66..550b1bc1 100644 --- a/fermata/src/main/res/values-ru/voice_cmd.xml +++ b/fermata/src/main/res/values-ru/voice_cmd.xml @@ -24,6 +24,10 @@ &action_stop; (&action_play;)|старт (&action_play;) (&location_favorites;) + (включить|показать) субтитры? + (выключить|отключить|скрыть) субтитры? + (поменять|сменить|изменить) субтитры? + (поменять|сменить|изменить) аудио[ -]?дорожк[уа] &location_folders; &location_favorites; &location_playlists; diff --git a/fermata/src/main/res/values/voice_cmd.xml b/fermata/src/main/res/values/voice_cmd.xml index 6b8ccc8d..3132f56a 100644 --- a/fermata/src/main/res/values/voice_cmd.xml +++ b/fermata/src/main/res/values/voice_cmd.xml @@ -24,6 +24,10 @@ &action_stop; (&action_play;)|start (&action_play;) (&location_favorites;) + (((turn|switch) on)|show) subtitles? + (((turn|switch) off)|hide) subtitles? + change subtitles? + change audio[ -]?stream &location_folders; &location_favorites; &location_playlists;