本文整理汇总了Java中javafx.scene.media.AudioClip类的典型用法代码示例。如果您正苦于以下问题:Java AudioClip类的具体用法?Java AudioClip怎么用?Java AudioClip使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AudioClip类属于javafx.scene.media包,在下文中一共展示了AudioClip类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import javafx.scene.media.AudioClip; //导入依赖的package包/类
/**
* Level initialisieren
*
* @param collector - Objektsammler
*/
@Override
protected void init(ObjectCollector collector) {
rdm = new Random();
// Init Hintergrundmusik
menuTheme = new Media(getClass().getResource("/de/janroslan/verse/resources/sounds/menu.aiff").toExternalForm());
mplayer = new MediaPlayer(menuTheme);
mplayer.setVolume(0.7);
mplayer.setAutoPlay(true);
// Init Maus Hover Sound
buttonHoverSound = new AudioClip(getClass().getResource("/de/janroslan/verse/resources/sounds/click.wav").toString());
initPictures(collector);
initObjs(collector);
initTexts(collector);
initButtons(collector);
}
示例2: Picto
import javafx.scene.media.AudioClip; //导入依赖的package包/类
public Picto(String name) {
this.rectangle = new Rectangle();
String soundResourceName = "pictogrammes/sounds/" + name + ".m4a";
URL soundSourceResource = getClass().getClassLoader().getResource(soundResourceName);
if (soundSourceResource == null) {
throw new RuntimeException("Resource not found : " + soundResourceName);
}
this.sound = new AudioClip(soundSourceResource.toExternalForm());
String imageResourceName = "pictogrammes/images/" + name + ".jpg";
URL imageResource = getClass().getClassLoader().getResource(imageResourceName);
if (imageResource == null) {
throw new RuntimeException("Resource not found : " + imageResourceName);
}
rectangle.setFill(new ImagePattern(new Image(imageResource.toExternalForm()), 0, 0, 1, 1, true));
}
示例3: displayAlert
import javafx.scene.media.AudioClip; //导入依赖的package包/类
/**
* 大破警告
*
* @param badlyShips
*/
private static void displayAlert(List<Ship> badlyShips) {
try {
Path dir = Paths.get(AppConfig.get().getAlertSoundDir());
Path p = Audios.randomAudioFile(dir);
if (p != null) {
AudioClip clip = new AudioClip(p.toUri().toString());
clip.setVolume(AppConfig.get().getSoundLevel() / 100D);
clip.play();
}
} catch (Exception e) {
LoggerHolder.get().warn("サウンド通知に失敗しました", e);
}
for (Ship ship : badlyShips) {
ImageView node = new ImageView(Ships.shipWithItemImage(ship));
String message = Messages.getString("ship.badly", Ships.shipMst(ship) //$NON-NLS-1$
.map(ShipMst::getName)
.orElse(""), ship.getLv());
Tools.Conrtols.showNotify(node, "大破警告", message, Duration.seconds(30));
}
}
示例4: DurianWidgetService
import javafx.scene.media.AudioClip; //导入依赖的package包/类
public DurianWidgetService(List<SearchTreeItem> searchTreeItems) {
this.searchTreeItems = searchTreeItems;
setOnSucceeded(e -> goAgain());
setOnFailed (e -> goAgain());
searchTreeItems.stream().forEach(sti -> {
sti.searchProperty().addListener((observable, oldVal, newVal) -> {
Integer total = newVal.getSearchResult().getTotal();
if (total != null) {
resultsFound.setValue(total + resultsFound.getValue());
if (resultsFound.intValue() > 0) {
String soundfile = Paths.get(BluemarlinConfig.defaultNotificationSound()).toAbsolutePath().toUri().toString();
AudioClip notificationSound = new AudioClip(soundfile);
Platform.runLater(() -> notificationSound.play(1.0));
}
}
});
});
}
示例5: checkWallCollision
import javafx.scene.media.AudioClip; //导入依赖的package包/类
private void checkWallCollision()
{
boolean ballHitTopWall = ball.getY() < MARGIN_TOP_BOTTOM;
boolean ballHitBottomWall = ball.getY() + BALL_SIZE > HEIGHT - MARGIN_TOP_BOTTOM;
if (ballHitTopWall || ballHitBottomWall) {
ball.setAngle(ball.getAngle() * -1);
new AudioClip(Sounds.HIT_WALL).play();
}
if (ballHitTopWall) {
ball.setY(MARGIN_TOP_BOTTOM);
} else if (ballHitBottomWall) {
ball.setY(HEIGHT - MARGIN_TOP_BOTTOM - BALL_SIZE);
}
}
示例6: towerBlast
import javafx.scene.media.AudioClip; //导入依赖的package包/类
public void towerBlast(boolean sound,int cycle){
final IntegerProperty frameCounter = new SimpleIntegerProperty(0);
anim = new Timeline(
new KeyFrame(FRAME_TIME, event -> {
frameCounter.set((frameCounter.get() + 1) % numCells);
setViewport(cellClips[frameCounter.get()]);
})
);
anim.setCycleCount(cycle);
anim.setOnFinished(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
stack.getChildren().remove(current);
}
});
anim.play();
if(sound){
AudioClip blast =new AudioClip (Url.BLAST_SOUND_EFFECT);
blast.play();
blast.setCycleCount(1);
}
}
示例7: readObject
import javafx.scene.media.AudioClip; //导入依赖的package包/类
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
long versione = (Long) ois.readLong();
nome = (String) ois.readObject();
numero = ois.readInt();
byte[] buf = new byte[1024];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
for (int readNum; (readNum = ois.read(buf)) != -1;) {
bos.write(buf, 0, readNum); //no doubt here is 0
}
buf = bos.toByteArray();
System.err.println("Lunghezza lettura: " + buf.length);
File temp = File.createTempFile("tempfileCSVS", ".wav");
fos = new FileOutputStream(temp.getAbsolutePath());
fos.write(buf);
fos.close();
URI u = temp.toURI();
path = temp.getAbsolutePath();
System.out.println(u.toURL().toString());
audioClip = new AudioClip(u.toString());
}
示例8: Choice
import javafx.scene.media.AudioClip; //导入依赖的package包/类
public Choice(String name) {
this.rectangle = new Rectangle();
this.sound = new AudioClip("file:sounds/" + name + ".m4a");
rectangle.setFill(new ImagePattern(new Image("file:images/" + name + ".png"), 0, 0, 1, 1, true));
this.name = name;
}
示例9: playBackgroundMusic
import javafx.scene.media.AudioClip; //导入依赖的package包/类
/**************************************************
* Helper Methods *
**************************************************/
private void playBackgroundMusic()
{
music = SoundUtils.getAudioClip(res.path() + res.music());
music.setCycleCount(AudioClip.INDEFINITE);
music.play();
}
示例10: loadSound
import javafx.scene.media.AudioClip; //导入依赖的package包/类
/**
* Load the sound into the cache.
*
* @param identifier The unique identifier to store the sound data. This is
* unique across all sound types.
* @param source The path location relative to src/main/resources/sound/
* @param type The type of the sound to be store into the cache. This
* determines to what object the sound is played by.
* @return Returns true if sound was successfully loaded into SoundCache.
* False if a sound already exists with identifier.
* @throws IOException If there was a problem opening a file.
* @throws InvalidMidiDataException If the standard MIDI file is malformed.
*/
public boolean loadSound(String identifier, String source, SoundType type)
throws InvalidMidiDataException, IOException {
//If a sound is being loaded with an identifier already being used, return false.
if (effectsCollection.containsKey(identifier) || midiCollection.containsKey(identifier)) {
return false;
}
/*
* Attempt to create a file object and see if such a file exists.
* Otherwise throw a exception that it doesn't exist.
*/
Path soundPath = Paths.get("src", "main", "resources", "sounds", source);
URI soundLocation = soundPath.toUri();
File soundFile = new File(soundLocation);
if (!soundFile.exists()) {
throw new FileNotFoundException();
}
//If the sound is an Effect, create an AudioClip. If it is a MIDI create a sequence.
if (type == SoundType.EFFECT) {
effectsCollection.put(identifier, new AudioClip(soundLocation.toString()));
return true;
} else if (type == SoundType.MIDI) {
Sequence sequence = MidiSystem.getSequence(soundFile);
midiCollection.put(identifier, sequence);
return true;
} else {
throw new IllegalArgumentException("Audio type does not exist.");
}
}
示例11: showRotate
import javafx.scene.media.AudioClip; //导入依赖的package包/类
private void showRotate() {
URL doorBellWav = getClass().getResource("door-bell.wav");
AudioClip doorBellSound = new AudioClip(doorBellWav.toString());
doorBellSound.play();
if (timeline != null) {
timeline.stop();
}
Settings.instance().incrementCurrentUser();
timeMinutes.set("Rotate");
paneColor.set("-fx-background-color:#FF0000");
showMainWindow();
nag = new Timeline();
nag.setCycleCount(Timeline.INDEFINITE);
nag.getKeyFrames().add(new KeyFrame(Duration.seconds(15), new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
if (timeMinutes.getValue().equals("Rotate")) {
showMainWindow();
doorBellSound.play();
} else {
nag.stop();
}
}
}));
nag.playFromStart();
}
示例12: start
import javafx.scene.media.AudioClip; //导入依赖的package包/类
@Override
public void start(Stage palco) throws Exception {
AudioClip clip = new AudioClip(AUDIO_URL);// 1
clip.play(); // 2
StackPane raiz = new StackPane();
raiz.getChildren().add(new Text("Tocando Música ")); // 3
Scene cena = new Scene(raiz, 600, 100);
palco.setTitle("Tocando Audio em JavaFX");
palco.setScene(cena);
palco.show();
}
示例13: Home
import javafx.scene.media.AudioClip; //导入依赖的package包/类
public Home(){
mTimerText = new SimpleStringProperty();
mTaskText = new SimpleStringProperty();
setTaskText("CURRENT TASK");
setTimerText(0);
mNotify = new AudioClip(getClass().getResource("/sounds/notify.mp3").toExternalForm());
}
示例14: Sound
import javafx.scene.media.AudioClip; //导入依赖的package包/类
/**
* Constructor for sound object, takes the filename and creates an AudioClip object
* @param fileName The filename of the sound file that will be played
*/
public Sound(String fileName) {
persistentSettings();
try {
URL url = Music.class.getResource("../SoundClips/" + fileName);
soundClip = new AudioClip(url.toString());
} catch (RuntimeException e) {
LOG.error("There was an error creating sound, check file URL", e);
}
}
示例15: playForever
import javafx.scene.media.AudioClip; //导入依赖的package包/类
/**
* Plays the sound indefinitely
*/
public void playForever() {
try {
if (mute) {
return;
}
soundClip.setVolume(vol);
soundClip.setCycleCount(AudioClip.INDEFINITE);
soundClip.play();
} catch (RuntimeException e) {
LOG.error("Could not play the sound forever", e);
}
}