主要功能介绍
实现音乐暂停,播放,下一首,上一首;
程序运行截图
核心代码解析
功能键的实现
public void onClick(View v) {
switch(v.getId()){
case R.id.song1:
if(!mediaPlayer.isPlaying()){
initMediaPlayer(1);
mediaPlayer.start();
}
case R.id.song2:
if(!mediaPlayer.isPlaying()){
initMediaPlayer(1);
mediaPlayer.start();
}
case R.id.song3:
if(!mediaPlayer.isPlaying()){
initMediaPlayer(2);
mediaPlayer.start();
}
case R.id.start:
if(!mediaPlayer.isPlaying()){
mediaPlayer.start();//开始
}
break;
case R.id.pause:
if(mediaPlayer.isPlaying()){
mediaPlayer.pause();//暂停
}
break;
case R.id.last:
if(mediaPlayer.isPlaying()){
n--;
initMediaPlayer(n);
mediaPlayer.start();//上一曲
}
break;
case R.id.next:
if(mediaPlayer.isPlaying()){
n++;
initMediaPlayer(n);
mediaPlayer.start();//下一曲
}
break;
default:
break;
}
}
项目地址
https://qcloud.coding.net/u/love999love/p/AndroidMusic/git
APP下载链接
https://dev.tencent.com/u/love999love/p/AndroidMusic/git/tree/master/MyApplication1/app/release