The Sound Player component and system.util.playSoundClip are wav file only. Since wav files are simply huge, compared to mp3, I decided to try out the JavaFX libraries. Here is my first runthrough.
Verified on my Windows machine. No time to check on Linux yet, but since JavaFX is included on x86/x64, I don’t see why it wouldn’t work.
I can say it will not work on ARM (like a Raspi), since Oracle dropped JavaFX support. Which is sad, because that’s what I really wanted it for…
This example plays the theme from Bonanza, because, well, why not? Also added a tag to monitor to stop the playback early, if needed.
from javafx.scene.media import AudioClip from time import sleep # Set path to audio file and tag used to stop playback. audioFilePath = 'file:///C:/media/Bonanza.mp3' stopFlagPath = '[default]Test/Audio/stopFlag' # Load up the audio stream plunk = AudioClip(audioFilePath) # Play the audio stream plunk.play() # Check every so often to see if the stopFlag is active, and stop playback if true. # Useful for long clips. while plunk.isPlaying() == 1: stopFlag = system.tag.read(stopFlagPath).value if stopFlag == 1: plunk.stop() else: sleep(0.3) # Reset the stop flag system.tag.write(stopFlagPath, 0)