80,350
社区成员
发帖
与我相关
我的任务
分享
public boolean playmusic(int listPosition) {
//playBtn.setBackgroundResource(R.drawable.play_selector);
Mp3Info mp3Info = mp3Infos.get(listPosition);
//musicTitle.setText(mp3Info.getTitle());
/*Intent intent = new Intent(this.getActivity(),PlayerService.class);
intent.setAction("com.wyj.media.MUSIC_SERVICE");
intent.putExtra("listPosition",listPosition);
intent.putExtra("url", mp3Info.getUrl());
intent.putExtra("MSG", AppConstant.PlayerMsg.PLAY_MSG);
this.getActivity().startService(intent);*/
path=mp3Info.getUrl();
try {
//initLrc();
mediaPlayer.reset();// 把各项参数恢复到初始状态
mediaPlayer.setDataSource(path);
mediaPlayer.prepare(); // 进行缓冲
mediaPlayer.start(); // 开始播放
} catch (Exception e) {
e.printStackTrace();
}
Log.d(TAG,"method playmusic()has been called!");
Log.d(TAG,"the path of this song is that:"+path);
return true;
}
public boolean playmusic(int listPosition) {
//playBtn.setBackgroundResource(R.drawable.play_selector);
Mp3Info mp3Info = mp3Infos.get(listPosition);
//musicTitle.setText(mp3Info.getTitle());
/*Intent intent = new Intent(this.getActivity(),PlayerService.class);
intent.setAction("com.wyj.media.MUSIC_SERVICE");
intent.putExtra("listPosition",listPosition);
intent.putExtra("url", mp3Info.getUrl());
intent.putExtra("MSG", AppConstant.PlayerMsg.PLAY_MSG);
this.getActivity().startService(intent);*/
path=mp3Info.getUrl();
//initLrc();
mediaPlayer.reset();// 把各项参数恢复到初始状态
try {
mediaPlayer.setDataSource(path);
} 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();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mediaPlayer.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // 进行缓冲
mediaPlayer.start(); // 开始播放
Log.d(TAG,"method playmusic()has been called!");
Log.d(TAG,"the path of this song is that:"+path);
return true;
}
我改成这样,结果运行后Logcat显示这样
定位到Testfragement.java第100行是这样的mediaPlayer.reset();// 把各项参数恢复到初始状态
不知错在哪里?public boolean playmusic(int listPosition) {
//playBtn.setBackgroundResource(R.drawable.play_selector);
Mp3Info mp3Info = mp3Infos.get(listPosition);
//musicTitle.setText(mp3Info.getTitle());
/*Intent intent = new Intent(this.getActivity(),PlayerService.class);
intent.setAction("com.wyj.media.MUSIC_SERVICE");
intent.putExtra("listPosition",listPosition);
intent.putExtra("url", mp3Info.getUrl());
intent.putExtra("MSG", AppConstant.PlayerMsg.PLAY_MSG);
this.getActivity().startService(intent);*/
path=mp3Info.getUrl();
//initLrc();
mediaPlayer.reset();// 把各项参数恢复到初始状态
try {
mediaPlayer.setDataSource(path);
} 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();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mediaPlayer.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // 进行缓冲
mediaPlayer.start(); // 开始播放
Log.d(TAG,"method playmusic()has been called!");
Log.d(TAG,"the path of this song is that:"+path);
return true;
}
mediaPlayer.reset();// 把各项参数恢复到初始状态