I am trying to play an MP3 file on my desktop. I have something that plays MP3, but I canโt adjust the volume. Although it should work in accordance with the documents. My code is:
I use this: https://code.google.com/p/java-audio-player/
import maryb.player.Player; public class MusicPlayer { private Player player; private float volume; private String filePath; public String getFileLocation() { return filePath; } public float getVolume() { return volume; } public void setVolume(float volume) { this.player.setCurrentVolume(volume); } public MusicPlayer(String filePath, float volume) { try { player = new Player(); player.setCurrentVolume(volume); player.setSourceLocation(filePath); } catch(Exception e) { e.printStackTrace(); } } public void play() { if (player != null && !player.getSourceLocation().equals(null) || !player.getSourceLocation().equals("")) { player.play(); } } public void pause() { if (player != null && !player.getSourceLocation().equals(null) || !player.getSourceLocation().equals("")) { player.pause(); } } 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(); } }
It:
player.setCurrentVolume(volume);
It seems that it does not work, since everything that I set as an argument is still the same, the volume does not change. I asked a question a while ago, but did not receive an answer, and I'm still looking for an answer, a question; which API can I use to play MP3 with volume control and the ability to pause and stop music, thanks a lot, Sam /
source share