java 程序写音乐
代码不报错.但运行后没有声音...请哪位写个告知于我(在线等);写的详细点吧.....imnoob==!...
代码 不报错.
但 运行后 没有声音...
请哪位写个告知于我(在线等);
写的详细点吧.....im noob = =! 展开
但 运行后 没有声音...
请哪位写个告知于我(在线等);
写的详细点吧.....im noob = =! 展开
展开全部
首先你要去http://java.sun.com/products/java-media/jmf/2.1.1/下载一下JMF的包,如果用的是windows操作系统,就下一下for xp版本的
package com.qiu.jmf;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import javax.media.CannotRealizeException;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player;
/**
* 播放音频文件
* Date : 2009-09-21
* @author Qiu
*
*/
public class SimpleAudioPlayer {
public Player player = null;
public SimpleAudioPlayer (URL url) throws IOException,NoPlayerException,CannotRealizeException {
player = Manager.createRealizedPlayer(url);
}
public SimpleAudioPlayer (File file) throws IOException,NoPlayerException,CannotRealizeException {
this(file.toURL());
}
public void start(){
player.start();
}
public void stop(){
player.stop();
player.close();
}
public static void main(String[] args) throws NoPlayerException, CannotRealizeException, IOException {
File file=new File("C:\\Program Files\\KuGou\\KuGou2008\\mp3\\h不得不爱(潘玮柏_弦子).mp3");
SimpleAudioPlayer audioPlayer = new SimpleAudioPlayer(file);
audioPlayer.start();
}
}
package com.qiu.jmf;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import javax.media.CannotRealizeException;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player;
/**
* 播放音频文件
* Date : 2009-09-21
* @author Qiu
*
*/
public class SimpleAudioPlayer {
public Player player = null;
public SimpleAudioPlayer (URL url) throws IOException,NoPlayerException,CannotRealizeException {
player = Manager.createRealizedPlayer(url);
}
public SimpleAudioPlayer (File file) throws IOException,NoPlayerException,CannotRealizeException {
this(file.toURL());
}
public void start(){
player.start();
}
public void stop(){
player.stop();
player.close();
}
public static void main(String[] args) throws NoPlayerException, CannotRealizeException, IOException {
File file=new File("C:\\Program Files\\KuGou\\KuGou2008\\mp3\\h不得不爱(潘玮柏_弦子).mp3");
SimpleAudioPlayer audioPlayer = new SimpleAudioPlayer(file);
audioPlayer.start();
}
}
展开全部
Java应用程序播放音乐是很麻烦的!!!你可以看一下这个:
http://hi.baidu.com/anexplore/blog/item/50d1481a035d80f0af5133f2.html
http://hi.baidu.com/anexplore/blog/item/50d1481a035d80f0af5133f2.html
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
文件读取的时候不对吧
要么格式不对
要么格式不对
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询