📄 sound.java
字号:
/* * RIC 2 by Harry Otten (c) Copyright 2003 hotten@dds.nl * Check out http://www.hotten.dds.nl/ric/This program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.*/import java.io.*; // for IOException and Input/OutputStreamimport sun.audio.*; //import the sun.audio package public abstract class Sound { public static boolean play(String filename) { /* The return type will always be true only when the * file is damaged or that the notfound file is missing it will be false*/ boolean waarde=false; try { /* if the number is unknown play this * bacause the windows platform can not play ?.wav */ if (filename.equals("?.wav")) filename="unknown.wav"; InputStream in = new FileInputStream("../audio/"+filename); // Create an AudioStream object from the input stream. AudioStream as = new AudioStream(in); // Use the static class member "player" from class AudioPlayer to play // clip. AudioPlayer.player.start(as); waarde=true; /* I DON'T KNOW HOW TO CHECK IF THE PLAYER STOP AND THE FILE CAN BE CLOSED */ } catch (FileNotFoundException e) { /* If we can not open the number file... we try to open the notfound file. * So we have to check if we can open that one else we will be stuck in a never ending loo */ System.out.println("Can not open file: "+filename+"\n"); if (!filename.equals("notfound.wav")) waarde=play("notfound.wav"); } catch (IOException e) { System.out.println("Can not playback!!! for file: "+filename); } return waarde; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -