Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
New Developer
brent_glad
Posts: 66
Registered: 11-23-2009

media player.stop() then player.start() resumes from the same position. creating huge buffer?

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?

Please use plain text.
Developer
JCarty
Posts: 1,028
Registered: 01-25-2009

Re: media player.stop() then player.start() resumes from the same position. creating huge buffer?

[ Edited ]

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?

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
Please use plain text.
New Developer
brent_glad
Posts: 66
Registered: 11-23-2009

Re: media player.stop() then player.start() resumes from the same position. creating huge buffer?

 

            HttpConnection conn = (HttpConnection) Connector.open(murl, Connector.READ_WRITE);

 

 

We are using that to connect. Look forward to your advice!

Please use plain text.
Developer
JCarty
Posts: 1,028
Registered: 01-25-2009

Re: media player.stop() then player.start() resumes from the same position. creating huge buffer?

[ Edited ]

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.

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
Please use plain text.
New Developer
brent_glad
Posts: 66
Registered: 11-23-2009

Re: media player.stop() then player.start() resumes from the same position. creating huge buffer?

 

            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();


 

Please use plain text.
Developer
JCarty
Posts: 1,028
Registered: 01-25-2009

Re: media player.stop() then player.start() resumes from the same position. creating huge buffer?

[ Edited ]

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();
}

 

 

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
Please use plain text.
Developer
Posts: 1,474
Registered: 04-14-2009

Re: media player.stop() then player.start() resumes from the same position. creating huge buffer?

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.

Please use plain text.
Developer
JCarty
Posts: 1,028
Registered: 01-25-2009

Re: media player.stop() then player.start() resumes from the same position. creating huge buffer?

[ Edited ]

 


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.

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
Please use plain text.