============问题描述============
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; }不知这段代码是否有问题,经过测试,这个方法在歌曲条目被点击的时候是会被调用的,但是却没有播放音乐,求各位指点迷津
============解决方案1============
音乐播放的方法调用顺序没有问题,检查音乐文件的路径是否正确,看看播放音乐时候打印的Log (catch的异常是什么?)============解决方案2============
支持1楼,把log放到catch里面,打印一下e。============解决方案3============
mediaPlayer没实例化吧============解决方案4============
mediaPlayer没实例化~...