Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Mudassir
Posts: 209
Registered: ‎11-08-2008
My Device: Not Specified
Accepted Solution

Play audio file through streaming...

Hi All,

I wanna play the song through streaming.

I wanna play audio File. But instead of connection with the specific file. I wanna pass the array of bytes directly to the stream,and then play those bytes to the players.

How can I achieve this ?

 

Thanks and Regards
Developer
Mudassir
Posts: 209
Registered: ‎11-08-2008
My Device: Not Specified

Re: Play audio file through streaming...

[ Edited ]

 

Hi,

I wanna play audio player, directly by passing array of bytes...

Message Edited by Mudassir on 08-26-2009 09:08 AM
Thanks and Regards
Developer
cliff76
Posts: 52
Registered: ‎07-17-2008
My Device: Not Specified

Re: Play audio file through streaming...

Having direct experience, I can tell you that the streaming API is broken (not functional) in OS versions prior to 4.3. I believe somewhere after 4.3 they enabled streaming and I know for certain that its available in 4.5. So the first thing you'll need t odo is upgrade beyond 4.3 if you haven't already. Next you can try invoking the J2ME MMAPI call that accepts an input stream and see if that works. I haven't tried this yet but I'm planning on doing so. Post back on your progress cause I'd love to know how well and on which devices this works. Here's the API call you'll want to look at:

 

javax.microedition.media.Player player = javax.microedition.media.Manager.createPlayer(getAudioInputStream(), "audio/x-wav");

Developer
Developer
rab
Posts: 283
Registered: ‎07-22-2008
My Device: Not Specified

Re: Play audio file through streaming...

You can always use a custom  DataSource class. It works with all OS versions.

 

Rab

 

Developer
cliff76
Posts: 52
Registered: ‎07-17-2008
My Device: Not Specified

Re: Play audio file through streaming...

You know what? That's a good idea. I never thought about that many years ago... I like it! :smileyhappy: I'll definitely have to try this out...
Developer
Mudassir
Posts: 209
Registered: ‎11-08-2008
My Device: Not Specified

Re: Play audio file through streaming...

ByteArrayInputStream in2 = null; try { FileConnection fileConnection = (FileConnection)Connector.open("file:///SDCard/Blackberry/music/1.wav", Connector.READ ); InputStream inputStream = fileConnection.openDataInputStream(); byte[] audioData = new byte[(int)fileConnection.fileSize()]; inputStream.read(audioData,0,audioData.length); { in2 = new ByteArrayInputStream(audioData); } } catch (Exception ex) { System.err.println("Error open file connection."+ex.toString()); } secondPlayer = javax.microedition.media.Manager.createPlayer((InputStream)in2, "audio/wav"); // secondPlayer.addPlayerListener(this); secondPlayer.realize(); secondVolumeControl = getVolumeControl(secondPlayer); if (secondVolumeControl != null) secondVolumeControl.setLevel(90); secondPlayer.prefetch(); secondPlayer.start();

 

thanks every one, finally i found the solution.It is possible by taking the ByteArrayInputStream, and passing the array of bytes of any wave file.But the array of bytes should be in the proper sequence as it store in the Wave File.

 

Thanks all...

Thanks and Regards
Developer
cliff76
Posts: 52
Registered: ‎07-17-2008
My Device: Not Specified

Re: Play audio file through streaming...

That's interesting. Does the audio data have to be played from memory? I see you get the InputStream from the SDCard ten read into a memory array before creating a second InputStream around the memory contents. Is this necessary or can you play the stream directly off of the card? Also, when you mention the right order are you referring to big endian vs. little endian? If so, do you have examples of byte-order swapping over an audio stream? I apologize for the barrage of questions. I'm getting ready to dive into the same type of development and I don't want to bang my head like I did last time.
Developer
Developer
rab
Posts: 283
Registered: ‎07-22-2008
My Device: Not Specified

Re: Play audio file through streaming...

Just one remark:

   this solution ( if I am not mistaken ) requires the entire file to be downloaded before starting the player.

The solution using the DataSource will allow you to play while downloading.

 

Rab

Developer
cliff76
Posts: 52
Registered: ‎07-17-2008
My Device: Not Specified

Re: Play audio file through streaming...

This kinda makes sense. I remember having buffer issues and truncation when I tried using a direct URL to the audio. Of course I was using this for TTS so I also implemented a weird way of breaking up sentences into separate calls and chaining them together with an "on complete".
Developer
Mudassir
Posts: 209
Registered: ‎11-08-2008
My Device: Not Specified

Re: Play audio file through streaming...

Hi,

If possible, then, may you plz explain more clearly ? 

Thanks and Regards