我试图播放MP3文件,我的桌面上。我有些东西可以播放MP3,但我无法调节音量。尽管它应该按照文档工作。我的代码:播放MP3的Java
我用这个:https://code.google.com/p/java-audio-player/
import maryb.player.Player;
public class MusicPlayer {
private Player player;
private float volume;
private String filePath;
/**
* Gets the location of the file being played.
* @return
*/
public String getFileLocation() {
return filePath;
}
/**
* Gets the volume at which the music file is being played.
* @return
*/
public float getVolume() {
return volume;
}
/**
* Sets the current volume of the music file being played.
* @param volume
*/
public void setVolume(float volume) {
this.player.setCurrentVolume(volume);
}
/**
* Constructs a new MusicPlayer object, to use the specified music file.
* @param filePath - path to the music file.
* @param volume - volume the file should be played at.
*/
public MusicPlayer(String filePath, float volume) {
try {
player = new Player();
player.setCurrentVolume(volume);
player.setSourceLocation(filePath);
} catch(Exception e) {
e.printStackTrace();
}
}
/**
* Plays the music file.
*/
public void play() {
if (player != null && !player.getSourceLocation().equals(null) || !player.getSourceLocation().equals("")) {
player.play();
}
}
/**
* Pauses the music file.
*/
public void pause() {
if (player != null && !player.getSourceLocation().equals(null) || !player.getSourceLocation().equals("")) {
player.pause();
}
}
/**
* Stops the music file.
*/
public void stop() {
if (player != null && !player.getSourceLocation().equals(null) || !player.getSourceLocation().equals("")) {
player.stop();
}
}
public static void main(String[] args) {
MusicPlayer player = new MusicPlayer(signlink.findcachedir() + "music.mp3", 0.1f);
player.play();
}
}
此:
player.setCurrentVolume(volume);
似乎并不奏效,因为无论我设置把作为参数,它仍然是相同的,音量不会改变。我确实问过一个问题,但没有得到回应,我仍然在寻找答案,问题在于;我可以使用哪些API用于播放MP3带音量调节和暂停和停止音乐的能力,非常感谢,萨姆/
音量值'0F'和'1.0F',你确定你没有用错误的值设置之间? – 2013-07-20 15:43:39
是啊,我0F和1.0F之间设定,当我将它设置,我已经试过印刷播放器的音量值和它说0.0 – user1009569
嗯,你的M $ Windows机器上运行?所以它可能很有趣,但尝试以管理员模式运行'java.exe',我不知道这个lib如何改变音量(应用程序或全局系统声音)! – 2013-07-20 16:23:10