forked from jackcook/bigger-fish
-
Notifications
You must be signed in to change notification settings - Fork 3
/
video_player.py
34 lines (26 loc) · 862 Bytes
/
video_player.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import subprocess
import time
from enum import Enum
class SupportedPlayers(Enum):
MPV = 1
MPLAYER = 2
VLC = 3
@staticmethod
def map(name: str):
if name.lower() == "mpv":
return SupportedPlayers.MPV
if name.lower() == "mplayer":
return SupportedPlayers.MPLAYER
if name.lower() == "vlc":
return SupportedPlayers.VLC
class VideoPlayer:
players = None
player = None
def __init__(self, players=SupportedPlayers, player=SupportedPlayers.VLC):
self.players = players
self.player = player.name
def play(self, file_path, length):
player_name = self.player.lower()
player_process = subprocess.Popen([player_name, file_path], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
time.sleep(length)
player_process.kill()