本文整理了Java中java.applet.Applet.newAudioClip()
方法的一些代码示例,展示了Applet.newAudioClip()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Applet.newAudioClip()
方法的具体详情如下:
包路径:java.applet.Applet
类名称:Applet
方法名:newAudioClip
暂无
代码示例来源:origin: kevin-wayne/algs4
private static void playApplet(String filename) {
URL url = null;
try {
File file = new File(filename);
if (file.canRead()) url = file.toURI().toURL();
}
catch (MalformedURLException e) {
throw new IllegalArgumentException("could not play '" + filename + "'", e);
}
// URL url = StdAudio.class.getResource(filename);
if (url == null) {
throw new IllegalArgumentException("could not play '" + filename + "'");
}
AudioClip clip = Applet.newAudioClip(url);
clip.play();
}
代码示例来源:origin: stackoverflow.com
import java.applet.Applet;
import java.applet.AudioClip;
final AudioClip clip = Applet.newAudioClip(resourceUrl);
代码示例来源:origin: ThomasFooteDQ/DroidQuest
public SoundClip(String f) {
filename = f;
try {
URL baseURL = new URL("file:" + System.getProperty("user.dir") + "/sounds/");
URL soundURL;
soundURL = new URL(baseURL, filename);
audioClip = Applet.newAudioClip(soundURL);
}
catch (MalformedURLException e) {
System.err.println(e.getMessage());
}
}
}
代码示例来源:origin: stackoverflow.com
import java.applet.*;
import java.net.*;
public class MainClass {
public static void main(String[] args) {
try {
AudioClip clip = Applet.newAudioClip(
new URL("file:C:/sound.wav"));
clip.play();
} catch (MalformedURLException murle) {
murle.printStackTrace();
}}}
代码示例来源:origin: com.googlecode.princeton-java-introduction/stdlib
/**
* Play a sound file (in .wav, .mid, or .au format) in a background thread.
*/
public static void play(String filename) {
URL url = null;
try {
File file = new File(filename);
if (file.canRead()) url = file.toURI().toURL();
}
catch (MalformedURLException e) { e.printStackTrace(); }
// URL url = StdAudio.class.getResource(filename);
if (url == null) throw new RuntimeException("audio " + filename + " not found");
AudioClip clip = Applet.newAudioClip(url);
clip.play();
}
代码示例来源:origin: BiglySoftware/BiglyBT
@Override
public void run() {
try {
AudioClip audio_clip = null;
if ( sound_file.length() == 0 ){
audio_clip = Applet.newAudioClip(BuddyPluginView.class.getClassLoader().getResource( default_sound ));
}else{
URL file_url = new File( sound_file ).toURI().toURL();
audio_clip = Applet.newAudioClip( file_url );
}
audio_clip.play();
Thread.sleep(2500);
} catch (Throwable e) {
}
}
}.start();
代码示例来源:origin: edu.princeton.cs/algs4
private static void playApplet(String filename) {
URL url = null;
try {
File file = new File(filename);
if(file.canRead()) url = file.toURI().toURL();
}
catch (MalformedURLException e) {
throw new IllegalArgumentException("could not play '" + filename + "'", e);
}
// URL url = StdAudio.class.getResource(filename);
if (url == null) {
throw new IllegalArgumentException("could not play '" + filename + "'");
}
AudioClip clip = Applet.newAudioClip(url);
clip.play();
}
代码示例来源:origin: stackoverflow.com
Button logout = new JButton( "Logout" );
logout.addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent evt )
{
// play a sound before loging out
try
{
java.applet.AudioClip clip =
java.applet.Applet.newAudioClip(new java.net.URL( "file:/logout.wav"));
clip.play();
// loging out.....
}
catch( Exception e ) {}
}
});
代码示例来源:origin: com.googlecode.princeton-java-introduction/stdlib
/**
* Loop a sound file (in .wav, .mid, or .au format) in a background thread.
*/
public static void loop(String filename) {
URL url = null;
try {
File file = new File(filename);
if (file.canRead()) url = file.toURI().toURL();
}
catch (MalformedURLException e) { e.printStackTrace(); }
// URL url = StdAudio.class.getResource(filename);
if (url == null) throw new RuntimeException("audio " + filename + " not found");
AudioClip clip = Applet.newAudioClip(url);
clip.loop();
}
代码示例来源:origin: com.github.fracpete/princeton-java-stdlib
/**
* Play a sound file (in .wav, .mid, or .au format) in a background thread.
*/
public static void play(String filename) {
URL url = null;
try {
File file = new File(filename);
if (file.canRead()) url = file.toURI().toURL();
}
catch (MalformedURLException e) { e.printStackTrace(); }
// URL url = StdAudio.class.getResource(filename);
if (url == null) throw new RuntimeException("audio " + filename + " not found");
AudioClip clip = Applet.newAudioClip(url);
clip.play();
}
代码示例来源:origin: com.github.fracpete/princeton-java-stdlib
/**
* Loop a sound file (in .wav, .mid, or .au format) in a background thread.
*/
public static void loop(String filename) {
URL url = null;
try {
File file = new File(filename);
if (file.canRead()) url = file.toURI().toURL();
}
catch (MalformedURLException e) { e.printStackTrace(); }
// URL url = StdAudio.class.getResource(filename);
if (url == null) throw new RuntimeException("audio " + filename + " not found");
AudioClip clip = Applet.newAudioClip(url);
clip.loop();
}
代码示例来源:origin: brianway/algorithms-learning
/**
* Plays an audio file (in .wav, .mid, or .au format) in a background thread.
*
* @param filename the name of the audio file
*/
public static void play(String filename) {
URL url = null;
try {
File file = new File(filename);
if (file.canRead()) url = file.toURI().toURL();
} catch (MalformedURLException e) {
e.printStackTrace();
}
// URL url = StdAudio.class.getResource(filename);
if (url == null) throw new RuntimeException("audio " + filename + " not found");
AudioClip clip = Applet.newAudioClip(url);
clip.play();
}
代码示例来源:origin: brianway/algorithms-learning
/**
* Plays an audio file (in .wav, .mid, or .au format) in a loop in a background thread.
*
* @param filename the name of the audio file
*/
public static void loop(String filename) {
URL url = null;
try {
File file = new File(filename);
if (file.canRead()) url = file.toURI().toURL();
} catch (MalformedURLException e) {
e.printStackTrace();
}
// URL url = StdAudio.class.getResource(filename);
if (url == null) throw new RuntimeException("audio " + filename + " not found");
AudioClip clip = Applet.newAudioClip(url);
clip.loop();
}
代码示例来源:origin: igniterealtime/Spark
/**
* Creates an AudioClip from a URL.
*
* @param clipOfURL the url of the AudioClip to play. We only support .wav files at the moment.
* @return the AudioFile found. If no audio file was found,returns null.
*/
private AudioClip loadClipForURL(String clipOfURL) {
final URL url = SoundsRes.getURL(clipOfURL);
AudioClip clip = null;
try {
clip = Applet.newAudioClip(url);
}
catch (Exception e) {
Log.error("Unable to load sound url: " + url + "\n\t: " + e);
}
return clip;
}
代码示例来源:origin: org.ops4j.pax.logging/pax-logging-service
/**
* Attempt to initialize the appender by creating a reference to an AudioClip.
*
* Will log a message if format is not supported, file not found, etc.
*
*/
public void activateOptions() {
/*
* AudioSystem.getAudioInputStream requires jdk 1.3,
* so we use applet.newaudioclip instead
*
*/
try {
clip = Applet.newAudioClip(new URL(audioURL));
} catch (MalformedURLException mue) {
LogLog.error("unable to initialize SoundAppender", mue);}
if (clip == null) {
LogLog.error("Unable to initialize SoundAppender");
}
}
代码示例来源:origin: ops4j/org.ops4j.pax.logging
/**
* Attempt to initialize the appender by creating a reference to an AudioClip.
*
* Will log a message if format is not supported, file not found, etc.
*
*/
public void activateOptions() {
/*
* AudioSystem.getAudioInputStream requires jdk 1.3,
* so we use applet.newaudioclip instead
*
*/
try {
clip = Applet.newAudioClip(new URL(audioURL));
} catch (MalformedURLException mue) {
LogLog.error("unable to initialize SoundAppender", mue);}
if (clip == null) {
LogLog.error("Unable to initialize SoundAppender");
}
}
代码示例来源:origin: org.ops4j.pax.logging/pax-logging-service
/**
* Attempt to initialize the appender by creating a reference to an AudioClip.
*
* Will log a message if format is not supported, file not found, etc.
*
*/
public void activateOptions() {
/*
* AudioSystem.getAudioInputStream requires jdk 1.3,
* so we use applet.newaudioclip instead
*
*/
try {
clip = Applet.newAudioClip(new URL(audioURL));
} catch (MalformedURLException mue) {
LogLog.error("unable to initialize SoundAppender", mue);}
if (clip == null) {
LogLog.error("Unable to initialize SoundAppender");
}
}
代码示例来源:origin: ops4j/org.ops4j.pax.logging
/**
* Attempt to initialize the appender by creating a reference to an AudioClip.
*
* Will log a message if format is not supported, file not found, etc.
*
*/
public void activateOptions() {
/*
* AudioSystem.getAudioInputStream requires jdk 1.3,
* so we use applet.newaudioclip instead
*
*/
try {
clip = Applet.newAudioClip(new URL(audioURL));
} catch (MalformedURLException mue) {
LogLog.error("unable to initialize SoundAppender", mue);}
if (clip == null) {
LogLog.error("Unable to initialize SoundAppender");
}
}
代码示例来源:origin: MegaMek/megamek
/**
* Try to load the "bing" sound clip.
*/
private void loadSoundClip() {
if (GUIPreferences.getInstance().getSoundBingFilename() == null) {
return;
}
try {
File file = new File(GUIPreferences.getInstance().getSoundBingFilename());
if (!file.exists()) {
System.err.println("Failed to load audio file: " + GUIPreferences.getInstance().getSoundBingFilename()); //$NON-NLS-1$
return;
}
bingClip = Applet.newAudioClip(file.toURI().toURL());
} catch (Exception ex) {
ex.printStackTrace();
}
}
代码示例来源:origin: igniterealtime/Spark
/**
* Plays a sound file.
*
* @param soundFile the File object representing the wav file.
*/
public void playClip(final File soundFile) {
final Runnable playThread = () -> {
try {
final URL url = soundFile.toURI().toURL();
AudioClip ac = fileMap.get(url);
if (ac == null) {
ac = Applet.newAudioClip(url);
fileMap.put(url, ac);
}
ac.play();
}
catch (MalformedURLException e) {
Log.error(e);
}
};
TaskEngine.getInstance().submit(playThread);
}
内容来源于网络,如有侵权,请联系作者删除!