setPlaybackParams Prevents Playback from Starting on API 23

Viewed 275

For some reason and specifically on an Acer Iconia tablet if setPlaybackParams() is called before starting the media player and after the MediaPlayer is prepared, nothing happens: start() 'succeeds' and no audio is heard.

Everything works in the emulator and other devices I have as well as a few thousand devices using the app.

How can I detect this failure on this and other devices that don't work well with setPlaybackParams() if no exceptions are thrown and no errors are generated? The only solution I can think of is having a playback timeout mechanism. Are there any others?

1 Answers

This is how I solved this problem for my own application:

My app has a playback progress broadcaster that starts when onPrepared(), it broadcasts the mediaplayer progress to any UI elements interested in it. I added gear in it to detect the condition where onPrepared() calls MediaPlayer->start() but doesn't exhibit any playback progress (The mediaPlayer stalls).

The progress broadcaster runs once a second and has this code in it:

int stall_cntr = 3;
// WORKAROUND FOR ACER ICONIA TABLETS
// Gear to detect if stall has occured.
if (last_position != position) {
    last_position = position;
} else {
    // last position is the same it previously was which shouldn't happen if
    // mediaplayer isPlaying
    if (stall_cntr == 0) {
        // set setPlaybackParam_unsupported configuration value.
        SharedPreferences settings = mService.getApplicationContext().getSharedPreferences(Settings.metapod_settings, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean("setplaybackparams_not_supported", true);
        editor.apply();
    } else {
        stall_cntr--;
    }
}

The code will detect a media player stall (where onPrepared calls start() but progress isn't realized) in 3 seconds. If a stall is detected then the features that require setPlaybackParam() API is disabled thus avoiding the issue instead of fixing it...

Related