解决方案 »

  1.   

    音乐播放的方法调用顺序没有问题,检查音乐文件的路径是否正确,看看播放音乐时候打印的Log (catch的异常是什么?)
      

  2.   

    支持1楼,把log放到catch里面,打印一下e。
      

  3.   

    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();// 把各项参数恢复到初始状态
    不知错在哪里?
      

  4.   

    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();// 把各项参数恢复到初始状态
    不知错在哪里?