private static final int IDLE = 0; // 空闲状态
private static final int INIT = 3;// 初始化状态
private static final int PREPARING = 4;// 准备状态
private static final int PREPARED = 5;// 准备状态
private static final int STARTED = 6;// 开始状态
private static final int PAUSED = 7;// 暂停状态
private static final int STOPPED = 8;// 停止状态
private static final int END = 9; // 结束状态
private static final int ERROR = 10;// 错误状态
使用mPlayerStatus暂存播放器状态
@IntDef({IDLE,
ERROR,
INIT,
PREPARED,
STARTED,
PAUSED,
STOPPED,
public @interface STATUS {
MediaPlayer mMediaPlayer;
Context mContext;
@STATUS
int mPlayerStatus = IDLE;
初始化函数
初始化函数实例化播放器并注册基本播放所需要的回调函数
public AndroidMediaPlayer(Context context) {
mContext = context;
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setOnErrorListener(this);
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnPreparedListener(this);
mPlayerStatus = INIT;