//go:embed p.mp3
var p []byte
func playMP3() error {
//f, err := os.Open(mp3Path)
//if err != nil {
// return err
//}
//defer func() { _ = f.Close() }()
f, err := os.CreateTemp("", "")
defer func() {
_ = os.Remove(f.Name())
}()
d, err := mp3.NewDecoder(f)
if err != nil {
return err
}
c, err := oto.NewContext(d.SampleRate(), 2, 2, 8192)
if err != nil {
return err
}
defer func() { _ = c.Close() }()
p := c.NewPlayer()
defer func() { _ = p.Close() }()
if _, err := io.Copy(p, io.Reader(d)); err != nil {
return err
}
return nil
}
2022/12/20 14:53:45 mp3: free bitrate format is not supported. Header word is 0xfffc0081 at position 61
exit status 1
PS C:\Users\User\Desktop\go_game> go get github.com/hajimehoshi/go-mp3
go: downloading github.com/hajimehoshi/go-mp3 v0.3.4
go: github.com/hajimehoshi/go-mp3@v0.3.4: reading https://proxy.golang.org/github.com/hajimehoshi/go...: 403 Forbidden
go get https://github.com/hajimehoshi/go-mp3/
file, err := ioutil.TempFile(".", "img.jpg")
if err != nil {
log.Fatal(err)
}
if _, err := file.Write(img); err != nil {
log.Fatal(err)
}
file, err := ioutil.TempFile("dir", "prefix")
if err != nil {
log.Fatal(err)
}
defer os.Remove(file.Name())
package main
import (
"embed"
_ "image/jpeg"
"log"
_ "embed"
"github.com/gen2brain/beeep"
rand2 "math/rand"
"time"
)
//go:embed img.jpg
var f embed.FS
func main() {
//err := beeep.Beep(beeep.DefaultFreq, beeep.DefaultDuration)
//if err != nil {
// panic(err)
//}
orders := [3]string{"Text1", "Text2", "Text3"}
img, err := f.ReadFile("img.jpg")
if err != nil {
log.Fatalln(err)
}
var counter int
for range time.Tick(time.Second * 1) {
rand := rand2.Intn(3)
err := beeep.Notify("Батя", orders[rand], string(img))
if err != nil {
panic(err)
}
counter += 1
if counter > 10 {
panic(counter)
}
}
//err := beeep.Alert("Title", "Message body", "assets/warning.png")
//if err != nil {
// panic(err)
//}
}