Saturday, May 28, 2011

[android-developers] MediaPlayer deadlock fix (or alternative players)

Hello,

I've seen this question asked a few times, but have not been able to
find the answer. I am developing a very simple music player that
streams MP3s from a list of URLs. It works fine most of the time, but
after playing several songs (or switching to a new song several
times), the application freezes and displays a choice between force-
closing the application or waiting for it to unfreeze. This seems to
happen while MediaPlayer.reset() is called. A simplified series of
calls in my program is as follows:

public void Play(Song song)
{
m_player.reset();//Hangs here after a few songs
m_player.setDataSource(song.url);
m_player.prepare();//I actually use prepareAsync here and
call .start() in the listener, but showing this for simplicity
m_player.start();

m_player.setOnCompletionListener(new OnCompletionListener()
{
@Override
public void onCompletion(MediaPlayer mp)
{
Play(nextsong.url);//Start over with a new song
}
});
}

Is there a way to get MediaPlayer to stop hanging? Are there any
simple alternatives to streaming music?

Thanks for any advice,
Andrey

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate