music player can list playlist and library files

This commit is contained in:
cuu 2023-01-19 15:46:54 +00:00
parent 2d18c23e89
commit e59d572610
2 changed files with 98 additions and 11 deletions

View File

@ -1,7 +1,7 @@
package MusicPlayer
import (
//"fmt"
"fmt"
"log"
"path/filepath"
@ -224,9 +224,7 @@ func (self *MusicLibListPage) Click() {
conn := self.Parent.MpdClient
conn.Add(cur_li.Path)
self.Parent.SyncList()
//addfile(cur_li.Path)
//PlayListPage.SyncList()
//print("add" , cur_li._Path)
fmt.Println("add" , cur_li.Path)
}
@ -237,13 +235,12 @@ func (self *MusicLibListPage) Click() {
func (self *MusicLibListPage) KeyDown(ev *event.Event) {
if ev.Data["Key"] == UI.CurKeys["Left"] || ev.Data["Key"] == UI.CurKeys["Menu"] {
if UI.IsKeyMenuOrB(ev.Data["Key"]) || ev.Data["Key"] == UI.CurKeys["Left"] {
self.ReturnToUpLevelPage()
self.Screen.Draw()
self.Screen.SwapAndShow()
}
if ev.Data["Key"] == UI.CurKeys["Up"] {
self.ScrollUp()
@ -258,6 +255,9 @@ func (self *MusicLibListPage) KeyDown(ev *event.Event) {
self.Screen.SwapAndShow()
}
if UI.IsKeyStartOrA(ev.Data["Key"]) {
self.Click()
}
return
}
@ -285,6 +285,9 @@ func (self *MusicLibListPage) Draw() {
v.Draw()
}
self.Scroller.UpdateSize( len(self.MyList)*UI.DefaultInfoPageListItemHeight, self.PsIndex*UI.DefaultInfoPageListItemHeight)
self.Scroller.Draw()
} else{
self.Ps.(*ListPageSelector).Width = self.Width
self.Ps.Draw()

View File

@ -4,6 +4,8 @@ import (
"fmt"
"path/filepath"
"log"
"strconv"
"strings"
"github.com/cuu/gogame/event"
"github.com/cuu/gogame/rect"
"github.com/cuu/gogame/surface"
@ -36,6 +38,9 @@ type MusicPlayerPage struct {
Scrolled int
MpdClient *mpd.Client
CurSongTime string
CurSongName string
}
func NewMusicPlayerPage() *MusicPlayerPage {
@ -60,6 +65,8 @@ func NewMusicPlayerPage() *MusicPlayerPage {
p.BGwidth = 56
p.BGheight = 70
p.CurSongTime = "0:0"
return p
}
@ -76,6 +83,8 @@ func (self *MusicPlayerPage) OnLoadCb() {
fmt.Println("Start mpd client")
}
self.SyncList()
}
func (self *MusicPlayerPage) OnPopUpCb() {
@ -86,6 +95,10 @@ func (self *MusicPlayerPage) OnPopUpCb() {
}
}
func (self *MusicPlayerPage) OnReturnBackCb() {
self.SyncList()
}
func (self *MusicPlayerPage) SetCoords() {
}
@ -146,7 +159,29 @@ func (self *MusicPlayerPage) SyncPlaying() {
}
current_song,_ := conn.CurrentSong()
if len(current_song) > 0 {
if val,ok := current_song["song"]; ok{
posid, _ := strconv.Atoi(val)
if posid < len(self.MyList) {
if state,ok2 := current_song["state"]; ok2 {
if state == "stop" {
self.MyList[posid].(*MusicPlayPageListItem).Active = false
}else{
self.MyList[posid].(*MusicPlayPageListItem).Active = true
}
}
if song_time,ok3 := current_song["time"]; ok3 {
self.CurSongTime = song_time
times := strings.Split(self.CurSongTime,":")
if len(times) > 1{
cur,_ := strconv.ParseFloat(times[0],64)
end,_ := strconv.ParseFloat(times[1],64)
pos := int( (cur/end)*100.0 )
self.MyList[posid].(*MusicPlayPageListItem).PlayingProcess = pos
}
}
}
}
}
}
@ -164,12 +199,12 @@ func (self *MusicPlayerPage) Init() {
self.Width = self.Screen.Width
self.Height = self.Screen.Height
ps := UI.NewInfoPageSelector()
ps.Width = UI.Width - 12
ps.PosX = 2
//ps := UI.NewInfoPageSelector()
ps := NewListPageSelector()
//ps.Width = UI.Width - 12
ps.Parent = self
self.Ps = ps
self.PsIndex = 0
bgpng := UI.NewIconItem()
@ -218,6 +253,21 @@ func (self *MusicPlayerPage) KeyDown(ev *event.Event) {
self.Screen.Draw()
self.Screen.SwapAndShow()
}
if ev.Data["Key"] == UI.CurKeys["Up"] {
self.ScrollUp()
self.Screen.Draw()
self.Screen.SwapAndShow()
}
if ev.Data["Key"] == UI.CurKeys["Down"] {
self.ScrollDown()
self.Screen.Draw()
self.Screen.SwapAndShow()
}
return
}
@ -227,7 +277,41 @@ func (self *MusicPlayerPage) Draw() {
if len(self.MyList) == 0 {
self.Icons["bg"].NewCoord(self.Width/2, self.Height/2)
self.Icons["bg"].Draw()
}
}else {
if len(self.MyList)*UI.DefaultInfoPageListItemHeight > self.Height {
self.Ps.(*ListPageSelector).Width = self.Width - 11
self.Ps.Draw()
for _, v := range self.MyList {
if v.(*MusicPlayPageListItem).PosY > self.Height+self.Height/2 {
break
}
if v.(*MusicPlayPageListItem).PosY < 0 {
continue
}
v.Draw()
}
self.Scroller.UpdateSize( len(self.MyList)*UI.DefaultInfoPageListItemHeight, self.PsIndex*UI.DefaultInfoPageListItemHeight)
self.Scroller.Draw()
} else{
self.Ps.(*ListPageSelector).Width = self.Width
self.Ps.Draw()
for _, v := range self.MyList {
if v.(*MusicPlayPageListItem).PosY > self.Height+self.Height/2 {
break
}
if v.(*MusicPlayPageListItem).PosY < 0 {
continue
}
v.Draw()
}
}
}
if self.HWND != nil {
surface.Fill(self.HWND, UI.MySkinManager.GiveColor("White"))