33 lines
678 B
Go
33 lines
678 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"fyne.io/fyne/v2/app"
|
|
"fyne.io/fyne/v2/widget"
|
|
"github.com/ebitengine/oto/v3"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
var a = app.New()
|
|
var btn = widget.NewButton("Play", func() {
|
|
var b, _ = os.ReadFile("sample.wav")
|
|
// create reader from bytes
|
|
var reader = bytes.NewReader(b)
|
|
var ctxOptions = oto.NewContextOptions{
|
|
SampleRate: 44100,
|
|
ChannelCount: 2,
|
|
Format: oto.FormatSignedInt16LE,
|
|
BufferSize: 0,
|
|
}
|
|
var ctx, ready, _ = oto.NewContext(&ctxOptions)
|
|
<-ready // Wait for the context to be ready
|
|
var player = ctx.NewPlayer(reader)
|
|
player.Play()
|
|
},
|
|
)
|
|
var w = a.NewWindow("Hello")
|
|
w.SetContent(btn)
|
|
w.ShowAndRun()
|
|
}
|