Skip to content

Commit

Permalink
fixed getting Kodi resume state before starting a playback. added mul…
Browse files Browse the repository at this point in the history
…tiple efforts run for seeks
  • Loading branch information
elgatito committed Sep 28, 2019
1 parent 9189896 commit 06b335a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bittorrent/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ func (btp *Player) Buffer() error {

btp.overlayStatus = xbmc.NewOverlayStatus()

btp.GetIdent()
go btp.waitCheckAvailableSpace()
go btp.playerLoop()

Expand Down Expand Up @@ -865,7 +866,6 @@ playbackWaitLoop:
playing := true

btp.updateWatchTimes()
btp.GetIdent()
btp.findNextEpisode()

log.Infof("Got playback: %fs / %fs", btp.p.WatchedTime, btp.p.VideoDuration)
Expand Down
23 changes: 20 additions & 3 deletions maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (
episodeType = "episode"
)

var seekCatched = false

// Notification serves callbacks from Kodi
func Notification(w http.ResponseWriter, r *http.Request, s *bittorrent.Service) {
sender := r.URL.Query().Get("sender")
Expand Down Expand Up @@ -64,6 +66,8 @@ func Notification(w http.ResponseWriter, r *http.Request, s *bittorrent.Service)
p.Params().KodiPosition = request.Position

case "Player.OnSeek":
seekCatched = true

p := s.GetActivePlayer()
if p == nil || p.Params().VideoDuration == 0 {
return
Expand All @@ -83,6 +87,8 @@ func Notification(w http.ResponseWriter, r *http.Request, s *bittorrent.Service)
}

case "Player.OnPlay":
seekCatched = false

time.Sleep(400 * time.Millisecond) // Let player get its WatchedTime and VideoDuration
p := s.GetActivePlayer()
if p == nil {
Expand Down Expand Up @@ -124,9 +130,20 @@ func Notification(w http.ResponseWriter, r *http.Request, s *bittorrent.Service)
}

if resumePosition > 0 {
log.Infof("OnPlay. Seeking to %v", resumePosition)
time.Sleep(500 * time.Millisecond)
xbmc.PlayerSeek(resumePosition)
go func(resume float64) {
log.Infof("OnPlay. Seeking to %v", resume)

for i := 1; i <= 3; i++ {
time.Sleep(time.Duration(i*500) * time.Millisecond)
if seekCatched {
log.Infof("OnPlay. Seek completed")
return
}

log.Infof("OnPlay. Triggering Seek to %v", resume)
xbmc.PlayerSeek(resume)
}
}(resumePosition)
}

case "Player.OnStop":
Expand Down

0 comments on commit 06b335a

Please sign in to comment.