package com.dlc.eboard.iflytek

import android.content.Context
import android.media.MediaPlayer

/**
 * info
 *
 * @author ReiChin_
 */
object AudioPlayerManager {

    private var mAppContext: Context? = null
    private var mMediaPlayer: MediaPlayer? = null

    fun init(context: Context) {
        mAppContext = context
    }

    fun release() {
        mAppContext = null
        mMediaPlayer?.release()
    }

    fun speakVoice(resId: Int, listener: MediaPlayer.OnCompletionListener? = null) {
        mMediaPlayer?.release()

        mMediaPlayer = mAppContext?.let {
            MediaPlayer.create(it, resId)
        }
        mMediaPlayer?.setOnCompletionListener(listener)
        mMediaPlayer?.start()
    }

}