javafx.scene.media.AudioClip Java Examples

The following examples show how to use javafx.scene.media.AudioClip. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApiReqMapStart.java    From logbook-kai with MIT License 6 votes vote down vote up
/**
 * 大破警告
 *
 * @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));
    }
}
 
Example #2
Source File: Beeper.java    From helloiot with GNU General Public License v3.0 5 votes vote down vote up
public Beeper(ClipFactory factory, Node alert, Animation alertanimation) {

        this.alert = alert;
        this.alertanimation = alertanimation;
        // http://www.soundjay.com/tos.html
        beep = factory.createClip(getClass().getResource("/com/adr/helloiot/sounds/beep-01a.wav").toExternalForm(), AudioClip.INDEFINITE);
    }
 
Example #3
Source File: Exercise_16_22.java    From Intro-to-Java-Programming with MIT License 5 votes vote down vote up
@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
}
 
Example #4
Source File: ApiReqMapNext.java    From logbook-kai with MIT License 5 votes vote down vote up
/**
 * 大破警告
 *
 * @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));
    }
}
 
Example #5
Source File: Audios.java    From logbook-kai with MIT License 5 votes vote down vote up
/**
 * デフォルトサウンドを再生するタスクを返します。
 * 
 * @return デフォルトサウンドを再生するタスク
 */
public static Runnable playDefaultNotifySound() {
    return () -> {
        try {
            Path p = defaultNotifySound();
            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);
        }
    };
}
 
Example #6
Source File: MainController.java    From logbook-kai with MIT License 5 votes vote down vote up
/**
 * サウンド通知
 */
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);
        }
    }
}
 
Example #7
Source File: MediaTools.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static void audio(File file, double volumn, int cycle) {
    AudioClip clip = new AudioClip(file.toURI().toString());
    clip.setVolume(volumn);
    clip.setCycleCount(cycle);
    clip.play();
}
 
Example #8
Source File: StandardClip.java    From helloiot with GNU General Public License v3.0 4 votes vote down vote up
StandardClip(String url, int cyclecount) {
    clip = new AudioClip(url);
    clip.setCycleCount(cyclecount);
}
 
Example #9
Source File: PlaySoundController.java    From pdfsam with GNU Affero General Public License v3.0 4 votes vote down vote up
private void playSound(String soundURI) {
    if (userContext.isPlaySounds()) {
        new AudioClip(soundURI).play(1);
    }
}