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

View File

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

View File

@ -17,9 +17,11 @@ func start(app *tview.Application) {
tview.Styles.PrimitiveBackgroundColor = tcell.ColorDefault tview.Styles.PrimitiveBackgroundColor = tcell.ColorDefault
tview.Styles.BorderColor = tcell.ColorAntiqueWhite tview.Styles.BorderColor = tcell.ColorAntiqueWhite
player := &Player{}
child3 := NowPlayingBar() child3 := NowPlayingBar()
child2 := Queue(child3) child2 := Queue(child3)
child1 := playlist(child2) child1 := Playlist(child2, player)
flex := Layout(app, child1, child2, child3) 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 return event