java applecation可以播放声音吗

huyanqieyu 2008-04-12 03:44:46
java applecation可以播放声音吗,有办法吗??请高手说说怎么让它发出声音??
...全文
119 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
isk_java 2008-04-14
  • 打赏
  • 举报
回复
关注。
jeff_jian 2008-04-13
  • 打赏
  • 举报
回复
现在有很多人都写了JAVA的MP3播放器,我也写了一个,
APPLICATION可以播放声音文件.
jeff_jian 2008-04-13
  • 打赏
  • 举报
回复
applecation?
Application?
J_Factory 2008-04-13
  • 打赏
  • 举报
回复
看看JLayer这个开源项目吧,它提供了mp3格式的解码器,java自带的sound API支持的格式实在是太怪了
tiyuzhongxin789 2008-04-13
  • 打赏
  • 举报
回复
我也想学!!!关注...
Inhibitory 2008-04-12
  • 打赏
  • 举报
回复
可以. 代码来自<<Java经典代码>>一书, 可以到网上搜索下载看更仔细的, 里面还有很多与声音有关的代码.

These code examples and other materials are subject to Sun Microsystems,
Inc. Legal Terms
Loading and Playing Sampled Audio
Supported audio file formats: aif, au, and wav.
try {
// From file
AudioInputStream stream =
AudioSystem.getAudioInputStream(
new File("audiofile"));
// From URL
stream = AudioSystem.getAudioInputStream(
new URL("http://hostname/audiofile"));
// At present, ALAW and ULAW encodings must be
//converted
// to PCM_SIGNED before it can be played.
AudioFormat format = stream.getFormat();
if (format.getEncoding() !=
AudioFormat.Encoding.PCM_SIGNED) {
format = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
format.getSampleRate(),
format.getSampleSizeInBits()*2,
format.getChannels(),
format.getFrameSize()*2,
format.getFrameRate(),
true); // big endian
stream = AudioSystem.getAudioInputStream(
format, stream);
}
DataLine.Info info = new DataLine.Info(
Clip.class, stream.getFormat(),
//The next two lines should be in one line.
((int)stream.getFrameLength(
)*format.getFrameSize()));

Clip clip = (Clip) AudioSystem.getLine(info);
// This method does not return until the audio
//file is completely loaded.
clip.open(stream);
// Start playing.
clip.start();
} catch (MalformedURLException e) {
} catch (IOException e) {
} catch (LineUnavailableException e) {
} catch (UnsupportedAudioFileException e) {
}

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧