isamert / empv.el

An Emacs media player, media library manager, radio player, YouTube frontend
GNU General Public License v3.0
103 stars 18 forks source link

How to detect stream failure #53

Closed tvraman closed 6 months ago

tvraman commented 7 months ago

empv shows [ Playing, 00:00 of 00:00 (0%), -1/1] -- the -1/-1 indicates stream failure. Is it possible to detect this programmatically? At present, when this happens, I wait expectantly have to listen to the status line repeatedly until the -1/-1 shows up and then give up; I'd like to hav it announce the failure somehow -- which is the motivation behind the question

isamert commented 6 months ago

I am not quite sure how I can reproduce such issue but here is what can be done according to the mpv's documentation: I added a function called empv-event to be able to observe events generated by mpv. From my understanding, this type of errors should generate an end-file event with reason set to error or eof (which might not be an error). Here is what I came up with:

(empv-event
 'end-file
 (lambda (data)
   (pcase (alist-get 'reason data)
     ("eof" (when (alist-get 'file_error data)
              (message "File ended due to the end of file.  File error: %s" (alist-get 'file_error data))))
     ("error" (message "An error occurred. Error: %s.  File error: %s" (alist-get 'error data)  (alist-get 'file_error data))))))

This should (hopefully) print a message when an error happens during the playback.

tvraman commented 6 months ago

thanks, will give it a try and get back when I find out more --