Question

I'm trying to play wav file from database .I recuparate blob file with php file. This code works with video file if we replace inputStream with DataInputStream:

public void playAudio() {

    try {
        ContentConnection connection = (ContentConnection)Connector.open("http://localhost/P/getXmlMusic.php");
      InputStream iStrm = connection.openInputStream();         

        player = Manager.createPlayer(iStrm,"audio/x-wav");
        player.addPlayerListener(this);
        player.setLoopCount(4);
        player.prefetch();
        player.realize();
        player.start();
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
}

Error : Failed to realize Player: Malformed wave media: expected 'RIFF'

NB : I can play the same file locally.So the file is okey!

Was it helpful?

Solution

The valid WAV file should be started with "RIFF" string.

expected 'RIFF' means that RIFF string isn't found in the start of the WAV file. So it seems that the retrieved stream from server is not a valid WAV file.

I suggest you to try playing the original WAV file from your device's (locally). Change your code a bit to access the WAV using FileConnection API, or embed it directly inside the jar then read it using getResourceAsStream.

If the same error still persist, then the WAV file is invalid / not-standard, and Java API inside your device won't able to play it.

If the error is gone, then the mistake is in the server-side code. Ensure you have performed all operations correctly : filling database with wav file, read the blob from database, and forward it to client.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top