android - MediaPlayer keeps freezing on pre L devices -


i developing mediaplayer in android , far have tested application on lollipop, lg g3, s5 etc. found problem when runned app on pre l device ( s4 mini running 4.4.2 ). when music starts, because play url it's start playing 2-3 seconds , stop short time , after it's playing again , on.

reading again main tutorial android.developers, found can block main ui need run media player in service.

public class myservice extends service implements mediaplayer.onpreparedlistener {     private static final string action_play = "com.example.action.play";     mediaplayer mmediaplayer = null;      public int onstartcommand(intent intent, int flags, int startid) {         ...         if (intent.getaction().equals(action_play)) {             mmediaplayer = ... // initialize here             mmediaplayer.setonpreparedlistener(this);             mmediaplayer.prepareasync(); // prepare async not block main thread         }     }      /** called when mediaplayer ready */     public void onprepared(mediaplayer player) {         player.start();     } } 

if solution don't understand how can it, media player currenyl running in thread in activity.

i have solved problem calling .prepareasync() method after setting datasource , prepare.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -