WEB开发网
开发学院手机开发Android 开发 Android 带ListView的音乐播放器 阅读

Android 带ListView的音乐播放器

 2010-09-06 08:19:00 来源:WEB开发网   
核心提示://2. 初始化mp = new MediaPlayer();//3. 暂停mp.pause();//4. 继续mp.start();//5. 判断是否正在播放mp.isPlaying()//6.使用目标Urimp.release();mp = MediaPlayer.create(this, uri);//1. 定义

//2. 初始化

mp = new MediaPlayer();

//3. 暂停

mp.pause();

//4. 继续

mp.start();

//5. 判断是否正在播放

mp.isPlaying()

//6.使用目标Uri

mp.release();

mp = MediaPlayer.create(this, uri);

//1. 定义

MediaPlayer mp;

//2. 初始化

mp = new MediaPlayer();

//3. 暂停

mp.pause();

//4. 继续

mp.start();

//5. 判断是否正在播放

mp.isPlaying()

//6.使用目标Uri

mp.release();

mp = MediaPlayer.create(this, uri);

5. 单击ListView中某个Item 会播放目标音乐资源

Java代码

public void playMusic(long arg3) throws IllegalArgumentException, IllegalStateException, IOException{

Uri uri = Uri.withAppendedPath(

MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,

String.valueOf(arg3));

TextView tv = (TextView) findViewById(R.id.name);

tv.setText(uri.toString());

mp.release();

mp = MediaPlayer.create(this, uri);

mp.start();

}

list.setOnItemClickListener(new OnItemClickListener(){

@Override

public void onItemClick(AdapterView arg0, View arg1, int arg2,

long arg3) {

// TODO Auto-generated method stub

try {

playMusic(arg3);

} catch (IllegalArgumentException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IllegalStateException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

});

public void playMusic(long arg3) throws IllegalArgumentException,

上一页  1 2 3 4  下一页

Tags:Android ListView 音乐

编辑录入:coldstar [复制链接] [打 印]
赞助商链接