3
from argparse import ArgumentParser
9
from gi.repository import Gst
10
from gi.repository import GLib
11
from subprocess import check_output
14
def check_state(device):
15
"""Checks whether the sink is available for the given device.
17
sink_info = check_output(['pacmd', 'list-sinks'],
18
universal_newlines=True)
20
data = sink_info.split("\n")
22
device_name = re.findall(".*name:\s.*%s.*" % device, sink_info)[0].lstrip()
23
sink = re.findall(".*name:\s<(.*%s.*)>" % device, sink_info)[0].lstrip()
24
status = data[data.index("\t" + device_name) + 3]
25
except (IndexError, ValueError):
26
logging.error("Failed to find status for device: %s" % device)
29
os.environ['PULSE_SINK'] = sink
30
logging.info("[ Pulse sink ]".center(80, '='))
31
logging.info("Device: %s %s" % (device_name.strip(), status.strip()))
36
parser = ArgumentParser(description='Simple GStreamer pipeline player')
37
parser.add_argument('PIPELINE',
38
help='Quoted GStreamer pipeline to launch')
39
parser.add_argument('-t', '--timeout',
40
type=int, required=True,
41
help='Timeout for running the pipeline')
42
parser.add_argument('-d', '--device',
44
help="Device to check for status")
45
args = parser.parse_args()
47
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO,
52
if not check_state(args.device):
57
print("Attempting to initialize Gstreamer pipeline: {}".format(
59
element = Gst.parse_launch(args.PIPELINE)
60
except GLib.GError as error:
61
print("Specified pipeline couldn't be processed.")
62
print("Error when processing pipeline: {}".format(error))
66
print("Pipeline initialized, now starting playback.")
67
element.set_state(Gst.State.PLAYING)
70
time.sleep(args.timeout)
72
element.set_state(Gst.State.NULL)
77
if __name__ == "__main__":