Hi
I am using MMAPI to create player to play a wav file from a bluetooth inputstream- which is always open, even after I finish playing.
When I use player.start(), I can only hear a sudden of noise then get exception: java.lan.negtiveArraySizeException. With the same code, I can play sound well from a http link, or a fileStream (getClass().getResourceAsStream()).
I tried to read from the bluetooth inputstream, InputStream.read(byteBuffer) blocks and never return after the whole file finished. I guess because I didn't get EOF in the stream. This I solved with inputStream.available() >0 as condition, then I got the right file.
Here is part of my code:
My debug infomation shows the player is realized, prefefetched and started successfully, but can't play correctly, and give exceptions. My PlayerListener never get the END_OF_MEDIA event.Code://connection is bluetooth StreamConnection InputStream inputStream = connection.getInputStream(); public void run() { try { p = Manager.createPlayer(inputStream, "audio/X-wav"); p.addPlayerListener(this); p.realize(); debugInfo("Realized"); p.prefetch(); debugInfo("Prefetched"); p.start(); debugInfo("started"); } catch (IOException ioe) { ioe.printStackTrace(); } catch (MediaException me) { me.printStackTrace(); } } //Stop player on END_OF_MEDIA event.
Well, I am not sure I explained my problem clear. can anybody help me?
Thanks in advance.

Reply With Quote

