我正在尝试在我的桌面上播放 MP3 文件。我有一台可以播放 MP3 的自动取款机,但我无法调节音量。即使它应该根据文档工作。我的代码:
我用这个: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);
似乎不起作用,因为无论我设置 put 作为参数,它仍然是相同的,音量不会改变。前段时间我确实问了一个问题,但没有得到回应,我仍在寻找答案,问题是;我可以使用什么 API 来播放带有音量调节和暂停和停止音乐的 MP3,非常感谢,Sam/