Android应用开发--MP3音乐播放器Service实现(2)

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值