implement sound play

This commit is contained in:
raziman 2020-06-21 00:00:17 +08:00
parent 56318c2ec7
commit 8c41ff87e2
3 changed files with 19 additions and 3 deletions

View File

@ -15,7 +15,7 @@ type AudioFile struct {
Parent *tview.TreeNode
}
func playlist(list *tview.List) *tview.TreeView {
func Playlist(list *tview.List, player *Player) *tview.TreeView {
musicDir := "./music"
@ -69,10 +69,14 @@ func playlist(list *tview.List) *tview.TreeView {
case 'l':
if audioFile.IsAudioFile {
list.AddItem(audioFile.Name, audioFile.Path, 0, nil)
player.Push(audioFile.Path)
if !player.IsRunning {
go player.Run()
}
}
currNode.SetExpanded(true)
case 'h':

View File

@ -37,6 +37,8 @@ func Queue(playlist *tview.Box) *tview.List {
return nil
})
list.SetHighlightFullLine(true)
list.SetBorder(true).SetTitle("Queue")
list.SetSelectedBackgroundColor(tcell.ColorDarkCyan)

View File

@ -17,9 +17,11 @@ func start(app *tview.Application) {
tview.Styles.PrimitiveBackgroundColor = tcell.ColorDefault
tview.Styles.BorderColor = tcell.ColorAntiqueWhite
player := &Player{}
child3 := NowPlayingBar()
child2 := Queue(child3)
child1 := playlist(child2)
child1 := Playlist(child2, player)
flex := Layout(app, child1, child2, child3)
@ -49,6 +51,14 @@ func start(app *tview.Application) {
})
case ' ':
if player.ctrl.Paused {
player.Play()
} else {
player.Pause()
}
}
return event