-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSPVideoPlayer.py
82 lines (67 loc) · 2.94 KB
/
SPVideoPlayer.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# -*- coding: utf-8 -*-
# Copyright (c) 2010 Stas Zykiewicz <[email protected]>
#
# SPVideoPlayer.py
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 3 of the GNU General Public License
# as published by the Free Software Foundation. A copy of this license should
# be included in the file GPL-3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import os
import subprocess
class _Cmd(object):
# class that provides shell command strings
start = "/usr/bin/vlc --one-instance-when-started-from-file --intf 'skins2' --skins2-last=%s %s"
class Player:
"""class that wraps the system call to the vlc player and provides
some abstraction. It also restores the volume when vlc quits."""
def __init__(self,skinpath):
self.skinpath = os.path.abspath(skinpath)
self._cmd = _Cmd()
# Default is used in case of an error when calling amixer
self.volume_level = 75
def start(self, moviepath):
"""Start player.
Returns (True,'') when successful and (False,text) on any error.
This call blocks the main thread until the player is stopped."""
self._get_volume()
result = self._execute(self._cmd.start % (self.skinpath, os.path.abspath(moviepath)))
self._restore_volume()
return result
def stop(self):
pass
# internally used
def _get_volume(self):
try:
cmd=subprocess.Popen("amixer get Master",shell=True, \
stdout=subprocess.PIPE, \
stderr=subprocess.PIPE)
output = cmd.communicate()[0]
except Exception as info:
module_logger.warning("program 'amixer' not found, unable to get volume levels")
else:
for line in output.split('\n'):
if "%]" in line:
self.volume_level = int(line.split("%]")[0].split("[")[1])
def _restore_volume(self):
subprocess.Popen("amixer set Master %s" % self.volume_level + "%",shell=True)
def _execute(self,cmd):
try:
#result = subprocess.call(cmd)
result = os.system(cmd)
except OSError as info:
return (False, cmd+" "+str(info))
if result:
return (False, str(result))
return (True,'')
if __name__ == '__main__':
pl = Player('lib/SPData/themes/braintrainer/btp_800x600.vlt')
print(pl.start('lib/CPData/Test_actData/ayb.avi'))