Commit b5f020a5 authored by Sébastien Toque's avatar Sébastien Toque

make headset detection optional

parent 6ae74913
......@@ -57,4 +57,6 @@
<string name="enable_iomx">Activer le décodage matériel</string>
<string name="advanced_debugging">Débogage avancé</string>
<string name="quit">Quitter l\'application</string>
<string name="detect_headset">Détecter le casque</string>
<string name="detect_headset_detail">Pause lors du débranchement du casque, Reprise lors du branchement du casque</string>
</resources>
......@@ -59,4 +59,6 @@
<string name="enable_iomx">Enable hardware accelerated decoding</string>
<string name="advanced_debugging">Advanced Debugging</string>
<string name="quit">Quit Application</string>
<string name="detect_headset">Detect headset</string>
<string name="detect_headset_detail">Pause on headset removed, Resume on headset inserted</string>
</resources>
......@@ -24,6 +24,11 @@
android:key="enable_iomx"
android:title="@string/enable_iomx">
</CheckBoxPreference>
<CheckBoxPreference
android:key="enable_headset_detection"
android:title="@string/detect_headset"
android:summary="@string/detect_headset_detail">
</CheckBoxPreference>
<PreferenceScreen android:title="@string/advanced_debugging">
<Preference android:title="@string/quit" android:key="quit_app" android:enabled="true"/>
</PreferenceScreen>
......
......@@ -62,6 +62,8 @@ public interface AudioPlayer {
void setRepeatType(RepeatType t);
RepeatType getRepeatType();
void detectHeadset(boolean enable);
}
}
......@@ -61,6 +61,7 @@ public class AudioService extends Service {
private Notification mNotification;
private boolean mShuffling = false;
private RepeatType mRepeating = RepeatType.None;
private boolean mDetectHeadset = false;
@Override
public void onStart(Intent intent, int startId) {
......@@ -106,15 +107,17 @@ public class AudioService extends Service {
String action = intent.getAction();
int state = intent.getIntExtra("state", 0);
if (action.equalsIgnoreCase(AudioManager.ACTION_AUDIO_BECOMING_NOISY)) {
Log.i(TAG, "Headset Removed.");
if (mLibVLC.isPlaying() && mCurrentMedia != null)
pause();
}
else if (action.equalsIgnoreCase(Intent.ACTION_HEADSET_PLUG) && state != 0) {
Log.i(TAG, "Headset Inserted.");
if (!mLibVLC.isPlaying() && mCurrentMedia != null)
play();
if (mDetectHeadset) {
if (action.equalsIgnoreCase(AudioManager.ACTION_AUDIO_BECOMING_NOISY)) {
Log.i(TAG, "Headset Removed.");
if (mLibVLC.isPlaying() && mCurrentMedia != null)
pause();
}
else if (action.equalsIgnoreCase(Intent.ACTION_HEADSET_PLUG) && state != 0) {
Log.i(TAG, "Headset Inserted.");
if (!mLibVLC.isPlaying() && mCurrentMedia != null)
play();
}
}
}
};
......@@ -466,6 +469,11 @@ public class AudioService extends Service {
else
return false;
}
@Override
public void detectHeadset(boolean enable) throws RemoteException {
mDetectHeadset = enable;
}
};
}
......@@ -378,4 +378,13 @@ public class AudioServiceController implements AudioPlayerControl {
return RepeatType.None;
}
}
@Override
public void detectHeadset(boolean enable) {
try {
mAudioServiceBinder.detectHeadset(enable);
} catch (RemoteException e) {
Log.e(TAG, "remote procedure call failed: detectHeadset()");
}
}
}
......@@ -46,4 +46,5 @@ interface IAudioService {
Bitmap getCover();
void addAudioCallback(IAudioServiceCallback cb);
void removeAudioCallback(IAudioServiceCallback cb);
void detectHeadset(boolean enable);
}
......@@ -24,6 +24,7 @@ import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.Preference.OnPreferenceClickListener;
......@@ -72,7 +73,18 @@ public class PreferencesActivity extends PreferenceActivity {
return true;
}
});
// Headset detection option
CheckBoxPreference checkboxHS = (CheckBoxPreference) findPreference("enable_headset_detection");
checkboxHS.setOnPreferenceClickListener(
new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
CheckBoxPreference checkboxHS = (CheckBoxPreference) preference;
AudioServiceController.getInstance().detectHeadset(checkboxHS.isChecked());
return true;
}
});
// Attach debugging items
Preference quitAppPref = (Preference) findPreference("quit_app");
quitAppPref.setOnPreferenceClickListener(
......
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