gpt4 book ai didi

javax.sound.sampled.LineUnavailableException :

转载 作者:行者123 更新时间:2023-12-01 17:34:22 26 4
gpt4 key购买 nike

我在我的Mac上创建了一个tictactoe(creategame类)游戏,将其上传到GitHub,在Windows 7上下载。然后运行eclipse项目的时候就出现了这个错误。在研究中,我认为这是一个软件/驱动程序问题,或者没有检测到声音文件,作为初学者,我完全被难住了。 谢谢大家的帮助。

  Error with playing sound.
javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 24 bit, stereo, 6 bytes/frame, little-endian not supported.
at com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(Unknown Source)
at com.sun.media.sound.DirectAudioDevice$DirectClip.implOpen(Unknown Source)
at com.sun.media.sound.AbstractDataLine.open(Unknown Source)
at com.sun.media.sound.DirectAudioDevice$DirectClip.open(Unknown Source)
at com.sun.media.sound.DirectAudioDevice$DirectClip.open(Unknown Source)
at TicTacToe.CreateGame.playSound(CreateGame.java:157)
at TicTacToe.CreateGame.actionPerformed(CreateGame.java:200)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

public void playSound() {
// Load sounds


try {
AudioInputStream A = AudioSystem.getAudioInputStream(getClass().getResourceAsStream("/A3_04.wav"));
AudioInputStream Bb = AudioSystem.getAudioInputStream(getClass().getResourceAsStream("/Bb4_01.wav"));
AudioInputStream C = AudioSystem.getAudioInputStream(getClass().getResourceAsStream("/C5_01.wav"));
AudioInputStream D = AudioSystem.getAudioInputStream(getClass().getResourceAsStream("/D4_01.wav"));
AudioInputStream E = AudioSystem.getAudioInputStream(getClass().getResourceAsStream("/E4_01.wav"));
AudioInputStream F = AudioSystem.getAudioInputStream(getClass().getResourceAsStream("/F4_01.wav"));
AudioInputStream G = AudioSystem.getAudioInputStream(getClass().getResourceAsStream("/G4_01.wav"));




// IR and IR2 = random number max 7

AudioInputStream[] Sounds = { C, D, E, F, G, A, Bb };

Clip clip = AudioSystem.getClip();
Clip clip2 = AudioSystem.getClip();

clip.open(Sounds[IR]);
clip2.open(Sounds[IR2]);

clip.start();
clip2.start();

} catch (Exception ex) {
System.out.println("Error with playing sound.");
ex.printStackTrace();

}
}

Screenshot of eclipse

非常感谢您的帮助:P

最佳答案

public class PlaySound {

public PlaySound() {
super();
}

@SuppressWarnings("resource")
public void playSound() {
AudioStream Sounds = null;

try {
InputStream a3 = this.getClass().getClassLoader().getResourceAsStream("A3_04.wav");
InputStream bB4 = this.getClass().getClassLoader().getResourceAsStream("Bb4_01.wav");
InputStream c4 = this.getClass().getClassLoader().getResourceAsStream("C5_01.wav");
InputStream d4 = this.getClass().getClassLoader().getResourceAsStream("D4_01.wav");
InputStream e4 = this.getClass().getClassLoader().getResourceAsStream("E4_01.wav");
InputStream f4 = this.getClass().getClassLoader().getResourceAsStream("F4_01.wav");
InputStream g4 = this.getClass().getClassLoader().getResourceAsStream("G4_01.wav");


AudioStream a = new AudioStream(a3);
AudioStream b = new AudioStream(bB4);
AudioStream c = new AudioStream(c4);
AudioStream d = new AudioStream(d4);
AudioStream e = new AudioStream(e4);
AudioStream f = new AudioStream(f4);
AudioStream g = new AudioStream(g4);

int randomNumber = (int) (Math.random() *6);

if (randomNumber == 0) {Sounds = a; }
if (randomNumber == 1) {Sounds = b; }
if (randomNumber == 2) {Sounds = c; }
if (randomNumber == 3) {Sounds = d; }
if (randomNumber == 4) {Sounds = e; }
if (randomNumber == 5) {Sounds = f; }
if (randomNumber == 6) {Sounds = g; }

AudioPlayer.player.start(Sounds);



} catch (Exception ex) {
System.out.println("Error with playing sound.");
ex.printStackTrace();
}
}

}

关于javax.sound.sampled.LineUnavailableException :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61067119/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com