jogramming / dca

Go implementation for the DCA audio format
BSD 3-Clause "New" or "Revised" License
75 stars 60 forks source link

Stopping music example running in go routine? #4

Closed simvux closed 6 years ago

simvux commented 6 years ago

Using this example:

options := dca.StdEncodeOptions
options.RawOutput = true
options.Bitrate = 96
options.Application = "lowdelay"

videoInfo, err := ytdl.GetVideoInfo(videoURL)
if err != nil {
    // Handle the error
}

format := videoInfo.Formats.Extremes(ytdl.FormatAudioBitrateKey, true)[0]
downloadURL, err := videoInfo.GetDownloadURL(format)
if err != nil {
    // Handle the error
}

encodingSession, err := dca.EncodeFile(downloadURL.String(), options)
if err != nil {
    // Handle the error
}
defer encodingSession.Cleanup()

done := make(chan error)    
dca.NewStream(encodingSession, voiceConnection, done)
err := <- done
if err != nil && err != io.EOF {
    // Handle the error
}

how would i stop the music from playing? Can i use the done channel created by the stream? I'm using that code in a go routine and need to stop it from another go routine.

jogramming commented 6 years ago

you can call stop on the underlying encoding session, or you can pause the stream.