0

I've seen a lot of question about playing .mp3 files using JLayer in Android, a lot of these questions have accepted answers meaning that they succeeded in using JLayer to process .mp3 files.

I downloaded the .jar and imported it into my project. I then implemented the following to test if it is working:

AssetFileDescriptor assetFileDescriptor = getApplication().getAssets().openFd("testing.mp3");
FileDescriptor fileDescriptor = assetFileDescriptor.getFileDescriptor();
FileInputStream stream = new FileInputStream(fileDescriptor);
//JLayer below
Player player = new Player(stream);
player.play();

When I run my application I get the following error:

java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/sound/sampled/AudioFormat;

I did some research and found that javax is not supported by android. I had a look through JLayer.jar and found that in JavaSoundAudioDevice.java is the following imports:

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Line;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.DataLine.Info;

so, if javax is not supported by android and JLayer uses javax, how does other people get it working? - as shown in this question..

HB.
  • 4,116
  • 4
  • 29
  • 53
  • 1
    go [this](https://stackoverflow.com/questions/47414321/android-mp3-jlayer-missing-data) way - the first code snippet is more or less how you should decode your data – pskink Jul 18 '18 at 05:21
  • btw why do you have to use JLayer? – pskink Jul 18 '18 at 08:37
  • @pskink I found NetBeans project online that uses JLayer. I'm trying to build the project for android. I can remove JLayer and replace it with MediaPlayer if I like, but I decided to try and use JLayer. Is there a reason not to use it? – HB. Jul 18 '18 at 08:46
  • sure you can use it but the performance can suffer... – pskink Jul 18 '18 at 08:50

0 Answers0