2016-11-21 66 views
0

这是我目前正在尝试:如何在Java中使用.aiff文件?

final AudioClip note0 = new AudioClip(getClass().getResource("/Downloads/notes/A3.aiff").toString()); 
    key0.setOnMouseClicked(new EventHandler<MouseEvent>() 
    { 
     @Override 
     public void handle(MouseEvent me) 
     { 
      note0.play(); 
     } 
    }); 

我想打一个键(矩形对象)的说明(.AIFF音频文件)。但是,我不知道如何引用.getResource()中的文件路径。任何人都可以向我提供如何继续的建议吗?谢谢!

回答

0

getRessource适用于资源,这些资源是属于程序一部分的文件。对于外部文件,你可能需要一个文件网址:

final AudioClip note0 = new AudioClip("file:///Downloads/notes/A3.aiff"); 

到你的主目录的路径可能会在路径中丢失。

或者,复制A3.aiff的资源(或源)代码的根目录,然后访问它作为一种资源:

final AudioClip note0 = new AudioClip(getClass().getResource("/A3.aiff").toString());