package com.yidianling.course.router

import android.app.Activity
import android.content.Intent
import com.alibaba.android.arouter.launcher.ARouter
import com.ydl.media.audio.AudioPlayer
import com.yidianling.course.courseNew.CourseTopicActivity
import com.yidianling.router.course.ICourseRouter

/**
 * Created by hgw on 2018/5/3.
 */
class CourseRouterImp : ICourseRouter{

    override fun closePlayer() {
        if (AudioPlayer.get().isPlaying) {
            AudioPlayer.get().stopPlayer()
        }
    }

    override fun isPlaying(): Boolean {
        return AudioPlayer.get().isPlaying
    }

    override fun play(){
        AudioPlayer.get().play()
    }

    override fun pause(){
        AudioPlayer.get().playPause()
    }

    override fun startCoursePlayPage(activity: Activity, from: Int) {
        ARouter.getInstance()
            .build("/course/play")
            .withInt("from", from)
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            .withBoolean("isFromFloatView", false)
            .navigation()
    }

    override fun courseTopic(activity: Activity, id: String){
        return CourseTopicActivity.start(activity, id)
    }
}