12-03-2009 03:37 PM
Hi, I am creating a media player that streams a radio's online stream.
I got it all running using createPlayer, realize, prefetch and start.
In my app, I have play and pause buttons. The pause button calls the stop() function, which appears to work.Then the play button calls the start() function.
two problems:
=== PROBLEM 1
Sometimes the app doesn't launch and I have no idea why, or it launches but doesn't play anything back.
The stream is rock solid and i know the stream is fine. There seems to be no reason why the app fails. It happens on the simulator and the device. It often just dies right before the start() function.
=== PROBLEM 2
Another problem is that when I resume after pausing, it picks up exactly where it left off. How does it do that? I am not playing from a static file online. This is a stream. Is the app creating a huge buffer that I don't know of?
How do I make the pause button pause the stream and then have the play button start the stream in real-time and NOT where it left off?
12-03-2009 04:02 PM - last edited on 12-03-2009 04:03 PM
stop() doesn't reset the position back to the beginning it does start it where it left off. I think you have to call stop() then setMediaTime(0).
How did you get your audio to stream. Is it a standard http request or are you using RSTP for that radio stream?
12-03-2009 04:06 PM
HttpConnection conn = (HttpConnection) Connector.open(murl, Connector.READ_WRITE);
We are using that to connect. Look forward to your advice!
12-03-2009 04:14 PM - last edited on 12-03-2009 04:25 PM
Try the following that I've mentioned above ( setting setMediaTime(0)) after pressing stop button.
As far as it not launching all the time, if you have a try /catch around the call to start, analyze the console log in debug mode to see what the stack trace is telling you.
Without actual code, from you, around the call to player.start(), it is difficult to determine why it is *sometimes* closing.
12-03-2009 04:48 PM
String murl = new String("** this is where my stream link is");
HttpConnection conn = (HttpConnection) Connector.open(murl, Connector.READ_WRITE);
System.out.println("Connecting to: " + murl);
System.out.println("\n");
System.out.println("XXXXXXX= " + conn.getResponseMessage());
System.out.println("header 1: " + conn.getHeaderField(1));
System.out.println("header 2: " + conn.getHeaderField(2));
System.out.println("header 3: " + conn.getHeaderField(3));
System.out.println("header 4: " + conn.getHeaderField(4));
InputStream is = conn.openInputStream();
_player = Manager.createPlayer(is, "audio/mpeg");
_player.realize();
_player.prefetch();
_player.start();
12-03-2009 05:00 PM - last edited on 12-03-2009 05:02 PM
Manager.createPlayer, _player.realize(), _player.prefetch() and _player.start() all throw a MediaException error when there is an error.
Try putting a try / catch around the code like below:
try{
_player = Manager.createPlayer(is, "audio/mpeg");
_player.realize();
_player.prefetch();
_player.start();
} catch(Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
12-03-2009 05:04 PM
You need to implement your own DataSource + SourceStream that you will provide to the player instead of an InputStream. Your SourceStream can then perform some degree of buffering and will also be able to prevent excessive buffering by the player. The buffer inside your SourceStream is under your control, making it possible for you to discard the buffer whenever you feel like it. Also, a smart implementation will actually stop downloading the stream when the player is paused and will resume the download from the correct place when the player is resumed.
12-03-2009 05:14 PM - last edited on 12-03-2009 05:14 PM
klyubin wrote:You need to implement your own DataSource + SourceStream that you will provide to the player instead of an InputStream. Your SourceStream can then perform some degree of buffering and will also be able to prevent excessive buffering by the player. The buffer inside your SourceStream is under your control, making it possible for you to discard the buffer whenever you feel like it. Also, a smart implementation will actually stop downloading the stream when the player is paused and will resume the download from the correct place when the player is resumed.
Can anyone provide a good working example of the DataSource / SourceStream combination? I have searched but have found fragments of code but no posted working example and that is the biggest issue with why the same questions are reposted.
It is difficult on someone new to say "you'll have to provide your own implementation for..." when there is no good example of it.