示例#1
0
文件: audio.go 项目: mgalvey/piepan
func (p *Plugin) apiAudioSetTarget(call otto.FunctionCall) otto.Value {
	if len(call.ArgumentList) == 0 {
		p.instance.Client.VoiceTarget = nil
		return otto.TrueValue()
	}
	target, err := call.Argument(0).Export()
	if err != nil {
		return otto.UndefinedValue()
	}
	voiceTarget := target.(*gumble.VoiceTarget)
	p.instance.Client.Send(voiceTarget)
	p.instance.Client.VoiceTarget = voiceTarget
	return otto.TrueValue()
}
示例#2
0
文件: audio.go 项目: mgalvey/piepan
func (p *Plugin) apiAudioIsPlaying(call otto.FunctionCall) otto.Value {
	if p.instance.Audio.IsPlaying() {
		return otto.TrueValue()
	} else {
		return otto.FalseValue()
	}
}
示例#3
0
文件: audio.go 项目: mgalvey/piepan
func (p *Plugin) apiAudioPlay(call otto.FunctionCall) otto.Value {
	if p.instance.Audio.IsPlaying() {
		return otto.FalseValue()
	}
	obj := call.Argument(0).Object()
	if obj == nil {
		return otto.FalseValue()
	}

	filenameValue, _ := obj.Get("filename")
	callbackValue, _ := obj.Get("callback")

	if enc, ok := p.instance.Client.AudioEncoder.(*opus.Encoder); ok {
		enc.SetApplication(gopus.Audio)
	}

	p.instance.Audio.Source = gumble_ffmpeg.SourceFile(filenameValue.String())
	p.instance.Audio.Play()
	go func() {
		p.instance.Audio.Wait()
		if callbackValue.IsFunction() {
			p.callValue(callbackValue)
		}
	}()
	return otto.TrueValue()
}