Stop or release MediaPlayer while it is still preparing

Is it a bug or is it not possible to release, stop or kill MediaPlayer while it's preparing?

I have an instance of MediaPlayer running in Service, it stops fine if I stop, release, set it to null, while MediaPlayer is in prepared state. But it doesn't if I stop, release, set it to null if it's in preparing state.

onPrepared() is called after stop, release, setting to null. Some workaround for this?

I think it's common use case when a user wants to stop MediaPlayer before it has finished preparing.

Answers


By looking at the MediaPlayer documentation, you're not allowed to call stop() on an uninitialized object; which makes sense because you can't stop what is not running/ready yet.

On the other hand, release() seems to do the trick after looking at the source code of MediaPlayer.

But it doesn't harm to add a boolean flag to indicate that there is no need for the MediaPlayer object anymore and use that flag to release your object if onPrepared() gets called.

A pseudocode would look like this:

public void cancel(){
 mCancel = true;
}

public void onPrepared(MediaPlayer player){
  if(mCancel){
   player.release();
   //nullify your MediaPlayer reference
   mediaPlayer = null
  }
}

Need Your Help

How can I fix my div overlay for Firefox?

jquery css

I have this jsfiddle where I put a "cursor" div on top of a table. A function moves the cursor around by manipulating the CSS attributes left, top, width and height.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.