show photo of embeded

This commit is contained in:
tramhao 2021-04-08 15:14:37 +08:00
parent 904c89562e
commit 34ec606f81
3 changed files with 28 additions and 24 deletions

1
go.mod
View File

@ -8,6 +8,7 @@ require (
github.com/antchfx/xmlquery v1.3.4 // indirect
github.com/bogem/id3v2 v1.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/disintegration/imaging v1.6.2
github.com/faiface/beep v1.0.2
github.com/gdamore/tcell/v2 v2.2.0
github.com/gobwas/glob v0.2.3 // indirect

3
go.sum
View File

@ -23,6 +23,8 @@ github.com/bogem/id3v2 v1.2.0/go.mod h1:t78PK5AQ56Q47kizpYiV6gtjj3jfxlz87oFpty8D
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c=
github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4=
github.com/faiface/beep v1.0.2 h1:UB5DiRNmA4erfUYnHbgU4UB6DlBOrsdEFRtcc8sCkdQ=
github.com/faiface/beep v1.0.2/go.mod h1:1yLb5yRdHMsovYYWVqYLioXkVuziCSITW1oarTeduQM=
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
@ -115,6 +117,7 @@ golang.org/x/exp v0.0.0-20201229011636-eab1b5eb1a03/go.mod h1:I6l2HNBLBZEcrOoCpy
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20201208152932-35266b937fa6 h1:nfeHNc1nAqecKCy2FCy4HY+soOOe5sDLJ/gZLbx6GYI=
golang.org/x/image v0.0.0-20201208152932-35266b937fa6/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/mobile v0.0.0-20180806140643-507816974b79/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=

View File

@ -3,17 +3,16 @@
package main
import (
"bytes"
"errors"
"fmt"
"image"
"io/ioutil"
"log"
"os"
"strconv"
"strings"
"sync/atomic"
"time"
"github.com/disintegration/imaging"
"github.com/rivo/tview"
"github.com/tramhao/id3v2"
"github.com/ztrue/tracerr"
@ -34,7 +33,7 @@ type PlayingBar struct {
tag *id3v2.Tag
subtitle *lyric.Lyric
subtitles []*lyric.Lyric
albumPhoto []byte
albumPhoto *ugo.Image
}
func (p *PlayingBar) help() []string {
@ -145,19 +144,6 @@ func (p *PlayingBar) setSongTitle(title string) {
p.Clear()
titleColor := gomu.colors.title
p.AddText(title, true, tview.AlignCenter, titleColor)
reader, err := os.Open("/home/tramhao/.local/src/gomu/1.jpg")
if err != nil {
log.Fatal(err)
}
defer reader.Close()
img1, _, _ := image.Decode(reader)
_, err = ugo.NewImage(img1, 0, 0)
if err != nil {
log.Fatal(err)
}
// defer i.Clear()
// defer i.Destroy()
}
@ -165,11 +151,16 @@ func (p *PlayingBar) setSongTitle(title string) {
func (p *PlayingBar) newProgress(currentSong *AudioFile, full int) {
p.setFull(full)
p.setProgress(0)
p.setSongTitle(currentSong.name)
p.hasTag = false
p.tag = nil
p.subtitles = nil
p.subtitle = nil
if p.albumPhoto != nil {
p.albumPhoto.Clear()
p.albumPhoto.Destroy()
ugo.Close()
}
p.albumPhoto = nil
err := p.loadLyrics(currentSong.path)
if err != nil {
@ -204,6 +195,8 @@ func (p *PlayingBar) newProgress(currentSong *AudioFile, full int) {
p.subtitle = p.subtitles[0]
}
}
p.setSongTitle(currentSong.name)
}
// Sets default title and progress bar
@ -334,14 +327,21 @@ func (p *PlayingBar) loadLyrics(currentSongPath string) error {
}
// Do something with picture frame.
fmt.Println(pic.Description)
p.albumPhoto = pic.Picture
img1, err := imaging.Decode(bytes.NewReader(pic.Picture))
if err != nil {
return tracerr.Wrap(err)
}
dstImage128 := imaging.Fit(img1, 128, 128, imaging.Lanczos)
go gomu.app.QueueUpdateDraw(func() {
x, y, _, _ := p.GetInnerRect()
_, err := ugo.NewImage(dstImage128, x*16, y*31)
if err != nil {
log.Fatal(err)
}
})
}
err = ioutil.WriteFile("/home/tramhao/.local/src/gomu/1.jpg", p.albumPhoto, 0644)
if err != nil {
return tracerr.Wrap(err)
}
return nil
}