package player

/*
#include <uvdbus/smart_sound.h>
*/
import "C"
import (
	. "netease_control_center/globals"
	"netease_control_center/interfaces/log"
	. "netease_control_center/interfaces/schedule"
)

func ChangeAirPlayOnLineSt(isOnline bool) {
	airPlayIsOnline = isOnline

	if !isOnline {
		ClearProjectorVolProcess()
		AirplayPlayStateSet(false)
		MonitorAirplayPlayerBroadcast(MUSIC_ST_IDLE)
		PlayerHander[PlayerType_Airplay].ReportOffline()
	} else {
		log.Println(log.DebugLog, "airplay trig request play")

		//AirPlayPauseDoneSet(false)
		//AirPlayPlayDoneSet(true)
		AirplayPlayStateSet(true)
		if PlayerHander[PlayerType_Airplay].RequestPlay_Sync(nil) {
			MonitorAirplayPlayerBroadcast(MUSIC_ST_PLAYING)
			BtDiscon() //add by lupeng 20180824 #PV1-4011
		} else {
			ctrlAirPlayCmdToPhone(SPLAYER_ACTION_PAUSE)
			log.Println(log.WarningLog, "airplay request play err")
		}
	}

}

func AirPlayPause2() {
	if !airplayPlayState {
		log.Println(log.DebugLog, "airplay pause to phone has done.")
	} else {
		AirplayPlayStateSet(false)
		ctrlAirPlayCmdToPhone(SPLAYER_ACTION_PAUSE)
	}

	MonitorAirplayPlayerBroadcast(MUSIC_ST_PAUSED)
}

func AirPlayPauseForIgnoreCmd2() {
	ctrlAirPlayCmdToPhone(SPLAYER_ACTION_PAUSE)

	MonitorAirplayPlayerBroadcast(MUSIC_ST_PAUSED)
}

func AirPlayPlay2(start int, arg SCmd_Args) bool {
	if airplayPlayState {
		log.Println(log.DebugLog, "airplay play to phone has done.")
	} else {
		AirplayPlayStateSet(true)
		ctrlAirPlayCmdToPhone(SPLAYER_ACIION_PLAY)
	}

	MonitorAirplayPlayerBroadcast(MUSIC_ST_PLAYING)

	return true
}

func AirPlayStop2() {
	AirplayPlayStateSet(false)
	ctrlAirPlayCmdToPhone(SPLAYER_ACTION_PAUSE)
	MonitorAirplayPlayerBroadcast(MUSIC_ST_IDLE)
}

func AirPlaySeek2(pos uint32) {
	// nil
}

func AirPlayIsOnline2() bool {
	//
	return airPlayIsOnline
}

func AirPlayIfForcePause2() bool {

	return false
}

func AirPlayPlayNext2(arg interface{}) {
	AirplayPlayStateSet(true)
	ctrlAirPlayCmdToPhone(SPLAYER_ACTION_NEXT)
	MonitorAirplayPlayerBroadcast(MUSIC_ST_PLAYING)
}

func AirPlayPlayPre2(arg interface{}) {
	AirplayPlayStateSet(true)
	ctrlAirPlayCmdToPhone(SPLAYER_ACTION_PRE)
	MonitorAirplayPlayerBroadcast(MUSIC_ST_PLAYING)
}

func AirPlayPrepareNext2() {
	// nil
}

func AirPlayGetSUpportedSCmd2() []SCMD {

	return nil
}

func AirPlayGetPlayerName2() string {
	return AIRPLAY_PLAYER_NAME
}

func AirPlayChange2(in bool) {
	if !in {
		ClearProjectorVolProcess()
		//AirplayDisCon()
		log.Println(log.WarningLog, "Dis Airplay by vbox")
	}
}
