看看JMF
http://servlet.java.sun.com/javaone/conf/bofs/845/0-sf2001.jsp
应该可以实现你说的功能
http://servlet.java.sun.com/javaone/conf/bofs/845/0-sf2001.jsp
应该可以实现你说的功能
解决方案 »
- pache MINA与SNMP4j的问题
- JFilechooser的两个set方法不懂
- java 新手 如何建立打开对话框
- sheet.createRow(i)与sheet.getRow(i)的区别
- JScrollPane 里面放一个JTable 现在要把原有JTable去掉换成另外一个JTable该怎么做?
- Java里面如何显示"÷"这个符号?
- >>>>>>>>>>>急 程序编译无错 可appletviewer的效果中 箭头不改变方向
- 在LINUX怎么用java进行串行口通信?
- 使用Java多线程技术模拟大厦电梯运行
- 为什么我用jbuilder7生成的.exe文件运行时居然需要jre??这也叫什么??
- 初学Java有个问题:如何输入?
- 不同版本的JDK能否同时装上阿???
我有例程,你可以给我发信:[email protected]
可是,我是要做Applet啊...
要把JMF也打包到Applet里吗?
我只是想播放一个声音文件,播放完毕后,调页面中javascript函数,通知javascript
这就足够了
用JMF感觉大材小用了似的用Applet不能解决的就是,AudioClip播放是异步的
我想要同步的,或者有事件都行.Applet是否不能解决这个问题啊?再次对2位帮助表示感谢.
import java.awt.*;
import java.awt.event.*;
public class Pf extends Applet implements ActionListener {
AudioClip clip;
Button button_play,button_loop,button_stop;
public void init()
{//getAudioClip(),getCodeBase()是Applet的方法
clip=getAudioClip(getCodeBase(),"sound01.wav");
button_play=new Button("开始");
button_loop=new Button("循环");
button_stop=new Button("停止");
button_play.addActionListener(this);
button_loop.addActionListener(this);
button_stop.addActionListener(this);
add(button_play);add(button_loop);add(button_stop);
}
public void stop(){
clip.stop();
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==button_play) clip.play();
else if(e.getSource()==button_loop) clip.loop();
if(e.getSource()==button_stop) clip.stop();
}
}
import java.applet.AudioClip;
public class AudioLoop extends java.applet.Applet implements Runnable
{
AudioClip bgsound;
AudioClip beep;
Thread runner;
public void start()
{
if(runner==null)
{
runner=runner=new Thread(this);
runner.start();
}}
public void stop()
{
if(runner!=null)
{
if(bgsound!=null)
runner.stop();
runner==null;
}
}
public viod init()
{
bgsound=getAudioClip(getCodeBase()."audio/loop.au");
beep=getAudioClip(getCodeBase(),"audio/beep,au");
}
public void run()
{
if(bgsound!=null)bgsound.loop();
while(runner!=null)
{
try
{
Thread.sleep(100);
catch(InterruptedException e)
{}
if(bgsound!=null)
bgsound.play();
}
}
}
public void paint(Graphics g)
{
g.drawString("Playing Sound",10,10);
}
}
我举一个例子:三个audio file
a.au b.au c.au我需要用applet播放这3个声音
是依此播放,播放完a,然后b,然后c
audioclip不提供播放完毕的通知功能
如果分别写3个play,那么就会导致3个一起放
而我要的是分别,依此播放还有一个问题就是我想,播放a.au c.au
b.au不播放,但是中间要停播放b.au的声音那么长的时间...
今天我终于找到了sun的文档,上面说,这需要
得到clip 的length,然后sleep那么长
时间可是,,问题是,怎么才知道一个AudioClip的长度?anyone can help me?
document from sun:Problem: I want to play several sound files in succession from an applet. However, when I use play two times after each other they just get mixed up.
Unfortunately, the Java 2 SDK does not provide notification of when playback has completed. The Java Sound API provides this feature. It is available as an early access release. If you must use the SDK, you could try to determine the length of each clip and sleep for the same about of time before playing the next clip.