Get external output detection working a little better
This commit is contained in:
parent
8854996bcb
commit
c7e01fc0fe
@ -42,6 +42,7 @@ import android.content.IntentFilter;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.media.MediaPlayer;
|
import android.media.MediaPlayer;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
@ -304,8 +305,6 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
|
|||||||
private int mPendingSeek;
|
private int mPendingSeek;
|
||||||
|
|
||||||
private Method mIsWiredHeadsetOn;
|
private Method mIsWiredHeadsetOn;
|
||||||
private Method mIsBluetoothScoOn;
|
|
||||||
private Method mIsBluetoothA2dpOn;
|
|
||||||
private Method mStartForeground;
|
private Method mStartForeground;
|
||||||
private Method mStopForeground;
|
private Method mStopForeground;
|
||||||
|
|
||||||
@ -384,15 +383,8 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
|
|||||||
mMediaPlayer.setOnErrorListener(this);
|
mMediaPlayer.setOnErrorListener(this);
|
||||||
|
|
||||||
mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
|
mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
|
||||||
try {
|
|
||||||
mIsWiredHeadsetOn = mAudioManager.getClass().getMethod("isWiredHeadsetOn", (Class[]) null);
|
|
||||||
mIsBluetoothScoOn = mAudioManager.getClass().getMethod("isBluetoothScoOn", (Class[]) null);
|
|
||||||
mIsBluetoothA2dpOn = mAudioManager.getClass().getMethod("isBluetoothA2dpOn", (Class[]) null);
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
Log.d("VanillaMusic", "falling back to pre-2.0 AudioManager APIs");
|
|
||||||
}
|
|
||||||
|
|
||||||
mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
|
mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mStartForeground = getClass().getMethod("startForeground", int.class, Notification.class);
|
mStartForeground = getClass().getMethod("startForeground", int.class, Notification.class);
|
||||||
mStopForeground = getClass().getMethod("stopForeground", boolean.class);
|
mStopForeground = getClass().getMethod("stopForeground", boolean.class);
|
||||||
@ -400,6 +392,14 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
|
|||||||
Log.d("VanillaMusic", "falling back to pre-2.0 Service APIs");
|
Log.d("VanillaMusic", "falling back to pre-2.0 Service APIs");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!"3".equals(Build.VERSION.SDK)) {
|
||||||
|
try {
|
||||||
|
mIsWiredHeadsetOn = mAudioManager.getClass().getMethod("isWiredHeadsetOn", (Class[])null);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
Log.d("VanillaMusic", "falling back to pre-1.6 AudioManager APIs");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mSettings = PreferenceManager.getDefaultSharedPreferences(this);
|
mSettings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
mSettings.registerOnSharedPreferenceChangeListener(this);
|
mSettings.registerOnSharedPreferenceChangeListener(this);
|
||||||
mHeadsetPause = mSettings.getBoolean("headset_pause", true);
|
mHeadsetPause = mSettings.getBoolean("headset_pause", true);
|
||||||
@ -521,14 +521,17 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
|
|||||||
|
|
||||||
private boolean isSpeakerOn()
|
private boolean isSpeakerOn()
|
||||||
{
|
{
|
||||||
try {
|
if (mAudioManager.isBluetoothA2dpOn() || mAudioManager.isBluetoothScoOn())
|
||||||
return !(Boolean)mIsWiredHeadsetOn.invoke(mAudioManager, (Object[])null)
|
return false;
|
||||||
&& !(Boolean)mIsBluetoothScoOn.invoke(mAudioManager, (Object[])null)
|
|
||||||
&& !(Boolean)mIsBluetoothA2dpOn.invoke(mAudioManager, (Object[])null);
|
if (mIsWiredHeadsetOn != null) {
|
||||||
} catch (InvocationTargetException e) {
|
try {
|
||||||
Log.w("VanillaMusic", e);
|
return !(Boolean)mIsWiredHeadsetOn.invoke(mAudioManager, (Object[])null);
|
||||||
} catch (IllegalAccessException e) {
|
} catch (InvocationTargetException e) {
|
||||||
Log.w("VanillaMusic", e);
|
Log.w("VanillaMusic", e);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
Log.w("VanillaMusic", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Why is there no true equivalent to this in Android 2.0?
|
// Why is there no true equivalent to this in Android 2.0?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user