博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
play music
阅读量:6446 次
发布时间:2019-06-23

本文共 722 字,大约阅读时间需要 2 分钟。

android 播放音乐 

private MediaPlayer mMediaPlayer;  //定义

 

public void playTone() {

//mMediaPlayer.create(getApplicationContext(), uri)

mMediaPlayer.stop();
mMediaPlayer.reset();
mMediaPlayer.release();
mMediaPlayer = null;
Uri playUri = Uri.parse("/sdcard/music/"+list.get(focusedIndex).cType+".mp3");
try {
mMediaPlayer = MediaPlayer.create(CheckItemsActivity.this, playUri);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mMediaPlayer.start();

}

转载于:https://www.cnblogs.com/andylha/p/3745727.html

你可能感兴趣的文章