path = mp3Infos.get(current).getUrl();
play(0);
}else {
mediaPlayer.seekTo(0);
current = 0;
Intent sendIntent = new Intent(UPDATE_ACTION);
sendIntent.putExtra(“current”, current);
// 发送广播,将被Activity组件中的BroadcastReceiver接收到
sendBroadcast(sendIntent);
}
} else if(status == 4) { //随机播放
current = getRandomIndex(mp3Infos.size() - 1);
System.out.println(“currentIndex ->” + current);
Intent sendIntent = new Intent(UPDATE_ACTION);
sendIntent.putExtra(“current”, current);
// 发送广播,将被Activity组件中的BroadcastReceiver接收到
sendBroadcast(sendIntent);
path = mp3Infos.get(current).getUrl();
play(0);
}
}
});
myReceiver = new MyReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(PlayerActivity.CTL_ACTION);
registerReceiver(myReceiver, filter);
}
/**
-
获取随机位置
-
@param end
-
@return
*/
protected int getRandomIndex(int end) {
int index = (int) (Math.random() * end);
return index;
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public void onStart(Intent intent, int startId) {
path = intent.getStringExtra(“url”); //歌曲路径
current = intent.getIntExtra(“listPosition”, -1); //当前播放歌曲的在mp3Infos的位置
msg = intent.getIntExtra(“MSG”, 0); //播放信息
if (msg == AppConstant.PlayerMsg.PLAY_MSG) { //直接播放音乐
play(0);
} else if (msg == AppConstant.PlayerMsg.PAUSE_MSG) { //暂停
pause();
} else if (msg == AppConstant.PlayerMsg.STOP_MSG) { //停止
s