Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadMe Fix #5

Open
korvyr opened this issue May 14, 2018 · 2 comments
Open

ReadMe Fix #5

korvyr opened this issue May 14, 2018 · 2 comments

Comments

@korvyr
Copy link

korvyr commented May 14, 2018

Your readme is missing one vital piece in the example for using the ytdl package, which is to tell the voiceConnection that you have begun speaking.

e := voiceConnection.Speaking(true)
if e != nil {
   // handle error
}
@jogramming
Copy link
Owner

i guess that was kinda implied, since it's not showing connecting to voice either, but could add it

@korvyr
Copy link
Author

korvyr commented May 15, 2018

I suppose that's fair. I turned it all into something to this effect:

func ytPlay(v *discordgo.VoiceConnection, videoInfo *ytdl.VideoInfo) {
	defer v.Disconnect()
	defer v.Close()
	format := videoInfo.Formats.Extremes(ytdl.FormatAudioBitrateKey, true)[0]
	downloadURL, e := videoInfo.GetDownloadURL(format)
	if e != nil {
		rep(e)
		return
	}
	options := dca.StdEncodeOptions
	options.RawOutput = true
	options.Bitrate = 96
	options.Application = "lowdelay"
	encodingSession, e := dca.EncodeFile(downloadURL.String(), options)
	if e != nil {
		rep(e)
		return
	}
	defer encodingSession.Cleanup()
	e = v.Speaking(true)
	if e != nil {
		rep(e)
		return
	}
        defer v.Speaking(false)
	d := make(chan error)
	s := dca.NewStream(encodingSession, v, d)
	t := time.NewTicker(time.Second)
	for _ = range t.C {
		e := <-d
		if e != nil && e != io.EOF {
			rep(e)
			break
		}
		f, e := s.Finished()
		if e != nil {
			rep(e)
			break
		}
		if e == io.EOF || f {
			break
		}
	}
}

The ticker is completely unnecessary. I just used it for future expansion.

Also very much appreciate the package! Struggling with getting it to push to Discord, but I feel that's due to something I'm doing wrong. I'll figure it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants