Playing an MP3 clip from a byte [].

Hi

I’m writing a little application that takes an encrypted MP3 file, decrypts it and plays it.

I read the file in to a byte [], decrypt it successfully. I am however having trouble playing it from a byte array.

To play from a file seems to be quite straight forward, simply use javax.media.Player, no real problem. I can’t seem to find a simple way to play it from and byte [].

Any help would be much appreciated.

Cheers

The Java SDK has no way of playing a MP3 file. It handles wav and a bounch of other formats but not MP3.

See http://www.javazoom.net/javalayer/javalayer.html for a open source mp3 layer.

See http://www.mp3licensing.com/royalty/software.html for royality rates (if you want something free as in beer use ogg - it’s better anyways).

Thanks for the feedback.

I did manage to get MP3 playback working from a file, the following method takes a file name and kicks off playback.

The problem I have is trying to get this to work from a byte array.

Cheers,
Sharkins

import javax.media.*;

public void load(String url, boolean autoplay) throws Exception {

    if (player != null) {
        player.stop();
    }

    url = "file:" + url;

    mediaURL = new URL(url);

    player = Manager.createPlayer(mediaURL);

    // Add ourselves as a listener for a player's events
    player.addControllerListener(this);

    player.realize();
    player.prefetch();

    if (autoplay)
        player.start();
}

ahh you are using Java Media Framework. Well that has support for Mp3 but as you said there seams to be some problem with playing from a byte[] array. That is there is no simple metod anyway. But I think you can create extention of the DataSources that JMF is using and calling the method Manager.createPlayer( yourDatasource) instead. But as I never used JMF I can’t give you any more advice than to try google.

try lwjgl fmod :wink:

Thanks for the input people.

I’ll continue to play around with it and hopefully come up with something.

Cheers