46 lines
741 B
Go
46 lines
741 B
Go
package main
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"log"
|
|
|
|
"github.com/veandco/go-sdl2/sdl"
|
|
"github.com/veandco/go-sdl2/mix"
|
|
)
|
|
|
|
func main() {
|
|
if err := sdl.Init(sdl.INIT_AUDIO); err != nil {
|
|
log.Println(err)
|
|
return
|
|
}
|
|
defer sdl.Quit()
|
|
|
|
if err := mix.OpenAudio(44100, mix.DEFAULT_FORMAT, 2, 4096); err != nil {
|
|
log.Println(err)
|
|
return
|
|
}
|
|
defer mix.CloseAudio()
|
|
|
|
// Load entire WAV data from file
|
|
data, err := ioutil.ReadFile("../../assets/test.wav")
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
|
|
// Load WAV from data (memory)
|
|
chunk, err := mix.QuickLoadWAV(data)
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
defer chunk.Free()
|
|
|
|
// Play 4 times
|
|
chunk.Play(1, 3)
|
|
|
|
// Wait until it finishes playing
|
|
for mix.Playing(-1) == 1 {
|
|
sdl.Delay(16)
|
|
}
|
|
}
|
|
|