Basic audio player example
This commit is contained in:
parent
7a848839f4
commit
5df4b6ff8b
28
main.go
28
main.go
@ -1,8 +1,32 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "fyne.io/fyne/v2/app"
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fyne.io/fyne/v2/app"
|
||||||
|
"fyne.io/fyne/v2/widget"
|
||||||
|
"github.com/ebitengine/oto/v3"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var a = app.New()
|
var a = app.New()
|
||||||
a.NewWindow("Hello").ShowAndRun()
|
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()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user