×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Nov 2004
    Posts
    79

    can't play wav from inputstream (no ending)

    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:
    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.
    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.
    Well, I am not sure I explained my problem clear. can anybody help me?
    Thanks in advance.
    Last edited by aluckybird; 2004-12-03 at 16:59.

  2. #2
    Registered User
    Join Date
    Nov 2005
    Posts
    9

    Re: can't play file from inputstream (no ending)

    is it because of the bandwidth or packet issue?

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    29

    Re: can't play file from inputstream (no ending)

    Different phones handle sound in different ways. Try not prefetching or realizing, or just prefetch or just realize &c.

  4. #4
    Nokia Developer Expert
    Join Date
    Jul 2003
    Posts
    46

    Re: can't play file from inputstream (no ending)

    There's nothing wrong with the file itself. The implementation probably reads the whole content during realize or prefetch. If if can't get the EOF properly then that might be the reason for the failure.

    You can try to wrap the InputStream of BT under your own InputStream implementation and your code could then provide the proper EOF when the file has been completely read.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×