Exemple #1
0
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()
}
Exemple #2
0
func (p *Plugin) apiAudioIsPlaying(call otto.FunctionCall) otto.Value {
	if p.instance.Audio.IsPlaying() {
		return otto.TrueValue()
	} else {
		return otto.FalseValue()
	}
}