zoukankan      html  css  js  c++  java
  • 1600802047 android 第三次作业(音乐播放器)

    一、实现的功能

    播放、暂停、上一首、下一首    显示列表

    二、UI界面截图

    第一首歌

    第二首歌

    第三首歌

    第四首歌

    list列表

    点击播放音乐时图片旋转,点击上一首切换上一首歌,专辑图片和歌曲信息跟着切换到对应的信息,下一首歌也一样。

    三、关键代码

    播放功能和图片旋转

    case R.id.playorpause:
    if(!mediaPlayer.isPlaying() ) {
    mediaPlayer.start();
    if (!animation.isStarted())
    animation.start();
    animation.resume();
    }
    else if (mediaPlayer.isPlaying()) {
    mediaPlayer.pause();
    animation.pause();
    }
    break;

    切换下一首
    case R.id.next:
    if(mediaPlayer != null && index < 4) {
    mediaPlayer.stop();
    try {
    mediaPlayer.reset();
    mediaPlayer.setDataSource(music[index + 1]);
    index++;
    mediaPlayer.prepare();
    mediaPlayer.start();
            
          } catch (Exception e) {
          e.printStackTrace();
          }

    切换上一首

    case R.id.pre:
    if(mediaPlayer != null && index >= 0)
    mediaPlayer.stop();
    try{
    mediaPlayer.reset();
    mediaPlayer.setDataSource(music[index-1]);
    index--;
    mediaPlayer.prepare();
    mediaPlayer.start();
    }catch (Exception e){
    e.printStackTrace();
    }

    列表采用listview。

    四、代码git

    https://git.coding.net/LZ18009788462/musicplayer.git

    https://pan.baidu.com/s/1LVZgPbz2Q-nPLvC7Lher9g

  • 相关阅读:
    KMP算法的理解和代码实现
    关于线程死锁
    PAT1018
    PAT1059
    PAT1009
    PAT1006
    PAT1005
    PAT1004
    PAT1002
    PAT
  • 原文地址:https://www.cnblogs.com/18LZblog/p/10105559.html
Copyright © 2011-2022 走看看