Skip to content

Commit

Permalink
fix: Fix initial play event for YouTube TV clients
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Mar 10, 2024
1 parent 727bda9 commit ee8e7a5
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions internal/device/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ type Device struct {
ticker *time.Ticker

meta VideoMeta
mediaSessionId int
segments []sponsorblock.Segment
mutedSegmentId int
}
Expand Down Expand Up @@ -163,12 +162,10 @@ func (d *Device) tick() error {
castApp, castMedia, castVol := d.app.Status()

if castApp == nil || castApp.DisplayName != "YouTube" || castMedia == nil {
d.mediaSessionId = 0
d.changeTickInterval(config.Default.PausedInterval)
return nil
}

d.mediaSessionId = castMedia.MediaSessionId
if castMedia.PlayerState != StatePlaying && castMedia.PlayerState != StateBuffering {
d.changeTickInterval(config.Default.PausedInterval)
return nil
Expand Down Expand Up @@ -280,23 +277,15 @@ func (d *Device) onMessage(msg *api.CastMessage) {
d.changeTickInterval(config.Default.PlayingInterval)
}
case "MEDIA_STATUS":
currMediaSessionId, err := jsonparser.GetInt(payload, "status", "[0]", "mediaSessionId")
if err != nil {
return
}

playerState, _ := jsonparser.GetString(payload, "status", "[0]", "playerState")
switch playerState {
case StatePlaying, StateBuffering:
if int(currMediaSessionId) == d.mediaSessionId {
d.changeTickInterval(config.Default.PlayingInterval)
}
d.changeTickInterval(config.Default.PlayingInterval)
}
case "CLOSE":
d.unmuteSegment()
d.segments = nil
d.meta.Clear()
d.mediaSessionId = 0
}
}

Expand Down

0 comments on commit ee8e7a5

Please sign in to comment.