Send real pause for video

This commit is contained in:
gardouille 2022-07-05 09:12:15 +02:00
parent c97f868ef2
commit ce222097e2
Signed by: gardouille
GPG Key ID: E759BAA22501AF32
1 changed files with 34 additions and 6 deletions

View File

@ -127,12 +127,9 @@ define_vars() { # {{{
## }}}
## Translate user command to Kodi action {{{
case "${USER_MULTIMEDIA_COMMAND}" in
toggle|play ) ## Toggle current play
toggle|play|pause ) ## Toggle current play
KODI_ACTION="PlayerControl(play)"
;;
pause ) ## Pause current media if anything is playing
KODI_ACTION="PlayerControl(pause)"
;;
stop ) ## Stop current play
KODI_ACTION="PlayerControl(stop)"
;;
@ -185,7 +182,7 @@ procs running (with the pattern: ${RED}${local_proc_pattern}${COLOR_DEBUG}) on t
get_current_media_type() { # {{{
debug_message "get_current_media_type \
Run a request to ${KODI_HOST}:${KODI_PORT} API :"
Run a request to ${KODI_HOST}:${KODI_PORT} API."
KODI_CURRENT_MEDIA_TYPE=$(curl -s -X POST http://"${KODI_HOST}:${KODI_PORT}"/jsonrpc -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"Player.GetActivePlayers","id":0}' | sed -n 's/.*"type":"\(.*\)".*/\1/p')
}
@ -219,6 +216,35 @@ The current media is playing (speed: ${RED}${KODI_CURRENT_MEDIA_TYPE}${COLOR_DEB
return "${return_is_audio_paused}"
}
# }}}
is_video_paused() { # {{{
## Media is playing by default
return_is_video_paused="1"
debug_message "is_video_paused \
Run a request to ${KODI_HOST}:${KODI_PORT} API to get status of video media."
KODI_CURRENT_VIDEO_SPEED=$(curl -s -X POST http://"${KODI_HOST}:${KODI_PORT}"/jsonrpc -H 'Content-Type: application/json' --data '{"jsonrpc": "2.0", "method": "Player.GetProperties", "params": { "playerid": 1, "properties": [ "speed" ] }, "id": "VideoGetItem" }' | sed -n 's/.*"speed":\(.\).*/\1/p')
case "${KODI_CURRENT_VIDEO_SPEED}" in
0 ) ## Media is paused
debug_message "is_video_paused \
The current video is paused (speed: ${RED}${KODI_CURRENT_MEDIA_TYPE}${COLOR_DEBUG})."
return_is_video_paused="0"
;;
1 ) ## Media is playing
debug_message "is_video_paused \
The current video is playing (speed: ${RED}${KODI_CURRENT_MEDIA_TYPE}${COLOR_DEBUG})."
return_is_video_paused="1"
;;
* ) ## Error getting current media speed
error_message "Error with media speed (${KODI_CURRENT_VIDEO_SPEED})." 1
;;
esac
return "${return_is_video_paused}"
}
# }}}
main() { # {{{
@ -245,7 +271,9 @@ main() { # {{{
&& exit 0
;;
video ) ## Manage video media
debug_message "${RED}video${COLOR_DEBUG} type for current media is not yet managed."
is_video_paused \
&& debug_message "${RED}video${COLOR_DEBUG} media is already paused, no more action is required." \
&& exit 0
;;
* ) ## Unknown media type or no media at all
debug_message "Unknown media type ->${RED}${KODI_CURRENT_MEDIA_TYPE}${COLOR_DEBUG}<- or no media is playing (if empty), exit."