fixed resizing not working

This commit is contained in:
eyjhb 2025-02-08 21:13:09 +01:00
parent 2e3e74e128
commit cb1839a5bc
Signed by: eyjhb
GPG key ID: 609F508E3239F920
4 changed files with 107 additions and 102 deletions

View file

@ -27,7 +27,8 @@ type playerModel struct {
// TODO: make this smarter
// finished entries to send messages about
finishedEntries []int64
currentlyPlaying *feedEntry
playQueue []feedEntry
mpv *MPVPLayer
@ -44,25 +45,33 @@ func (m *playerModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case MsgPlayEntry:
f := feedEntry(msg)
go m.mpv.Queue(f)
m.queue(f)
}
// send message because it is finished
fe := m.mpv.FinishedPlaying()
if len(fe) > 0 {
var cmds []tea.Cmd
for _, e := range fe {
cmds = append(cmds, func() tea.Msg { return MsgWatchedEntry(e.ID) })
// we have a currentlyPlaying entry, but it is no longer playing
// which means we finished watching it
var cmds []tea.Cmd
if m.currentlyPlaying != nil && m.mpv.IsPlaying() == false {
if videoPercentageWatched(m.mpv.VideoPosition(), m.mpv.VideoDuration()) > 90 {
t := m.currentlyPlaying.ID
cmds = append(cmds, func() tea.Msg { return MsgWatchedEntry(t) })
}
// unset currentlyPlaying
m.currentlyPlaying = nil
if err := m.playNext(); err != nil {
cmds = append(cmds, func() tea.Msg { return MsgError(err) })
}
return m, tea.Batch(cmds...)
}
return m, nil
return m, tea.Batch(cmds...)
}
func (m *playerModel) View() string {
// return "NO DONT ASK"
// return fmt.Sprintf("IsPlaying: %v", m.mpv.IsPlaying())
return fmt.Sprintf("IsPlaying: %v, Pos: %v, Dur: %v, Per: %v", m.mpv.IsPlaying(), m.mpv.VideoPosition(), m.mpv.VideoDuration(), videoPercentageWatched(m.mpv.VideoPosition(), m.mpv.VideoDuration()))
if m.mpv.IsPlaying() {
timePos := time.Time{}.Add(m.mpv.VideoPosition())
@ -70,7 +79,7 @@ func (m *playerModel) View() string {
// truncate name if needed
// name := m.entry.Name
name := m.mpv.CurrentlyPlaying().Name
name := m.currentlyPlaying.Name
if len(name) > playerMaxTitleLength {
name = name[0:playerMaxTitleLength] + "..."
}
@ -86,3 +95,26 @@ func (m *playerModel) View() string {
return ""
}
// other functions
func (m *playerModel) queue(f feedEntry) error {
m.playQueue = append(m.playQueue, f)
if len(m.playQueue) == 1 && m.mpv.IsPlaying() == false {
m.currentlyPlaying = &m.playQueue[0]
m.playQueue = m.playQueue[1:]
return m.mpv.Play(VideoID("TODO-remove-this"), m.currentlyPlaying.Link)
}
return nil
}
func (m *playerModel) playNext() error {
if len(m.playQueue) > 0 && m.mpv.IsPlaying() == false {
m.currentlyPlaying = &m.playQueue[0]
m.playQueue = m.playQueue[1:]
return m.mpv.Play(VideoID("TODO-remove-this"), m.currentlyPlaying.Link)
}
return nil
}