Java 中如何插入背景音乐
2个回答
展开全部
import java.awt.BorderLayout;
import java.awt.Component;
import java.net.URL;
import javax.media.*;
public class PlayerApplet extends JApplet implements ControllerListener{
Player player = null;
public void init(){
setLayout(new BorderLayout());
String mediaFile = getParameter("FILE");
try{
URL mediaURL = new URL(getDocumentBase(),mediaFile);
player = Manager.createPlayer(mediaURL);
player.addControllerListener(this);
}catch(Exception ex){
System.err.println(ex.getMessage());
}
}
public void start(){
player.prefetch();
}
public void stop(){
//player.stop();
//player.deallocate();
}
public void destory(){
player.close();
}
public synchronized void controllerUpdate(ControllerEvent event){
if( event instanceof RealizeCompleteEvent ){
Component comp;
if(( comp = player.getVisualComponent() ) != null )
add("Center",comp);
if(( comp = player.getControlPanelComponent() ) != null)
add("South",comp);
validate();
}else if( event instanceof PrefetchCompleteEvent ){
player.setRate(3.0F);
player.start();
}
}
}
import java.awt.Component;
import java.net.URL;
import javax.media.*;
public class PlayerApplet extends JApplet implements ControllerListener{
Player player = null;
public void init(){
setLayout(new BorderLayout());
String mediaFile = getParameter("FILE");
try{
URL mediaURL = new URL(getDocumentBase(),mediaFile);
player = Manager.createPlayer(mediaURL);
player.addControllerListener(this);
}catch(Exception ex){
System.err.println(ex.getMessage());
}
}
public void start(){
player.prefetch();
}
public void stop(){
//player.stop();
//player.deallocate();
}
public void destory(){
player.close();
}
public synchronized void controllerUpdate(ControllerEvent event){
if( event instanceof RealizeCompleteEvent ){
Component comp;
if(( comp = player.getVisualComponent() ) != null )
add("Center",comp);
if(( comp = player.getControlPanelComponent() ) != null)
add("South",comp);
validate();
}else if( event instanceof PrefetchCompleteEvent ){
player.setRate(3.0F);
player.start();
}
}
}
追问
为什么说import javax.media.*;不存在呢,用的是NetBeans
2011-07-02
展开全部
这个可以去查一下java api
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询