1600802039

实现功能:

1.实现音乐的播放,暂停,上一首,下一首

2.生成播放列表

3..显示播放进度条

实现截图:

 实现录屏:

 

 

关键代码分析:

  显示音乐列表

list = new ArrayList<Map<String, Object>>();    //需要显示在listview里的信息
for (Iterator iterator = musicList.iterator(); iterator.hasNext();) {
Map<String, Object> map = new HashMap<String, Object>();
Musicdb mp3Info = (Musicdb) iterator.next();
map.put("title", mp3Info.getTitle());
map.put("artist", mp3Info.getArtist());
map.put("duration", mp3Info.getTime());
map.put("size", mp3Info.getSize());
map.put("url", mp3Info.getUrl());
map.put("bitmap", R.drawable.musicfile);

list.add(map);
} //加载sdcard中的歌曲信息

SimpleAdapter simpleAdapter = new SimpleAdapter(
this,
list,
R.layout.music_item,
new String[] {"bitmap","title","artist", "size","duration"},
new int[] {R.id.video_imageView,R.id.video_title,R.id.video_singer}
); //将sdcard中的歌曲属性放入
musicView.setAdapter(simpleAdapter); //listview里加载数据

  歌曲的播放、暂停、上一首、下一首

  private void pause() {                    //暂停
        intent.putExtra("MSG","1");
        isplay = false;                     //停止播放 
        bt_pause.setBackgroundResource(R.drawable.play);//图标换为播放
        startService(intent);
    }

private void player(String info){ //播放 intent.putExtra("MSG",info); isplay = true; //开始播放 bt_pause.setBackgroundResource(R.drawable.pause); //图标换为暂停 startService(intent); } private void backMusic() { //上一首 if(curr > 0){ curr -= 1; //如果不是第一首,计数减一,开始播放 player(); } } private void nextMusic() { //下一首 if(curr < musicList.size()-1){ //如果不是最后一首,计数加一,开始播放 curr += 1; player(); } }

 

代码链接:

https://git.dev.tencent.com/gao2039/1600802039.git

apk链接:

https://git.dev.tencent.com/gao2039/apk.git

posted on 2018-12-11 18:58  g21  阅读(139)  评论(0编辑  收藏  举报

导航