0

基本上我正在尝试使用已弃用的 java applet 东西将一些旧代码更新到 javafx,我认为主要问题是由于某种原因 javafx 的 audioclip 不支持“.au”文件并且我收到了这个错误,我会想知道是否有办法修复它/使用其他方式在 javafx 中播放音频而不实际转换文件类型。

原始代码:

import java.applet.*;

public class AnnounceTimeOnSeparateThread implements Runnable{
	private AudioClip[] hourAudio = new AudioClip[12];
	private AudioClip[] minuteAudio = new AudioClip[60];
	private AudioClip amAudio = Applet.newAudioClip(this.getClass().getResource("/audio/am.au"));
	private AudioClip pmAudio = Applet.newAudioClip(this.getClass().getResource("/audio/pm.au"));
	private int hour;
	private int minute;
	public AnnounceTimeOnSeparateThread() {
		for (int i = 0; i < 12; i++)
			hourAudio[i] = Applet.newAudioClip(this.getClass().getResource("/audio/hour" + i + ".au"));
		for (int i = 0; i < 60; i++)
			minuteAudio[i] = Applet.newAudioClip(this.getClass().getResource("/audio/minute" + i + ".au"));
	}

	public void setHour(int hour) {
		this.hour=hour;
	}
	public void setMinute(int minute) {
		this.minute=minute;
	}
	public void run() {
		try{ 
			hourAudio[hour % 12].play();
			Thread.sleep(1500);
			minuteAudio[minute].play();
			Thread.sleep(1500);
			}catch (InterruptedException ex) {
			}
		if (hour < 12)
			amAudio.play();
		else
			pmAudio.play();
		}
	}

我更新的错误尝试:(基本上只是将其更改为 fx 语法并导入))

import javafx.scene.media.AudioClip;

public class AnnounceTimeOnSeparateThread implements Runnable {
	private AudioClip[] hourAudio = new AudioClip[12];
	private AudioClip[] minuteAudio = new AudioClip[60];
	private AudioClip amAudio = new AudioClip(this.getClass().getResource("/audio/am.au").toExternalForm());
	private AudioClip pmAudio =new AudioClip(this.getClass().getResource("/audio/pm.au").toExternalForm());
	private int hour;
	private int minute;

	public AnnounceTimeOnSeparateThread() {
		for (int i = 0; i < 12; i++)
			hourAudio[i] = new AudioClip(this.getClass().getResource("/audio/hour" + i + ".au").toExternalForm());
		for (int i = 0; i < 60; i++)
			minuteAudio[i] = new AudioClip(this.getClass().getResource("/audio/minute" + i + ".au").toExternalForm());
	}

4

0 回答 0