Commit 9c39be1e9382ae2e49706524abeddd2e77256b96

  • avatar
  • Kevin James Purdy <pountaar @mo…a.sandbenders.org>
  • Wed Sep 09 10:12:10 CEST 2009
Mute on call now works.
  
55 android:versionName="0.9.0" >
66 <uses-sdk android:minSdkVersion="1" />
77 <uses-permission android:name="android.permission.INTERNET" />
8 <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
98 <application android:label="@string/app_name"
109 android:name="amdroid"
1110 android:icon="@drawable/amdroid_logo">
  
4747 public static Boolean playListVisible;
4848 public static Boolean confChanged;
4949 protected static Bundle cache;
50 private static Boolean mResumeAfterCall;
50 private static Boolean mResumeAfterCall = false;
5151
5252 //Handle phone calls
5353 private PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
8888 cache = new Bundle();
8989
9090 //Make sure we check for phone calls
91 //TelephonyManager tmgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
92 //tmgr.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
91 TelephonyManager tmgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
92 tmgr.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
9393
9494 try {
9595 comm = new ampacheCommunicator(prefs, this);
100100
101101 }
102102 playlistCurrent = new ArrayList();
103 }
104
105 public void onDestroy() {
106 TelephonyManager tmgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
107 tmgr.listen(mPhoneStateListener, 0);
103108 }
104109}
  
77import android.os.Handler;
88import android.os.IBinder;
99import android.os.Message;
10import android.media.MediaPlayer;
11import android.telephony.PhoneStateListener;
12import android.telephony.TelephonyManager;
13import android.media.AudioManager;
14import android.content.Context;
15import java.util.ArrayList;
1016
17import com.sound.ampache.objects.*;
18
1119public class playerService extends Service {
1220 private IBinder mBinder;
13 private boolean mServiceInUse = false;
21 private static boolean mServiceInUse = false;
22 private ArrayList<Song> playlistCurrent;
23 private MediaPlayer mp;
24 private static Boolean mResumeAfterCall;
1425
26 //Handle phone calls
27 private PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
28 @Override
29 public void onCallStateChanged(int state, String incomingNumber) {
30 if (state == TelephonyManager.CALL_STATE_RINGING) {
31 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
32 int ringvolume = audioManager.getStreamVolume(AudioManager.STREAM_RING);
33 if (ringvolume > 0) {
34 mResumeAfterCall = (mp.isPlaying() || mResumeAfterCall);
35 mp.pause();
36 }
37 } else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
38 // pause the music while a conversation is in progress
39 mResumeAfterCall = (mp.isPlaying() || mResumeAfterCall);
40 mp.pause();
41 } else if (state == TelephonyManager.CALL_STATE_IDLE) {
42 // start playing again
43 if (mResumeAfterCall) {
44 // resume playback only if music was playing
45 // when the call was answered
46 mp.start();
47 mResumeAfterCall = false;
48 }
49 }
50 }
51 };
52
53
1554 @Override
1655 public IBinder onBind(Intent intent) {
1756 //mDelayedStopHandler.removeCallbacksAndMessages(null);
6464 mServiceInUse = true;
6565 }
6666
67 @Override
68 public void onCreate() {
69 mp = new MediaPlayer();
70
71 }
6772}