Alternatives to rotating buffers into Players in J2ME?
Asked Answered
A

3

6

Due to (quite annoying) limitations on many J2ME phones, audio files cannot be played until they are fully downloaded. So, in order to play live streams, I'm forced to download chunks at a time, and construct ByteArrayInputStreams, which I then feed to Players.

This works well, except that there's an annoying gap of about 1/4 of a second every time a stream ends and a new one is needed. Is there any way to solve this problem, or the problem above?

Acyl answered 24/4, 2009 at 23:53 Comment(1)
I think what you want are the SourceStream and DataSource classes found in javax.microedition.media.protocol found here java.sun.com/javame/reference/apis/jsr135/javax/microedition/…Caves
B
2

The only good way to play long (3 minutes and more) tracks with J2ME JSR135, moderately reliably, on the largest number of handsets out there, is to use a "file://" url when you create the player, or to have the inputstream actually come from a FileConnection.

recent blackberry phones can use a ByteArrayInputstream only when they have a large java heap memory available.

a lot of phones running on the Symbian operating system will allow you to put files in a private area for the J2ME application while still being able to play tracks in the same location.

Bumpkin answered 27/4, 2009 at 12:49 Comment(0)
P
1

Unfortunately you can't get rid of these gaps, at least not on any device I've tried it on. It's very annoying indeed. It's part of the spec that you can't stream audio or video over HTTP.

If you want to stream from a server, the only way to do it is to use an RTSP server instead though you'll need to check support for this on your device.

And faking RTSP using a local server on the device (rtsp://localhost...) doesn't work either.. I tried that too.

Preconcerted answered 27/4, 2009 at 7:9 Comment(0)
C
0

EDIT2: Or you could just look at this which seems to be exactly what you want: http://java.sun.com/javame/reference/apis/jsr135/javax/microedition/media/protocol/DataSource.html

I would create two Player classes and make sure that I had received enough chunks before I started playing them. Then I would start playing the first chunk through player one and load the second one into player two. Then I would use the TimeBase class to keep track of how much time has passed and when I knew the first chunk would end (you should know how long each chunk has to play) then I would start playing the second chunk through the second player and load the third chunk into the first and so on and so forth until there are no more chunks to play.

The key here is using the TimeBase class properly to know when to make the transition. I think that that should get rid of the annoying 1/4 second gap bet between chunks. I hope that works, let me know if it does because it sounds really interesting.

EDIT: Player.prefetch() could also be useful here in reducing latency.

Caves answered 25/4, 2009 at 0:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.