Commit 9c39be1e9382ae2e49706524abeddd2e77256b96
- Diff rendering mode:
- inline
- side by side
AndroidManifest.xml
(0 / 1)
|   | |||
| 5 | 5 | android:versionName="0.9.0" > | |
| 6 | 6 | <uses-sdk android:minSdkVersion="1" /> | |
| 7 | 7 | <uses-permission android:name="android.permission.INTERNET" /> | |
| 8 | <uses-permission android:name="android.permission.READ_PHONE_STATE"/> | ||
| 9 | 8 | <application android:label="@string/app_name" | |
| 10 | 9 | android:name="amdroid" | |
| 11 | 10 | android:icon="@drawable/amdroid_logo"> |
|   | |||
| 47 | 47 | public static Boolean playListVisible; | |
| 48 | 48 | public static Boolean confChanged; | |
| 49 | 49 | protected static Bundle cache; | |
| 50 | private static Boolean mResumeAfterCall; | ||
| 50 | private static Boolean mResumeAfterCall = false; | ||
| 51 | 51 | ||
| 52 | 52 | //Handle phone calls | |
| 53 | 53 | private PhoneStateListener mPhoneStateListener = new PhoneStateListener() { | |
| … | … | ||
| 88 | 88 | cache = new Bundle(); | |
| 89 | 89 | ||
| 90 | 90 | //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); | ||
| 93 | 93 | ||
| 94 | 94 | try { | |
| 95 | 95 | comm = new ampacheCommunicator(prefs, this); | |
| … | … | ||
| 100 | 100 | ||
| 101 | 101 | } | |
| 102 | 102 | playlistCurrent = new ArrayList(); | |
| 103 | } | ||
| 104 | |||
| 105 | public void onDestroy() { | ||
| 106 | TelephonyManager tmgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); | ||
| 107 | tmgr.listen(mPhoneStateListener, 0); | ||
| 103 | 108 | } | |
| 104 | 109 | } |
|   | |||
| 7 | 7 | import android.os.Handler; | |
| 8 | 8 | import android.os.IBinder; | |
| 9 | 9 | import android.os.Message; | |
| 10 | import android.media.MediaPlayer; | ||
| 11 | import android.telephony.PhoneStateListener; | ||
| 12 | import android.telephony.TelephonyManager; | ||
| 13 | import android.media.AudioManager; | ||
| 14 | import android.content.Context; | ||
| 15 | import java.util.ArrayList; | ||
| 10 | 16 | ||
| 17 | import com.sound.ampache.objects.*; | ||
| 18 | |||
| 11 | 19 | public class playerService extends Service { | |
| 12 | 20 | 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; | ||
| 14 | 25 | ||
| 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 | |||
| 15 | 54 | @Override | |
| 16 | 55 | public IBinder onBind(Intent intent) { | |
| 17 | 56 | //mDelayedStopHandler.removeCallbacksAndMessages(null); | |
| … | … | ||
| 64 | 64 | mServiceInUse = true; | |
| 65 | 65 | } | |
| 66 | 66 | ||
| 67 | @Override | ||
| 68 | public void onCreate() { | ||
| 69 | mp = new MediaPlayer(); | ||
| 70 | |||
| 71 | } | ||
| 67 | 72 | } |

