Comments (2)
func Play(session *discordgo.Session, guildID, voiceChannelID, mediaURL string) error {
VoiceConnection, err := session.ChannelVoiceJoin(guildID, voiceChannelID, false, false)
if err != nil {
fmt.Println(err)
return err
}
defer VoiceConnection.Disconnect()
encodingSession, err := dca.EncodeFile(mediaURL, encodeOptionsPresetHigh)
if err != nil {
fmt.Println(err)
return err
}
defer encodingSession.Cleanup()
VoiceConnection.Speaking(true)
//Create channel for done signal
Channels[guildID] = make(chan error)
streamingSession := dca.NewStream(encodingSession, VoiceConnection, Channels[guildID])
//Wait for stream to finish
err = <-Channels[guildID]
if err != nil {
return err
}
VoiceConnection.Speaking(false)
_, err = streamingSession.Finished()
if err != nil {
fmt.Println(err)
}
encodingSession.Stop()
encodingSession.Cleanup()
if err != nil || err != ErrorStoppedManually {
fmt.Println(err)
return err
}
return nil
}
This is my play function by the way. "mediaURL" is the formatted url that's given by ytdl.
from dca.
Alright turns out this method just didn't want to work for me.
I'm going to close this issue now, but I shall show what can be done to remedy this!
Since I have a function where I get metadata about a youtube video through ytdl for ease of access your code may differ. If your code is built similarly to mine, with the exception of having to get a streamURL through format (Example in the ReadMe), you'll want to do these steps:
First: add "net/http" to your imports.
Second: define a function that gets the formatted url.
videoInfo, err := ytdl.GetVideoInfo(url)
if err != nil {
return nil, err
}
format := videoInfo.Formats.Extremes(ytdl.FormatAudioBitrateKey, true)[0]
videoURL, err := videoInfo.GetDownloadURL(format)
if err != nil {
return nil, err
}
resp, err := http.Get(videoURL.String())
if err != nil {
return nil, err
}
Third: define a body from resp
body := resp.Body
Fourth: Replace the encodingSession with something like this:
encodingSession, err := dca.EncodeMem(body, dca.StdEncodeOptions)
if err != nil {
return err
}
This worked for me, and I hope anyone who sees this may find this method to work aswell!
Huge credit to the people on the Discord Gophers discord server for sharing the knowledge.
Especially: diamondburned#4507
from dca.
Related Issues (18)
- [Request] Changing volume mid-stream HOT 1
- Sound plays 2x as fast if set 40 as FrameDuration HOT 2
- ffmpeg not reconnect when youtube URL is expired HOT 1
- Option reconnect not found HOT 4
- [Feature Request] Change Volume Mid-stream HOT 2
- How to Install and use
- Sometime, EOF signal send before the stream end HOT 4
- Link to DCA1 specification page does not work
- Error parsing ffmpeg stats: strconv.ParseFloat: parsing "N": invalid syntax HOT 6
- ffmpeg Option reconnect not found. HOT 2
- Returning "EOF" error in the beginning of the file. HOT 1
- Encoding not working because of volume argument on FFmpeg command HOT 1
- Output becomes an empty file HOT 4
- Stopping music example running in go routine? HOT 1
- ReadMe Fix HOT 2
- [Request] Filtering Mid-Stream HOT 7
- Youtube Stream EOFs in the middle of stream HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dca.