Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MediaPlayer Streaming issues on Android 4.4 (API 19)

My app is having issues with the MediaPlayer streaming, specifically on Nexus 5. I'm not sure if this is Nexus 5 or API level 19 causing the problem. Basically my MediaPlayer gets prepared and I call MediaPlayer.start(), but the MediaPlayer doesn't begin streaming.

This happens at random and only on my Nexus 5 device. When this happens, if I try seeking the MediaPlayer it begins to play. Is anyone else experiencing this?

UPDATE: I've filed a bug against Android: https://code.google.com/p/android/issues/detail?id=62304

like image 586
shoke Avatar asked Nov 11 '13 21:11

shoke


People also ask

How do I reset my media player on Android?

Just use pause to stop, followed by seekTo(0) before restarting: mediaPlayer. seekTo(0); mediaPlayer.

What is MediaPlayer release?

android.media.MediaPlayer. MediaPlayer class can be used to control playback of audio/video files and streams. MediaPlayer is not thread-safe. Creation of and all access to player instances should be on the same thread. If registering callbacks, the thread must have a Looper.

Which method is used to bring the media player to prepared state?

So instead of calling MediaPlayer directly, MediaPlayerWrapper is used, which internally updates StateMachine and exposes getState() method.


1 Answers

Not sure if it's related, I had similar issue with local file playback, only on 4.4 occasionally, not reproducible on 4.3. This only happens when I want to play a new song reusing the existing MediaPlayer.

Solution: I had to call stop(); before reset(); and setDataSource():

    stop();
    reset();

    try {
        setDataSource(context, uri);
        prepareAsync();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
like image 82
X.Y. Avatar answered Sep 30 '22 19:09

X.Y.