Commit 4471bcc9 authored by Thomas Guillem's avatar Thomas Guillem Committed by Geoffrey Métais

Audio passthrough setting

parent d68b95d3
...@@ -597,4 +597,8 @@ ...@@ -597,4 +597,8 @@
<string name="sdcard_permission_dialog_message">VLC cannot delete this file without write access permission.\nPlease go to your SD Card and click on \"Select\".\nYou may have to click on \"Show SD card\" first in the top-right menu</string> <string name="sdcard_permission_dialog_message">VLC cannot delete this file without write access permission.\nPlease go to your SD Card and click on \"Select\".\nYou may have to click on \"Show SD card\" first in the top-right menu</string>
<string name="dialog_sd_wizard">Show me</string> <string name="dialog_sd_wizard">Show me</string>
<string name="renderers_disconnect">Disconnect</string> <string name="renderers_disconnect">Disconnect</string>
<string name="audio_digital_failed">Failed to change Audio Digital Output state</string>
<string name="audio_digital_output_enabled">Audio Digital Output enabled</string>
<string name="audio_digital_output_disabled">Audio Digital Output disabled</string>
<string name="audio_digital_title">Digital audio output (passthrough)</string>
</resources> </resources>
...@@ -4,7 +4,10 @@ ...@@ -4,7 +4,10 @@
android:key="audio_category" android:key="audio_category"
android:title="@string/audio_prefs_category"> android:title="@string/audio_prefs_category">
<CheckBoxPreference
android:defaultValue="false"
android:key="audio_digital_output"
android:title="@string/audio_digital_title" />
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="false" android:defaultValue="false"
android:key="artists_show_all" android:key="artists_show_all"
......
...@@ -61,6 +61,7 @@ import org.videolan.vlc.interfaces.IPlaybackSettingsController; ...@@ -61,6 +61,7 @@ import org.videolan.vlc.interfaces.IPlaybackSettingsController;
import org.videolan.vlc.util.AndroidDevices; import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.Constants; import org.videolan.vlc.util.Constants;
import org.videolan.vlc.util.Strings; import org.videolan.vlc.util.Strings;
import org.videolan.vlc.util.VLCOptions;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
...@@ -92,6 +93,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList ...@@ -92,6 +93,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
private static final int ID_POPUP_VIDEO = 9 ; private static final int ID_POPUP_VIDEO = 9 ;
private static final int ID_REPEAT = 10 ; private static final int ID_REPEAT = 10 ;
private static final int ID_SHUFFLE = 11 ; private static final int ID_SHUFFLE = 11 ;
private static final int ID_PASSTHROUGH = 12 ;
private Activity mActivity; private Activity mActivity;
private int mMode = -1; private int mMode = -1;
...@@ -102,6 +104,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList ...@@ -102,6 +104,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
private TextView mPlaybackSpeed; private TextView mPlaybackSpeed;
private TextView mSleep; private TextView mSleep;
private TextView mPassThrough;
private TextView mJumpTitle; private TextView mJumpTitle;
...@@ -466,14 +469,26 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList ...@@ -466,14 +469,26 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
mService.shuffle(); mService.shuffle();
initShuffle(); initShuffle();
break; break;
case ID_PASSTHROUGH: {
togglePassthrough();
break;
}
} }
} }
private void togglePassthrough() {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(AdvOptionsDialog.this.getContext());
boolean enabled = !VLCOptions.isAudioDigitalOutputEnabled(prefs);
if (mService.setAudioDigitalOutputEnabled(enabled)) {
VLCOptions.setAudioDigitalOutputEnabled(prefs, enabled);
mToast.setText(enabled ? getString(R.string.audio_digital_output_enabled) : getString(R.string.audio_digital_output_disabled));
} else mToast.setText(R.string.audio_digital_failed);
mToast.show();
}
@Override @Override
public void onFocusChange(View v, boolean hasFocus) { public void onFocusChange(View v, boolean hasFocus) {
if (v instanceof TextView) if (v instanceof TextView) ((TextView) v).setTextColor(v.hasFocus() ? UiTools.Resources.ITEM_FOCUS_ON : mTextColor);
((TextView) v).setTextColor(v.hasFocus() ?
UiTools.Resources.ITEM_FOCUS_ON : mTextColor);
mToast.setText(mAdapter.getSelectedAdvOptionHelp()); mToast.setText(mAdapter.getSelectedAdvOptionHelp());
mToast.show(); mToast.show();
} }
...@@ -511,6 +526,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList ...@@ -511,6 +526,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
mService = service; mService = service;
boolean tvUi = VLCApplication.showTvUi(); boolean tvUi = VLCApplication.showTvUi();
int large_items = 0; int large_items = 0;
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(AdvOptionsDialog.this.getContext());
mAdapter.addOption(new Option(ID_SLEEP, R.attr.ic_sleep_normal_style, getString(R.string.sleep_title))); mAdapter.addOption(new Option(ID_SLEEP, R.attr.ic_sleep_normal_style, getString(R.string.sleep_title)));
mAdapter.addOption(new Option(ID_PLAYBACK_SPEED, R.attr.ic_speed_normal_style, getString(R.string.playback_speed))); mAdapter.addOption(new Option(ID_PLAYBACK_SPEED, R.attr.ic_speed_normal_style, getString(R.string.playback_speed)));
...@@ -537,6 +553,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList ...@@ -537,6 +553,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
} else { } else {
mAdapter.addOption(new Option(ID_SAVE_PLAYLIST, R.attr.ic_save, getString(R.string.playlist_save))); mAdapter.addOption(new Option(ID_SAVE_PLAYLIST, R.attr.ic_save, getString(R.string.playlist_save)));
} }
if ("0".equals(prefs.getString("aout", "0"))) mAdapter.addOption(new Option(ID_PASSTHROUGH, R.attr.ic_popup_dim, getString(R.string.audio_digital_title)));
setDialogDimensions(large_items); setDialogDimensions(large_items);
} }
...@@ -619,8 +636,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList ...@@ -619,8 +636,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
public void onBindViewHolder(ViewHolder holder, int position) { public void onBindViewHolder(ViewHolder holder, int position) {
final Option option = mList.get(position); final Option option = mList.get(position);
final TextView tv = (TextView) holder.itemView; final TextView tv = (TextView) holder.itemView;
if (mSelection == position) if (mSelection == position) tv.requestFocus();
tv.requestFocus();
tv.setId(option.id); tv.setId(option.id);
final int icon = UiTools.getResourceFromAttribute(mActivity, option.icon); final int icon = UiTools.getResourceFromAttribute(mActivity, option.icon);
if (option.id == ID_CHAPTER_TITLE) if (option.id == ID_CHAPTER_TITLE)
......
...@@ -25,6 +25,7 @@ package org.videolan.vlc.gui.preferences; ...@@ -25,6 +25,7 @@ package org.videolan.vlc.gui.preferences;
import android.app.Activity; import android.app.Activity;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.preference.CheckBoxPreference;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.preference.TwoStatePreference; import android.support.v7.preference.TwoStatePreference;
...@@ -47,12 +48,6 @@ public class PreferencesAudio extends BasePreferenceFragment implements SharedPr ...@@ -47,12 +48,6 @@ public class PreferencesAudio extends BasePreferenceFragment implements SharedPr
return R.string.audio_prefs_category; return R.string.audio_prefs_category;
} }
@Override
public void onStart() {
super.onStart();
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -62,6 +57,20 @@ public class PreferencesAudio extends BasePreferenceFragment implements SharedPr ...@@ -62,6 +57,20 @@ public class PreferencesAudio extends BasePreferenceFragment implements SharedPr
/* no AudioOutput choice */ /* no AudioOutput choice */
findPreference("aout").setVisible(false); findPreference("aout").setVisible(false);
} }
updatePassThroughSummary();
final boolean opensles = "1".equals(getPreferenceManager().getSharedPreferences().getString("aout", "0"));
if (opensles) findPreference("audio_digital_output").setVisible(false);
}
private void updatePassThroughSummary() {
final boolean pt = getPreferenceManager().getSharedPreferences().getBoolean("audio_digital_output", false);
findPreference("audio_digital_output").setSummary(pt ? R.string.audio_digital_output_enabled : R.string.audio_digital_output_disabled);
}
@Override
public void onStart() {
super.onStart();
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
} }
@Override @Override
...@@ -86,10 +95,16 @@ public class PreferencesAudio extends BasePreferenceFragment implements SharedPr ...@@ -86,10 +95,16 @@ public class PreferencesAudio extends BasePreferenceFragment implements SharedPr
case "aout": case "aout":
VLCInstance.restart(); VLCInstance.restart();
((PreferencesActivity)activity).restartMediaPlayer(); ((PreferencesActivity)activity).restartMediaPlayer();
final boolean opensles = "1".equals(getPreferenceManager().getSharedPreferences().getString("aout", "0"));
if (opensles) ((CheckBoxPreference)findPreference("audio_digital_output")).setChecked(false);
findPreference("audio_digital_output").setVisible(!opensles);
break; break;
case Constants.KEY_ARTISTS_SHOW_ALL: case Constants.KEY_ARTISTS_SHOW_ALL:
((PreferencesActivity)activity).updateArtists(); ((PreferencesActivity)activity).updateArtists();
break; break;
case "audio_digital_output":
updatePassThroughSummary();
break;
} }
} }
} }
\ No newline at end of file
...@@ -21,10 +21,12 @@ ...@@ -21,10 +21,12 @@
*/ */
package org.videolan.vlc.gui.tv.preferences; package org.videolan.vlc.gui.tv.preferences;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.preference.CheckBoxPreference;
import org.videolan.libvlc.util.AndroidUtil; import org.videolan.libvlc.util.AndroidUtil;
import org.videolan.libvlc.util.HWDecoderUtil; import org.videolan.libvlc.util.HWDecoderUtil;
...@@ -61,6 +63,14 @@ public class PreferencesAudio extends BasePreferenceFragment implements SharedPr ...@@ -61,6 +63,14 @@ public class PreferencesAudio extends BasePreferenceFragment implements SharedPr
/* no AudioOutput choice */ /* no AudioOutput choice */
findPreference("aout").setVisible(false); findPreference("aout").setVisible(false);
} }
updatePassThroughSummary();
final boolean opensles = "1".equals(getPreferenceManager().getSharedPreferences().getString("aout", "0"));
if (opensles) findPreference("audio_digital_output").setVisible(false);
}
private void updatePassThroughSummary() {
final boolean pt = getPreferenceManager().getSharedPreferences().getBoolean("audio_digital_output", false);
findPreference("audio_digital_output").setSummary(pt ? R.string.audio_digital_output_enabled : R.string.audio_digital_output_disabled);
} }
@Override @Override
...@@ -75,8 +85,10 @@ public class PreferencesAudio extends BasePreferenceFragment implements SharedPr ...@@ -75,8 +85,10 @@ public class PreferencesAudio extends BasePreferenceFragment implements SharedPr
switch (key){ switch (key){
case "aout": case "aout":
VLCInstance.restart(); VLCInstance.restart();
if (getActivity() != null ) if (getActivity() != null ) ((PreferencesActivity)getActivity()).restartMediaPlayer();
((PreferencesActivity)getActivity()).restartMediaPlayer(); final boolean opensles = "1".equals(getPreferenceManager().getSharedPreferences().getString("aout", "0"));
if (opensles) ((CheckBoxPreference)findPreference("audio_digital_output")).setChecked(false);
findPreference("audio_digital_output").setVisible(!opensles);
} }
} }
} }
\ No newline at end of file
...@@ -187,6 +187,7 @@ class PlayerController : IVLCVout.Callback, MediaPlayer.EventListener { ...@@ -187,6 +187,7 @@ class PlayerController : IVLCVout.Callback, MediaPlayer.EventListener {
private fun newMediaPlayer() : MediaPlayer { private fun newMediaPlayer() : MediaPlayer {
return MediaPlayer(VLCInstance.get()).apply { return MediaPlayer(VLCInstance.get()).apply {
setAudioDigitalOutputEnabled(VLCOptions.isAudioDigitalOutputEnabled(VLCApplication.getSettings()));
VLCOptions.getAout(VLCApplication.getSettings())?.let { setAudioOutput(it) } VLCOptions.getAout(VLCApplication.getSettings())?.let { setAudioOutput(it) }
setRenderer(RendererDelegate.selectedRenderer) setRenderer(RendererDelegate.selectedRenderer)
this.vlcVout.addCallback(this@PlayerController) this.vlcVout.addCallback(this@PlayerController)
......
...@@ -147,6 +147,16 @@ public class VLCOptions { ...@@ -147,6 +147,16 @@ public class VLCOptions {
return options; return options;
} }
public static boolean isAudioDigitalOutputEnabled(SharedPreferences pref) {
return pref.getBoolean("audio_digital_output", false);
}
public static void setAudioDigitalOutputEnabled(SharedPreferences pref, boolean enabled) {
SharedPreferences.Editor editor = pref.edit();
editor.putBoolean("audio_digital_output",enabled);
editor.apply();
}
public static String getAout(SharedPreferences pref) { public static String getAout(SharedPreferences pref) {
int aout = -1; int aout = -1;
try { try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment