goxr3plus / java-stream-player

🌌Java Advanced Audio Controller Library (WAV, AU, AIFF, MP3, OGG VORBIS, FLAC, MONKEY's AUDIO and SPEEX audio formats )
GNU General Public License v3.0
147 stars 33 forks source link

UnsupportedAudioFileException on exported jar #74

Closed PixelDoted closed 2 years ago

PixelDoted commented 2 years ago

java-stream-player version: 10.0.2

I can play MP3's in VSCode
but not in an exported jar

when I try to play an mp3 it outputs

Mar 31, 2022 11:32:36 AM com.goxr3plus.streamplayer.stream.StreamPlayer initAudioInputStream
INFO: File of unsupported format

javax.sound.sampled.UnsupportedAudioFileException: File of unsupported format
    at java.desktop/javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1066)
    at com.goxr3plus.streamplayer.stream.FileDataSource.getAudioInputStream(FileDataSource.java:29)
    at com.goxr3plus.streamplayer.stream.StreamPlayer.initAudioInputStream(StreamPlayer.java:338)
    at com.goxr3plus.streamplayer.stream.StreamPlayer.open(StreamPlayer.java:291)
    at me.pixeldots.imaudio.Audio.AudioPlayer.playAudio(AudioPlayer.java:49)
    at me.pixeldots.imaudio.Audio.APHelper.lambda$0(APHelper.java:17)
    at java.base/java.lang.Thread.run(Thread.java:833)

I found this issue (#73)
saying they were missing dependencies, but didn't say what dependencies

I also tried the demo code but it still didn't work when exported to a jar

goxr3plus commented 2 years ago

Let's see if @omegaui can help you with this . If not i will have a look . Just yesterday i updated XR3Player to Java 18 which is using java-stream-player so i will test it too why that may happen . Probably the exported jar is missing something . You can have a look on XR3Player pom file to see how i create the final jar file.

omegaui commented 2 years ago

@goxr3plus @PixelDoted

When I came across this issue, I took a look at META-INF's services files of each jar dependency of java-stream-player and found out that some files have the same name and in preparing the fat jar they were overwriting each other therefore causing the UnsupportedAudi...... Exception.

Thus, running from the IDE was preventing the overwrite as all dependencies were loaded dynamically.

So for me, dynamically loading the dependencies fixed the issue.

PixelDoted commented 2 years ago

I got it working by using the <build>...</build> from XR3Player's POM file

Thanks for the help!

goxr3plus commented 2 years ago

@omegaui Hm looks like I will decompile all the dependencies and fix their package names so they don't override that's weird.

goxr3plus commented 2 years ago

I got it working by using the <build>...</build> from XR3Player's POM file

Thanks for the help!

Happy to hear :) XR3Player uses all the functionality of Stream Player so any complex operation you may want to do I have done already so feel free to ask :)