Java 类javafx.scene.media.AudioClip 实例源码
项目:GazePlay
文件:Pictos.java
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));
}
项目:Verse
文件:MainMenu.java
/**
* 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);
}
项目:logbook-kai
文件:ApiReqMapNext.java
/**
* 大破警告
*
* @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));
}
}
项目:bluemarlin
文件:DurianWidgetService.java
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));
}
}
});
});
}
项目:fx-pong
文件:Game.java
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);
}
}
项目:stupidwarriors
文件:Explode.java
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);
}
}
项目:SimulatoreCVS
文件:ModelCampana.java
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());
}
项目:GazePlay
文件:Choices.java
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;
}
项目:apcs_final
文件:GamePanel.java
/**************************************************
* Helper Methods *
**************************************************/
private void playBackgroundMusic()
{
music = SoundUtils.getAudioClip(res.path() + res.music());
music.setCycleCount(AudioClip.INDEFINITE);
music.play();
}
项目:coaster
文件:SoundCache.java
/**
* 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.");
}
}
项目:MobTime
文件:TimeController.java
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();
}
项目:livro-javafx-pratico
文件:TocandoAudio.java
@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();
}
项目:work-break-countdown-timer
文件:Home.java
public Home(){
mTimerText = new SimpleStringProperty();
mTaskText = new SimpleStringProperty();
setTaskText("CURRENT TASK");
setTimerText(0);
mNotify = new AudioClip(getClass().getResource("/sounds/notify.mp3").toExternalForm());
}
项目:minesim
文件:Sound.java
/**
* 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);
}
}
项目:minesim
文件:Sound.java
/**
* 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);
}
}
项目:Intro-to-Java-Programming
文件:Exercise_16_22.java
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
// Create three buttons
Button play = new Button("Play");
Button loop = new Button("Loop");
Button stop = new Button("Stop");
// Create a pane and set its properties
HBox pane = new HBox(5);
pane.setAlignment(Pos.CENTER);
pane.setPadding(new Insets(10, 10, 10, 10));
pane.getChildren().addAll(play, loop, stop);
// Create a audio clip
AudioClip audio = new AudioClip(
"http://cs.armstrong.edu/liang/common/audio/anthem/anthem3.mp3");
// Create and register handlers
play.setOnAction(e -> {
audio.play();
});
stop.setOnAction(e -> {
audio.stop();
});
loop.setOnAction(e -> {
audio.setCycleCount(AudioClip.INDEFINITE);
});
// Create a scene and place it in the stage
Scene scene = new Scene(pane);
primaryStage.setTitle("Exercise_16_22"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
}
项目:logbook-kai
文件:MainController.java
/**
* サウンド通知
*/
private void soundNotify(Path dir) {
if (this.clip == null || !this.clip.isPlaying()) {
try {
Path p = Audios.randomAudioFile(dir);
if (p != null) {
this.clip = new AudioClip(p.toUri().toString());
this.clip.setVolume(AppConfig.get().getSoundLevel() / 100D);
this.clip.play();
}
} catch (Exception e) {
LoggerHolder.get().warn("サウンド通知に失敗しました", e);
}
}
}
项目:timey
文件:AudioPlayer.java
/**
* Spielt den Sound in einem separaten Thread ab.
* @param threadHelper ThreadHelper
* @param path Pfad zur Datei
* @param exceptionHandler Behandlung von Exceptions
*/
public void playInThread(final ThreadHelper threadHelper, final String path, final Thread.UncaughtExceptionHandler exceptionHandler) {
/*
* Sound in separatem Thread abspielen, da die Anwendung bei nicht-vorhandener Datei sonst einige Zeit (ca. 5 Sekunden) nicht mehr
* reagieren würde, bevor eine Exception auftritt.
*/
threadHelper.run(new Runnable() {
public void run() {
new AudioClip(new File(path).toURI().toString()).play();
}
}, exceptionHandler);
}
项目:SimulatoreCVS
文件:ModelCampana.java
public ModelCampana(String nome, int numero, String path) {
this.nome = nome;
this.numero = numero;
this.path = path;
File f = new File(path);
URI u = f.toURI();
this.audioClip = new AudioClip(u.toString());
}
项目:SimulatoreCVS
文件:ModelCampana.java
public void loadFromPath(String path) {
File f = new File(path);
URI u = f.toURI();
audioClip = new AudioClip(u.toString());
this.path = path;
}
项目:sevenwonders
文件:GUIManager.java
public static void loadMusic(String musicFileName) {
if (bgMusic != null)
bgMusic.stop();
bgMusic = ResManager.getAudio(musicFileName);
bgMusic.setCycleCount(AudioClip.INDEFINITE);
bgMusic.setVolume(volumn);
}
项目:Fishification
文件:AbstractWorld.java
public void playAudioClip(String audioClipName, double volume) {
// Play Audio
ResourceManager<AudioClip> audioResourceManager = getAudioResourceManager();
AudioClip audioClip = audioResourceManager.get(audioClipName);
if (audioClip != null) {
audioClip.play(volume);
}
}
项目:minicraft-plus-revived
文件:Sound.java
private Sound(String name) {
clip = new AudioClip(Sound.class.getResource(name).toString());
}
项目:apcs_final
文件:AdBlockerFrame.java
private void playBackgroundMusic()
{
music = SoundUtils.getAudioClip("res/menu/bread.mp3");
music.setCycleCount(AudioClip.INDEFINITE);
music.play();
}
项目:FXGLGames
文件:Config.java
private static AudioClip loadAudio(String path) throws Exception {
AudioClip clip = new AudioClip(instance.getClass().getResource(AUDIO_ROOT + path).toExternalForm());
clip.volumeProperty().bind(volume);
return clip;
}
项目:Tantrix
文件:MovableTile.java
public MovableTile(Tile Tile, GameGUI gameGUI, int deckPosition) {
super(MovableTile.class.getResource(
TILE_BASE_URI + Tile.toString() + ".png").toString());
this.tile = Tile;
this.gameGUI = gameGUI;
this.setDeckPosition(deckPosition);
/*Invoked when the mouse is pressed on a Movable Tile*/
this.setOnMousePressed(event -> {
scenex = event.getSceneX();
sceney = event.getSceneY();
xbase = getLayoutX();
ybase = getLayoutY();
event.consume();
});
/*Invoked when the mouse dragged a Movable Tile*/
this.setOnMouseDragged(event -> {
toFront();
dragged = true;
/* move Tile by same amount as the mouse */
setLayoutX(xbase + event.getSceneX() - scenex);
setLayoutY(ybase + event.getSceneY() - sceney);
scenex = event.getSceneX();
sceney = event.getSceneY();
xbase = getLayoutX();
ybase = getLayoutY();
gameGUI.highlightNearestHexagon(this);
event.consume();
});
/*Invoked when the mouse is released from the Movable Tile*/
this.setOnMouseReleased(event -> {
AudioClip tileReleaseClip = new AudioClip(AUDIO_BASE_URI.toString());
tileReleaseClip.play();
if (!dragged){
rotate();
}
else {
gameGUI.attemptToMove(this,deckPosition);
dragged = false;
}
gameGUI.checkPuzzle();
event.consume();
});
}
项目:helloiot
文件:Beeper.java
public Beeper(ClipFactory factory, Label alert) {
this.alert = alert;
// http://www.soundjay.com/tos.html
beep = factory.createClip(getClass().getResource("/com/adr/helloiot/sounds/beep-01a.wav").toExternalForm(), AudioClip.INDEFINITE);
}
项目:helloiot
文件:StandardClip.java
StandardClip(String url, int cyclecount) {
clip = new AudioClip(url);
clip.setCycleCount(cyclecount);
}
项目:keymix
文件:Sample.java
public Sample (String uri) {
this.URI = uri;
this.clip = new AudioClip(uri);
this.playing = false;
}
项目:keymix
文件:Sample.java
private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException {
in.defaultReadObject();
this.clip = new AudioClip(this.URI);
}
项目:Verse
文件:Switch.java
public Switch(int startX, int startY) {
super("switch", startX, startY, new Image("/de/janroslan/verse/resources/switch.png"), 3, 1, 0.5, 2, 0);
pushed = false;
clickSound = new AudioClip(getClass().getResource("/de/janroslan/verse/resources/sounds/click.wav").toString());
}
项目:Verse
文件:LevelFinish.java
public LevelFinish(int startX, int startY) {
super("finish", startX, startY, new Image("/de/janroslan/verse/resources/flag.png"), 2, 1, 0.5, 2, 0);
finishSound = new AudioClip(getClass().getResource("/de/janroslan/verse/resources/sounds/levelFinish.wav").toString());
finished = false;
}
项目:FXGLGames
文件:Config.java
private static AudioClip loadAudio(String path) throws Exception {
AudioClip clip = new AudioClip(instance.getClass().getResource(AUDIO_ROOT + path).toExternalForm());
clip.volumeProperty().bind(volume);
return clip;
}
项目:minesim
文件:Sound.java
public Sound(AudioClip audioSound){
soundClip = audioSound;
}
项目:minesim
文件:Sound.java
public void setSoundClip(AudioClip audioSetSound){
soundClip = audioSetSound;
}
项目:minesim
文件:Sound.java
public AudioClip getSoundClip(){
return soundClip;
}
项目:minesim
文件:SoundTests.java
@Before
public void setUp(){
sound1 = PowerMockito.mock(AudioClip.class);
}
项目:lib-resources
文件:LibResources.java
@Override
public AudioClip loadAudioClip(String audioClipName) {
return this.loadAudioClip(ELoadStrategy.LOAD_WITH_PREDEFINED_PATH, audioClipName);
}
项目:fx-pong
文件:Game.java
private void checkPaddleOrEdgeCollision(Paddle paddle)
{
boolean ballHitEdge;
if (paddle == player) {
ballHitEdge = ball.getX() < MARGIN_LEFT_RIGHT + GOAL_WIDTH;
} else {
ballHitEdge = ball.getX() + BALL_SIZE > WIDTH - MARGIN_LEFT_RIGHT - GOAL_WIDTH;
}
if (!ballHitEdge) {
return;
}
boolean ballHitPaddle = ball.getY() + BALL_SIZE > paddle.getY() && ball.getY() < paddle.getY() + PADDLE_HEIGHT;
if (ballHitPaddle) {
/*
* Find out what section of the paddle was hit.
*/
for (int i = 0; i < PADDLE_SECTIONS; i++) {
boolean ballHitCurrentSection = ball.getY() < paddle.getY() + (i + 0.5) * PADDLE_SECTION_HEIGHT;
if (ballHitCurrentSection) {
ball.setAngle(PADDLE_SECTION_ANGLES[i] * (paddle == opponent ? -1 : 1));
break; /* Found our match. */
} else if (i == PADDLE_SECTIONS - 1) { /* If we haven't found our match by now, it must be the last section. */
ball.setAngle(PADDLE_SECTION_ANGLES[i] * (paddle == opponent ? -1 : 1));
}
}
/*
* Update and reposition the ball.
*/
ball.setSpeed(ball.getSpeed() * BALL_SPEED_INCREASE);
if (paddle == player) {
ball.setX(MARGIN_LEFT_RIGHT + GOAL_WIDTH);
} else {
ball.setX(WIDTH - MARGIN_LEFT_RIGHT - GOAL_WIDTH - BALL_SIZE);
}
new AudioClip(Sounds.HIT_PADDLE).play();
} else {
/*
* Update the score.
*/
if (paddle == opponent) {
player.setScore(player.getScore() + 1);
new AudioClip(Sounds.SCORE_PLAYER).play();
} else {
opponent.setScore(opponent.getScore() + 1);
new AudioClip(Sounds.SCORE_OPPONENT).play();
}
/*
* Check if the game has ended. If not, play another round.
*/
if (player.getScore() == winningScore || opponent.getScore() == winningScore) {
state = State.ENDED;
onGameEnd.run();
} else {
launchBall();
}
}
}
项目:BrickGame
文件:SoundBank.java
@Override
public Iterator<AudioClip> iterator() {
return clips.values().iterator();
}