3
from argparse import ArgumentParser
7
from gi.repository import Gst
8
from subprocess import check_output
11
def check_state(device):
12
"""Checks whether the sink is available for the given device.
14
sink_info = check_output(['pacmd', 'list-sinks'],
15
universal_newlines=True)
17
data = sink_info.split("\n")
19
device = re.findall(".*name:\s.*%s.*" % device, sink_info)[0].lstrip()
20
status = data[data.index("\t" + device) + 3]
21
except (IndexError, ValueError):
22
print("Failed to find status for device: %s" % device, file=sys.stderr)
25
print("Device: %s %s" % (device.strip(), status.strip()))
30
parser = ArgumentParser(description='Simple GStreamer pipeline player')
31
parser.add_argument('PIPELINE',
32
help='Quoted GStreamer pipeline to launch')
33
parser.add_argument('-t', '--timeout',
34
type=int, required=True,
35
help='Timeout for running the pipeline')
36
parser.add_argument('-d', '--device',
38
help="Device to check for status")
39
args = parser.parse_args()
42
element = Gst.parse_launch(args.PIPELINE)
43
element.set_state(Gst.State.PLAYING)
46
time.sleep(args.timeout)
50
if not check_state(args.device):
53
element.set_state(Gst.State.NULL)
58
if __name__ == "__main__":