如何从vlc捕获例外?

问题描述 投票:0回答:2

我在VLC的捕获异常方面有问题。而不是打印文本,我会得到以下信息:

  • [00007F0988001690]文件系统流错误:无法打开文件 /home/user/recording.mp3(没有这样的文件或目录)
  • [0000557838609BE0]主输入错误:无法打开输入
  • [0000557838609BE0]主要输入错误:VLC无法打开MRL 'file:///home/user/recording.mp3'。检查日志以获取细节。
  • 我的代码是我的代码:

from vlc import MediaPlayer x = MediaPlayer('recording.mp3') def play_sound(): try: x.play() except: print('Cannot play sound.') play_sound()

如何修复?

python try-catch vlc
2个回答
0
投票
我无法根据需要捕获错误,但是我可以阅读日志并在那上行动

Https://www.reddit.com/r/learlenprogramming/comments/fgymq4/import_vlc_error_python/

上打开代码登录,但没有一个可用于me.

instead,启动VLC和管道标准错误,使用 your_python_script.py &> yourlog_file.txt

然后使用

watchDog
观察该文件并采取行动。
不好。比我能找到的其他任何东西都要好。

我正在使用以下方式使用VLCS Event_Manager回调功能来本机本地播放错误。这是我的工作代码:

def callback_from_player(self, event: vlc.Event, *args): logging.debug('callback called: %s, from %s', event.type, args[0]) # continue with your code here, I am starting a new thread at this point. # one cannot call vlc library functions within the event callback function. def play(self): instance: vlc.Instance = vlc.Instance() list_player: vlc.MediaListPlayer = instance.media_list_player_new() list_player.set_playback_mode(vlc.PlaybackMode.loop) media_player: vlc.MediaPlayer = list_player.get_media_player() # the crutial line: media_player.event_manager().event_attach( vlc.EventType.MediaPlayerEncounteredError, self.callback_from_player, "media_player") media: vlc.Media = instance.media_new(self.url) media_list: vlc.MediaList = instance.media_list_new([]) list_player.set_media_list(media_list) media_list.add_media(media) list_player.play()


0
投票
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.