package com.yidianling.muse.activity

import com.alibaba.android.arouter.facade.annotation.Route
import com.ydl.media.audio.AudioPlayer
import com.ydl.ydl_flutter.flutter.base.BaseFlutterActivity
import com.ydl.ydlcommon.router.IYDLRouterConstant
import com.yidianling.muse.handler.MusePlugin
import org.json.JSONObject


/**
 * Created by xj on 2019/9/6.
 */

@Route(path = "/module/muse")
class MuseActivity : BaseFlutterActivity() {
    override fun initialRoute(): String {
        return "native/muse/home"
    }

    override fun initChannelPlugin(jsonObject: JSONObject) {

        MusePlugin.rigister(this, jsonObject.getString(IYDLRouterConstant.MUSIC_URL), jsonObject.getString(IYDLRouterConstant.DATA_JSON))

        /**
         * 如果正在播放音乐，则停止播放所有音乐
         */
        if (AudioPlayer.get().isPlaying) {
            AudioPlayer.get().stopPlayer()
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        /**
         * 退出冥想模块的时候，关闭音乐播放
         */
        AudioPlayer.get().stopPlayer()
    }
}
