Home Calling reset on Media Player after calling setDataSource, Freezes UI
Reply: 1

Calling reset on Media Player after calling setDataSource, Freezes UI

Manuel Munoz
1#
Manuel Munoz Published in 2015-04-15 20:31:51Z

Im working on a Music Player app, and all the music handled by the app are from streaming resources.

Everytime the user changes songs, i need to call reset and set a new dataSource. If the user rapidly switches songs, and the MediaPlayer is on the preparing state, the UI from my app freezes.

This only happens if i call reset and the media player is in the preparing state.

How can i prevent my app UI from freezing and getting an ANR?

PS: Im using prepareAsync(), not prepare().

Kevin Parker
2#
Kevin Parker Reply to 2015-04-15 20:35:41Z

See setOnPreparedListener. You can keep track of the state in your class through various listeners and avoid calling prepareAsync().

You might have better luck also calling stop() before reset().

http://developer.android.com/reference/android/media/MediaPlayer.html#setOnPreparedListener%28android.media.MediaPlayer.OnPreparedListener%29

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.316235 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO