6

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

b.lyte
  • 6,518
  • 4
  • 40
  • 51
  • I'm having the exact same issue on 4.4 (Nexus 5). The video will play but takes an age to start. Switching to the new ART runtime stopped me from having to seek in order to kick start the video. Seems google broke the codec. – Mark Nov 13 '13 at 11:40
  • Not sure but it looks related, on my Nexus 5 I'm having issues playing progressively streamed files (with chrome / firefox or the gallery ap) served by mod_h264_streamer (with Apache 2) which worked on android 4.3, when saved on the phone such files won't play too while the original file (not modified by the Apache module) plays normally – r4dius Nov 13 '13 at 01:50
  • Thanks for the comments! Super helpful to know that I'm not the only one facing these issues. I'm also noticing issues where the MediaPlayer will stream but stop playback of the clip earlier than it should: http://stackoverflow.com/questions/19918118/mediaplayer-randomly-stops-on-android-4-4-19 @Mark, thanks for the tip. This may work, but it's not really a viable solution to tell all my apps users to switch to. I'll post a bug against Android and see what they say. – b.lyte Nov 15 '13 at 02:48
  • FYI I've filed a bug against Android: https://code.google.com/p/android/issues/detail?id=62304 – b.lyte Nov 15 '13 at 21:21
  • 1
    I have the exact same problem with the app I'm developing (testing on my nexus 5 with stock android 4.4 unrooted). The bug doesn't appear on my galaxy nexus running android 4.3 paranoid android. Calling seekTo(0) right after MediaPlayer.start() seems to be a working workaround for now. – MrMaffen Nov 24 '13 at 23:33
  • I've spoken with someone from the Android team. They're releasing a fix for this issue in the next release it seems. – b.lyte Dec 23 '13 at 03:15
  • There seems to be a workaround solution for this: The start() not starting issue only happens for live event streams, where the segment target duration is 1 second or less. The workaround for the issue of playback not starting fast enough is to have segment sizes that add up to a "little over 10 seconds" with minimal overhead. E.g. 7-10 second segments are slower than 5-7 or 10-12 second segments. Hope this helps. – b.lyte Dec 23 '13 at 03:17

2 Answers2

1

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();
    }
X.Y.
  • 13,726
  • 10
  • 50
  • 63
0

time solution: in onprepare before start try this code:

if (mSeekWhenPrepared != 0) {
            seekTo(mSeekWhenPrepared);
        } else {seekTo(0);}
Master
  • 690
  • 6
  • 18