Skip to content

Commit

Permalink
fix: error message when press N key continuously
Browse files Browse the repository at this point in the history
  • Loading branch information
tramhao committed May 21, 2021
1 parent e6aeb69 commit d6b1d07
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions playingbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ func (p *PlayingBar) newProgress(currentSong *player.AudioFile, full int) {
p.subtitle = nil
p.mu.RUnlock()
if p.albumPhoto != nil {
p.albumPhoto.Clear()
p.albumPhoto.Destroy()
p.albumPhoto = nil
}

err := p.loadLyrics(currentSong.Path())
Expand Down Expand Up @@ -304,7 +306,9 @@ func (p *PlayingBar) loadLyrics(currentSongPath string) error {
p.tag = tag

if p.albumPhoto != nil {
p.albumPhoto.Clear()
p.albumPhoto.Destroy()
p.albumPhoto = nil
}

syltFrames := tag.GetFrames(tag.CommonID("Synchronised lyrics/text"))
Expand Down Expand Up @@ -382,38 +386,41 @@ func (p *PlayingBar) setColRowPixel(colrowPixel int) {
func (p *PlayingBar) updatePhoto() {
// Put the whole block in goroutine, in order not to block the whole apps
// also to avoid data race by adding QueueUpdateDraw
// go gomu.app.QueueUpdateDraw(func() {
if p.albumPhotoSource == nil {
return
}
go gomu.app.QueueUpdateDraw(func() {
if p.albumPhotoSource == nil {
return
}

if p.albumPhoto != nil {
p.albumPhoto.Destroy()
}
if p.albumPhoto != nil {
p.albumPhoto.Clear()
// p.albumPhoto.Destroy()
ugo.Initialize()
p.albumPhoto = nil
}

// get related size
x, y, width, colPixel, rowPixel, err := p.getConsoleSize()
if err != nil {
logError(err)
return
}
// get related size
x, y, width, colPixel, rowPixel, err := p.getConsoleSize()
if err != nil {
logError(err)
return
}

imageWidth := width * colPixel / 3
imageWidth := width * colPixel / 3

// resize the photo according to space left for x and y axis
dstImage := imaging.Resize(p.albumPhotoSource, imageWidth, 0, imaging.Lanczos)
positionX := x*colPixel + width*colPixel - dstImage.Rect.Dx() - colPixel
positionY := y*rowPixel - rowPixel - dstImage.Rect.Dy()
// resize the photo according to space left for x and y axis
dstImage := imaging.Resize(p.albumPhotoSource, imageWidth, 0, imaging.Lanczos)
positionX := x*colPixel + width*colPixel - dstImage.Rect.Dx() - colPixel
positionY := y*rowPixel - rowPixel - dstImage.Rect.Dy()

// register new image
p.albumPhoto, err = ugo.NewImage(dstImage, positionX, positionY)
if err != nil {
logError(err)
return
}
p.albumPhoto.Show()
// register new image
p.albumPhoto, err = ugo.NewImage(dstImage, positionX, positionY)
if err != nil {
logError(err)
return
}
p.albumPhoto.Show()

// })
})
}

func (p *PlayingBar) getConsoleSize() (int, int, int, int, int, error) {
Expand Down

0 comments on commit d6b1d07

Please sign in to comment.