Skip to content

Commit

Permalink
ref: use pause property instead of (deprecated) pause/resume events
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloo27 committed Nov 25, 2022
1 parent 87e25b2 commit 1295f14
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
15 changes: 9 additions & 6 deletions player/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ func handlePropertyChange(data *mpv.EventProperty) {
callHooks(HookLoopTrackChanged)
case "loop-playlist":
callHooks(HookLoopPlaylistChanged)
case "pause":
value := *(*int)(data.Data.(unsafe.Pointer))
if value == 0 {
State.Paused = false
callHooks(HookPlaybackResumed)
} else {
State.Paused = true
callHooks(HookPlaybackPaused)
}
}
}

Expand All @@ -30,12 +39,6 @@ func startEventHandler() {
handlePropertyChange(data)
case mpv.EVENT_FILE_LOADED:
callHooks(HookFileLoaded)
case mpv.EVENT_PAUSE:
State.Paused = true
callHooks(HookPlaybackPaused)
case mpv.EVENT_UNPAUSE:
State.Paused = false
callHooks(HookPlaybackResumed)
case mpv.EVENT_END_FILE:
callHooks(HookFileEnded)
case mpv.EVENT_IDLE:
Expand Down
5 changes: 4 additions & 1 deletion player/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ func Initialize() {
err = MpvInstance.ObserveProperty(0, "volume", mpv.FORMAT_DOUBLE)
utils.HandleError(err, "Cannot observer volume property")

err = MpvInstance.ObserveProperty(0, "pause", mpv.FORMAT_FLAG)
utils.HandleError(err, "Cannot observer pause property")

err = MpvInstance.ObserveProperty(0, "loop-file", mpv.FORMAT_FLAG)
utils.HandleError(err, "Cannot observer loo-file property")
utils.HandleError(err, "Cannot observer loop-file property")

err = MpvInstance.ObserveProperty(0, "loop-playlist", mpv.FORMAT_FLAG)
utils.HandleError(err, "Cannot observer loop-playlist property")
Expand Down

0 comments on commit 1295f14

Please sign in to comment.