diff --git a/playingbar.go b/playingbar.go index d268b9c7..aa51b6d2 100644 --- a/playingbar.go +++ b/playingbar.go @@ -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()) @@ -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")) @@ -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) {