IllegalStateException for MediaPlayer.prepareAsync

后端 未结 5 1414
一向
一向 2020-12-28 12:23
05-19 11:52:51.622: ERROR/MediaPlayer(1291): prepareAsync called in state 8
05-19 11:52:51.622: WARN/System.err(1291): java.lang.IllegalStateException
5条回答
  •  自闭症患者
    2020-12-28 13:06

    Your updated question:

    1. Check whether you have INTERNET permission in your AndroidManifest.xml
    2. Check whether you have some data connection enabled, as you want to stream from the internet
    3. What do you mean with "this solution also fails"? Does it throw an IllegalStateException? From what I see, it just won't do anything at all, because you register your OnPreparedListener after the MediaPlayer object has prepared itself, causing the onPrepared() method never to be called.

    A better approach would be to write:

    MediaPlayer mp = new MediaPlayer();  
    mp.setDataSource("http://.../movie.mp4");  
    mp.setOnPreparedListener(this);  
    mp.prepareAsync();
    

提交回复
热议问题