【发布时间】:2019-02-20 12:24:30
【问题描述】:
无法编译。我正在尝试在使用 try and catch 时播放声音。 wav 文件位于我的桌面上。 我收到错误,例如: AudioStream 无法解析为类型 AudioStream 无法解析为类型 无法解析 AudioPlayer。
我不确定如何解决这个问题,我知道这很简单,
import java.io.FileInputStream;
import java.io.InputStream;
public class PlayMySoundApplication
{
public static void main(String[] args)
throws Exception
{
// open the sound file as a Java input stream
String applause2x = "/Users/pc/Desktop/applause2x.wav";
InputStream in = new FileInputStream(applause2x);
// create an audiostream from the inputstream
AudioStream audioStream = new AudioStream(in);
// play the audio clip with the audioplayer class
AudioPlayer.player.start(audioStream);
【问题讨论】:
-
1. try & catch 用于处理异常。 2. 我在你发布的代码中看不到你的 try & catch
-
3.您尚未导入
AudioStream或AudioPlayer -
在上面的代码中,
throws Exception语句应该作为一个动作监听器。 -
@JonathanArendt throws Exception 应该替换为 try-catch
-
同意,但是导致问题的原因是什么?缺少导入
AudioPlayer和AudioStream类?
标签: java file-io try-catch fileinputstream