android闹钟程序实现铃声

代码:

private MediaPlayer mediaPlayer; mediaPlayer =MediaPlayer.create(context,R.drawable.XXX); Runnable rmp = new Runnable() { public void run() { mediaPlayer01.start(); } }; //然后 : final Thread tmp = new Thread(rmp); //再在适当的地方: tmp.start();  

 

简单一点并让音乐循环播放:

mediaPlayer = MediaPlayer.create(this, R.raw.m); mediaPlayer.setLooping(true);

 

如果要获得播放音乐时间:

1.player.getCurrentPosition()
2. public static String timeToString(long duration)
  {
    if (duration < 0)
      return "00:00";
    StringBuffer sb = new StringBuffer();
    long m = duration / (60 * 1000);
    sb.append(m < 10 ? "0" + m : m);
    sb.append(":");
    long s = (duration % (60 * 1000)) / 1000;
    sb.append(s < 10 ? "0" + s : s);
    return sb.toString();
  }
3.timeToString方法返回的就是播放时间

 

你可能感兴趣的:(thread,android,String,音乐)