Sometimes MediaPlayer prepareAsyc () does not call onPrepared () until POWER is pressed

I have been trying to reproduce what my QA team has called a β€œrandom pause” for some time. Today I played it three times when debugging using logcat. It appears intermittently and only in a bad network.

The user pauses in the sound until he touches his phone (press the power button or trackball), and he immediately starts playing again. This is because I call start in the onPrepared callback, and start is never called in these cases. This is our most serious mistake.

What i know:

1) This happens intermittently on the Nexus One with 2.2.1 (not sure if on other devices)

2) I call prepareAsyc () from the playback service while the device screen is off. Sometimes onPrepared () is never called, so my next call to mediaplayer.start () never starts. I see with network sniffers and a buffering callback that buffering is happening.

3) If I touch the power of the device or the trackball to wake it up, onPrepared () will be called immediately (already buffered) and my callback will start playing.

Here are logs with timestamps showing the problem three times:

FIRST EXAMPLE (without a callback for 20 seconds until I pressed the power button):

11-10 16:10:55.966 I/AwesomePlayer( 59): calling prefetcher->prepare() 11-10 16:11:15.511 D/KeyguardViewMediator( 94): wakeWhenReadyLocked(26) 11-10 16:11:15.511 D/KeyguardViewMediator( 94): handleWakeWhenReady(26) 11-10 16:11:15.511 D/KeyguardViewMediator( 94): pokeWakelock(5000) 11-10 16:11:15.511 I/power ( 94): *** set_screen_state 1 11-10 16:11:15.561 D/SurfaceFlinger( 94): Screen about to return, flinger = 0x1fe300 11-10 16:11:15.701 D/AK8973 ( 64): Compass Start 11-10 16:11:15.701 D/WifiService( 94): ACTION_SCREEN_ON 11-10 16:11:15.711 I/Prefetcher( 59): [0x602d80] cache below low water mark, filling cache. 11-10 16:11:15.821 I/AwesomePlayer( 59): prefetcher is done preparing 11-10 16:11:15.831 W/MogMediaPlayer.onPreparedListener( 2968): onPrepared, calling notifyPrepared() 

TWO MORE EXAMPLES (the first time 3 seconds before I hit the power, the next was 8 s):

 11-10 16:14:54.649 I/AwesomePlayer( 59): calling prefetcher->prepare() 11-10 16:14:57.500 D/KeyguardViewMediator( 94): wakeWhenReadyLocked(26) 11-10 16:14:57.500 D/KeyguardViewMediator( 94): handleWakeWhenReady(26) 11-10 16:14:57.500 D/KeyguardViewMediator( 94): pokeWakelock(5000) 11-10 16:14:57.500 I/power ( 94): *** set_screen_state 1 11-10 16:14:57.560 D/SurfaceFlinger( 94): Screen about to return, flinger = 0x1fe300 11-10 16:14:57.580 D/WifiStateTracker( 94): Reset connections and stopping DHCP 11-10 16:14:57.580 D/WifiService( 94): ACTION_SCREEN_ON 11-10 16:14:57.670 I/Prefetcher( 59): [0xa990] cache below low water mark, filling cache. 11-10 16:14:57.700 D/AK8973 ( 64): Compass Start 11-10 16:14:57.800 I/AwesomePlayer( 59): prefetcher is done preparing 11-10 16:14:57.800 W/MogMediaPlayer.onPreparedListener( 2968): onPrepared, calling notifyPrepared() 11-10 16:39:03.608 I/AwesomePlayer( 59): calling prefetcher->prepare() 11-10 16:39:11.506 D/KeyguardViewMediator( 94): wakeWhenReadyLocked(26) 11-10 16:39:11.506 D/KeyguardViewMediator( 94): handleWakeWhenReady(26) 11-10 16:39:11.506 D/KeyguardViewMediator( 94): pokeWakelock(5000) 11-10 16:39:11.506 I/power ( 94): *** set_screen_state 1 11-10 16:39:11.566 D/SurfaceFlinger( 94): Screen about to return, flinger = 0x1fe300 11-10 16:39:11.586 D/WifiStateTracker( 94): Reset connections and stopping DHCP 11-10 16:39:11.586 D/WifiService( 94): ACTION_SCREEN_ON 11-10 16:39:11.716 D/AK8973 ( 64): Compass Start 11-10 16:39:11.766 I/Prefetcher( 59): [0x59ac18] cache below low water mark, filling cache. 11-10 16:39:11.856 I/AwesomePlayer( 59): prefetcher is done preparing 11-10 16:39:11.946 W/MogMediaPlayer.onPreparedListener( 2968): onPrepared, calling notifyPrepared() 

Does anyone know anything about this error or how to get around it?

Thanks in advance Ben

+7
android
source share
2 answers

I am experiencing something very similar to Android 2.3.3, 2.3.7 and 4.1.2. For me, after working for some time, MediaPlayer accidentally refuses to load. The difference is that for me the power button does not help - it does nothing, onPrepared simply never gets called. I play files from an SD card, not from the network, so buffering is not a problem. This happens more often when files are downloaded frequently, but as a rule, an error is often often enough to affect all my users.

Your problem seems to be related to mine, but unfortunately I also have no answer. I am posting it here to gather additional information about the problem. I tried using setDataSource, prepare, prepare Async, as well as the MediaPlayer.create () method, which immediately starts loading the specified file. I tried to reuse the same mediaplyer (using mp.reset ()), and also create a completely new one for each new download file (I stop and call release () on the previous player in advance), but nothing changes: if the user starts switch files faster (but nothing more - I would expect some kind of multimedia application to handle this), about 1 out of every 5 files will not indicate a failure or download.

+2
source share

Finally found a solution in another thread where someone had a problem with streaming audio from MediaPlayer here .

The trick is to wake the device before the next track is prepared via wakeLock. This does not cause the screen to light up, so do not worry. Describes how I finally made it here .

0
source share

All Articles