JMF里面的MediaPlayer类的方法。mp.setMediaLocation("file:/D:\\cet6\\Cet6200812.mp3");但是却说NullPointerException,明明文件是有的。 为什么会这样?

解决方案 »

  1.   

    是不是文件表示路径的问题,你改成file:/d:/cet6/Cet6200812.mp3试试,要不然你就用seMediaLocator吧
      

  2.   


    改了也不行。去官网上看到说,
    The location of the media URL. It can be an URL or a relative address.  For example: 
    file:///e:/video/media/Sample1.mov 
    http://webServer/media/Sample1.mov 
    media/Sample1.mov 
    但是试了也不行,我晕。我想弄清楚知道为什么? 不过我试试setMediaLocator看
      

  3.   

    一般是protocol:// 然后加文件路径。
    我一般都用MediaLocator
      

  4.   

    setVisible(true);

    //mp.setMediaLocation("file:/D:\\cet6\\Cet6200812.mp3");
    try {
    fileToPlay = new URL(new java.lang.String("file://d:/cet6/Cet6200812.mp3"));
    } catch (MalformedURLException e) {
    System.out.print("地址格式不正确");
    }

    ml = new MediaLocator(fileToPlay);
    mp.setMediaLocator(ml);程序片段,很不幸还是不能打开,晕
      

  5.   

    我现在才发现我错了,
    竟然没有写 mp = new MediaPlayer()
    失败了...
      

  6.   

    "file:/C:\\轨迹.wav"  我试过,可以的