android4.0 bug批改系列五
发布时间: 2012-08-03 00:12:14 作者: rapoo
android4.0 bug修改系列五
1、修改当SD拔出的时候,音乐播放器停止播放的问题
src/com/android/music/MediaPlaybackActivity.java
private ServiceConnection osc = new ServiceConnection() {1061 public void onServiceConnected(ComponentName classname, IBinder obj) {1062 mService = IMediaPlaybackService.Stub.asInterface(obj);1063 startPlayback();1064 try {1065 // Assume something is playing when the service says it is,1066 // but also if the audio ID is valid but the service is paused.1067 if (mService.getAudioId() >= 0 || mService.isPlaying() ||1068 mService.getPath() != null) {1069 1070 /* add by chenjd, chenjd@allwinnertech.com1071 * save currently playing music 1072 */1073 Uri uri = Uri.parse(mService.getPath());1074 Cursor c = managedQuery(uri, null, null, null, null);1075 String st = null;1076 if(c != null)1077 {1078 while(c.moveToNext())1079 {1080 st = c.getString(1);1081 break;1082 }1083 c.close();1084 }1085 if(st != null)1086 {1087 SharedPreferences pf = getSharedPreferences("current", 0);1088 SharedPreferences.Editor editor = pf.edit();1089 editor.putString("PlayedMusic", st);1090 editor.commit();1091 }1092 1093 // something is playing now, we're done1094 mRepeatButton.setVisibility(View.VISIBLE);1095 mShuffleButton.setVisibility(View.VISIBLE);1096 mQueueButton.setVisibility(View.VISIBLE);1097 setRepeatButtonImage();1098 setShuffleButtonImage();1099 setPauseButtonImage();1100 return;1101 }1102 } catch (RemoteException ex) {1103 }1104 // Service is dead or not playing anything. If we got here as part1105 // of a "play this file" Intent, exit. Otherwise go to the Music1106 // app start screen.1107 if (getIntent().getData() == null) {1108 Intent intent = new Intent(Intent.ACTION_MAIN);1109 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);1110 intent.setClass(MediaPlaybackActivity.this, MusicBrowserActivity.class);1111 startActivity(intent);1112 }1113 finish();1114 }1115 public void onServiceDisconnected(ComponentName classname) {1116 mService = null;1117 }1118 };1119
在src/com/android/music/MediaPlaybackService.java
public void closeExternalStorageFiles(String storagePath) { // stop playback and clean up if the SD card is going to be unmounted.+ /* add by chenjd,chenjd@allwinnertech.com,20120113+ * don't let the playing stop + */+ SharedPreferences spf = getSharedPreferences("current", 0);+ String music = spf.getString("PlayedMusic", "null");+ if(!music.contains(storagePath))+ {+ return;+ } stop(true); notifyChange(QUEUE_CHANGED); notifyChange(META_CHANGED); };
public void registerExternalStorageListener() {738 if (mUnmountReceiver == null) {739 mUnmountReceiver = new BroadcastReceiver() {740 @Override741 public void onReceive(Context context, Intent intent) {742 String action = intent.getAction();743 if (action.equals(Intent.ACTION_MEDIA_EJECT)) {744 saveQueue(true);745 mQueueIsSaveable = false;746 closeExternalStorageFiles(intent.getData().getPath());747 } else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) {748 mMediaMountedCount++;749 mCardId = MusicUtils.getCardId(MediaPlaybackService.this);750 reloadQueue();751 mQueueIsSaveable = true;752 notifyChange(QUEUE_CHANGED);753 //notifyChange(META_CHANGED);754 }755 }756 };757 IntentFilter iFilter = new IntentFilter();758 iFilter.addAction(Intent.ACTION_MEDIA_EJECT);759 iFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);760 iFilter.addDataScheme("file");761 registerReceiver(mUnmountReceiver, iFilter);762 }763 }