Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Who knows the android mediaplayer states by their int value in LogCat?

I have an implementation that is using the Android MediaPlayer class. I keep on bumping into various bugs, change the code, bump into another bug. Depending on the bug, I get LogCat error messages reporting back from the MediaPlayer:

"xyz called in state x".

I don't want to post a thread for each bug I bump into, I rather get a hang of it all and fix the bugs myself. But I cannot find any document that would tell me which state number maps to which state, as they are described on the MediaPlayer online documentation.

Can someone post a link to such a list, or provide the list right here in this post? I think I would not be the only one that would appreciate that.

like image 232
AudioDroid Avatar asked Mar 13 '15 15:03

AudioDroid


People also ask

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.

What is media player in Android explain transition through the state machine?

Android is providing MediaPlayer class to access built-in mediaplayer services like playing audio,video e.t.c. In order to use MediaPlayer, we have to call a static Method create() of this class. This method returns an instance of MediaPlayer class. Its syntax is as follows − MediaPlayer mediaPlayer = MediaPlayer.


2 Answers

These are the states currently declared in mediaplayer.h on the master branch of the AOSP:

enum media_player_states {
    MEDIA_PLAYER_STATE_ERROR        = 0,
    MEDIA_PLAYER_IDLE               = 1 << 0,
    MEDIA_PLAYER_INITIALIZED        = 1 << 1,
    MEDIA_PLAYER_PREPARING          = 1 << 2,
    MEDIA_PLAYER_PREPARED           = 1 << 3,
    MEDIA_PLAYER_STARTED            = 1 << 4,
    MEDIA_PLAYER_PAUSED             = 1 << 5,
    MEDIA_PLAYER_STOPPED            = 1 << 6,
    MEDIA_PLAYER_PLAYBACK_COMPLETE  = 1 << 7
};
like image 109
Michael Avatar answered Feb 13 '23 08:02

Michael


Building on Michael's answer, here are the declared states with decimal values added for each of the shifted bits. Yeah, they're trivial to calculate, but this saves the extra step when resolving LogCat messages.

enum media_player_states {
    MEDIA_PLAYER_STATE_ERROR        = 0,        //   0
    MEDIA_PLAYER_IDLE               = 1 << 0,   //   1
    MEDIA_PLAYER_INITIALIZED        = 1 << 1,   //   2
    MEDIA_PLAYER_PREPARING          = 1 << 2,   //   4
    MEDIA_PLAYER_PREPARED           = 1 << 3,   //   8
    MEDIA_PLAYER_STARTED            = 1 << 4,   //  16
    MEDIA_PLAYER_PAUSED             = 1 << 5,   //  32
    MEDIA_PLAYER_STOPPED            = 1 << 6,   //  64
    MEDIA_PLAYER_PLAYBACK_COMPLETE  = 1 << 7    // 128
};
like image 41
scottt Avatar answered Feb 13 '23 07:02

scottt