Initial commit, lots of cleanup and stuff to do, it may not work.
This commit is contained in:
BIN
gumble/_examples/mumble-audio-player/chimes.ogg
Normal file
BIN
gumble/_examples/mumble-audio-player/chimes.ogg
Normal file
Binary file not shown.
53
gumble/_examples/mumble-audio-player/main.go
Normal file
53
gumble/_examples/mumble-audio-player/main.go
Normal file
@ -0,0 +1,53 @@
|
||||
package main // import "git.2mb.codes/~cmb/barnard/gumble/_examples/mumble-audio-player"
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"git.2mb.codes/~cmb/barnard/gumble/gumble"
|
||||
"git.2mb.codes/~cmb/barnard/gumble/gumbleffmpeg"
|
||||
"git.2mb.codes/~cmb/barnard/gumble/gumbleutil"
|
||||
_ "git.2mb.codes/~cmb/barnard/gumble/opus"
|
||||
)
|
||||
|
||||
func main() {
|
||||
files := make(map[string]string)
|
||||
var stream *gumbleffmpeg.Stream
|
||||
|
||||
flag.Usage = func() {
|
||||
fmt.Fprintf(os.Stderr, "Usage of %s: [flags] [audio files...]\n", os.Args[0])
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
|
||||
gumbleutil.Main(gumbleutil.AutoBitrate, gumbleutil.Listener{
|
||||
Connect: func(e *gumble.ConnectEvent) {
|
||||
for _, file := range flag.Args() {
|
||||
key := filepath.Base(file)
|
||||
files[key] = file
|
||||
}
|
||||
|
||||
fmt.Printf("audio player loaded! (%d files)\n", len(files))
|
||||
},
|
||||
|
||||
TextMessage: func(e *gumble.TextMessageEvent) {
|
||||
if e.Sender == nil {
|
||||
return
|
||||
}
|
||||
file, ok := files[e.Message]
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if stream != nil && stream.State() == gumbleffmpeg.StatePlaying {
|
||||
return
|
||||
}
|
||||
stream = gumbleffmpeg.New(e.Client, gumbleffmpeg.SourceFile(file))
|
||||
if err := stream.Play(); err != nil {
|
||||
fmt.Printf("%s\n", err)
|
||||
} else {
|
||||
fmt.Printf("Playing %s\n", file)
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user