-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/mobile: gomobile fails with big error (go1.20) #61656
Labels
mobile
Android, iOS, and x/mobile
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Comments
Go Code package main
import (
"embed"
"encoding/json"
"log"
"time"
fyne "fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/faiface/beep"
"github.com/faiface/beep/effects"
"github.com/faiface/beep/mp3"
"github.com/faiface/beep/speaker"
)
type AudioData struct {
Filename string `json:"filename"`
Desc string `json:"desc"`
IconName string `json:"icon"`
}
var AudioDataMain []AudioData
var jsonfile string = `[
{"filename":"tiger.mp3","desc":"Tiger","icon":"tico.png"},
{"filename":"monkey.mp3","desc":"Monkey","icon":"monkey.png"},
{"filename":"elephant.mp3","desc":"Elephant","icon":"elephant.jpeg"},
{"filename":"otter.mp3","desc":"Otter","icon":"otter.jpeg"}
]`
//go:embed audiofiles/*
var audiofiles embed.FS
var asnimalApp = app.New()
var mainWin = asnimalApp.NewWindow("Aminal Sound")
var playBtn = make(map[string]*widget.Button)
var playerMap = make(map[string]*audioPanel)
var IsPlaying = make(map[string]bool)
func init() {
err := json.Unmarshal([]byte(jsonfile), &AudioDataMain)
if err != nil {
log.Fatalln("unable to unmarshal json " + err.Error())
}
}
func main() {
mainWin.Resize(fyne.Size{Width: 400, Height: 400})
tabitemHome := container.NewTabItemWithIcon("", theme.HomeIcon(), setPage())
tab := container.NewAppTabs(tabitemHome)
tab.SetTabLocation(container.TabLocationBottom)
content := container.NewBorder(nil, nil, nil, nil, tab)
mainWin.SetContent(content)
mainWin.Show()
asnimalApp.Run()
asnimalApp.Quit()
}
func playFile(fileName string) {
log.Println("Play")
speaker.Lock()
for f, rec := range playerMap {
log.Println("in range player map", rec, f)
playerMap[f].ctrl.Paused = !rec.ctrl.Paused
playBtn[f].SetIcon(theme.MediaPlayIcon())
IsPlaying[f] = false
}
playBtn[fileName].SetIcon(theme.MediaPauseIcon())
IsPlaying[fileName] = true
speaker.Unlock()
err := createPlayerMap(fileName)
if err != nil {
log.Fatalln("error" + err.Error())
}
playerMap[fileName].play()
}
func pauseFile(fileName string) {
log.Println("pause")
IsPlaying[fileName] = false
playBtn[fileName].SetIcon(theme.MediaPlayIcon())
speaker.Lock()
playerMap[fileName].ctrl.Paused = !playerMap[fileName].ctrl.Paused
speaker.Unlock()
}
type audioPanel struct {
sampleRate beep.SampleRate
streamer beep.StreamSeeker
ctrl *beep.Ctrl
resampler *beep.Resampler
volume *effects.Volume
}
func newAudioPanel(sampleRate beep.SampleRate, streamer beep.StreamSeeker) *audioPanel {
ctrl := &beep.Ctrl{Streamer: beep.Loop(-1, streamer)}
resampler := beep.ResampleRatio(4, 1, ctrl)
volume := &effects.Volume{Streamer: resampler, Base: 2}
return &audioPanel{sampleRate, streamer, ctrl, resampler, volume}
}
func (ap *audioPanel) play() {
speaker.Play(ap.volume)
}
func loadResource(rname string) (r fyne.Resource) {
fs, err := audiofiles.ReadFile("audiofiles/icon/" + rname)
if err != nil {
log.Fatalln("error" + err.Error())
}
r = fyne.NewStaticResource(rname, fs)
return
}
func setPage() (page fyne.CanvasObject) {
//////////////////////////
page1 := widget.NewList(
func() int {
return len(AudioDataMain)
},
func() fyne.CanvasObject {
return container.New(layout.NewGridLayout(2), widget.NewButtonWithIcon("Go", theme.MediaPlayIcon(), nil),
widget.NewCard("title", "subtitle ", nil))
},
func(i widget.ListItemID, item fyne.CanvasObject) {
item.(*fyne.Container).Objects[0].(*widget.Button).SetText(AudioDataMain[i].Desc)
//item.(*fyne.Container).Objects[0].(*widget.Button).SetIcon(loadResource(AudioDataMain[i].IconName))
item.(*fyne.Container).Objects[0].(*widget.Button).OnTapped = func() {
log.Println(AudioDataMain[i].Filename)
playBtn[AudioDataMain[i].Filename] = item.(*fyne.Container).Objects[0].(*widget.Button)
if !IsPlaying[AudioDataMain[i].Filename] {
//playFile(AudioDataMain[i].Filename, item.(*fyne.Container).Objects[0].(*widget.Button))
playFile(AudioDataMain[i].Filename)
} else {
pauseFile(AudioDataMain[i].Filename)
}
}
item.(*fyne.Container).Objects[1].(*widget.Card).SetImage(canvas.NewImageFromResource(loadResource(AudioDataMain[i].IconName)))
})
page = page1
return
}
func createPlayerMap(Filename string) (err error) {
log.Println("createPlayerMap called ")
//for _, rec := range AudioDataMain {
file, err := audiofiles.Open("audiofiles/" + Filename)
if err != nil {
log.Fatalln("reading fs error" + err.Error())
return err
}
streamer, format, err := mp3.Decode(file)
if err != nil {
log.Fatalln(" mp3.Decode", err)
return err
}
speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/30))
ap := newAudioPanel(format.SampleRate, streamer)
playerMap[Filename] = ap
//}
//ap.play()
return
} go.mod
go.sum
|
seankhliao
changed the title
affected/package: gomobile fails with big error (go1.20)
x/mobile: gomobile fails with big error (go1.20)
Jul 30, 2023
I was expecting a prompt response! |
dr2chase
added
the
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
label
Aug 4, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
mobile
Android, iOS, and x/mobile
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
The text was updated successfully, but these errors were encountered: