Skip to content

Commit

Permalink
fix crash when trying to load unavailable python-vlc
Browse files Browse the repository at this point in the history
fixes #29
  • Loading branch information
xgi committed Feb 28, 2019
1 parent 80dd787 commit fb1b578
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions castero/players/vlcplayer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import time

import vlc

from castero.player import Player, PlayerDependencyError


Expand All @@ -17,15 +15,19 @@ def __init__(self, title, path, episode) -> None:
"""
super().__init__(title, path, episode)

import vlc
self.vlc = vlc

@staticmethod
def check_dependencies():
"""Checks whether dependencies are met for playing a player.
Overrides method from Player; see documentation in that class.
"""
try:
import vlc
vlc.Instance()
except NameError:
except (ImportError, OSError, AttributeError, ModuleNotFoundError):
raise PlayerDependencyError(
"Dependency VLC not found, which is required for playing"
" media files"
Expand All @@ -36,7 +38,7 @@ def _create_player(self) -> None:
Overrides method from Player; see documentation in that class.
"""
vlc_instance = vlc.Instance("--no-video --quiet")
vlc_instance = self.vlc.Instance("--no-video --quiet")

self._player = vlc_instance.media_player_new()
self._media = vlc_instance.media_new(self._path)
Expand All @@ -62,7 +64,7 @@ def stop(self) -> None:
Overrides method from Player; see documentation in that class.
"""
if self._player is not None:
if self._player.get_state() == vlc.State.Opening:
if self._player.get_state() == self.vlc.State.Opening:
self._player.release()
else:
self._player.stop()
Expand All @@ -74,7 +76,7 @@ def pause(self) -> None:
Overrides method from Player; see documentation in that class.
"""
if self._player is not None:
if self._player.get_state() != vlc.State.Opening:
if self._player.get_state() != self.vlc.State.Opening:
self._player.pause()
self._state = 2

Expand Down

0 comments on commit fb1b578

Please sign in to comment.