How to catch exception from VLC?

Viewed 821

I have problem with catching exception from VLC. Instead of printing my text I get information like:

  • [00007f0988001690] filesystem stream error: cannot open file /home/user/recording.mp3 (No such file or directory)
  • [0000557838609be0] main input error: Your input can't be opened
  • [0000557838609be0] main input error: VLC is unable to open the MRL 'file:///home/user/recording.mp3'. Check the log for details.

Here is my code:

from vlc import MediaPlayer

x = MediaPlayer('recording.mp3')

def play_sound():
    try:
        x.play()
    except:
        print('Cannot play sound.')

play_sound()

How to fix it?

1 Answers

This is not a great answer, but does me as a workaround until one turns up.

I cannot trap the error as desired, but I can read the logs and act on that

There is discussion at https://www.reddit.com/r/learnprogramming/comments/fgymq4/import_vlc_error_python/ on turning logging on in code, but none of that worked for me.

Instead, start vlc and pipe standard error to a file using

your_python_script.py &> yourlog_file.txt

Then use watchdog to observe that file and take action.

Not great. Better than anything else I can find.

Related