#!/usr/bin/env python3 # # Player - a very simple GStreamer player # # Copyright (C) 2016 Antonio Ospite # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import gi gi.require_version('Gst', '1.0') from gi.repository import Gst Gst.init(None) from gi.repository import GObject GObject.threads_init() class Player(object): def __init__(self, pipeline): self.pipeline = pipeline self.mainloop = GObject.MainLoop() @staticmethod def from_pipeline_string(pipeline_string): pipeline = Gst.parse_launch(pipeline_string) return Player(pipeline) def quit(self): self.mainloop.quit() self.pipeline.set_state(Gst.State.NULL) def bus_message_cb(self, unused_bus, message): if message.type == Gst.MessageType.EOS: self.quit() def play(self): bus = self.pipeline.get_bus() bus.add_signal_watch() bus.connect("message", self.bus_message_cb) self.pipeline.set_state(Gst.State.PLAYING) try: self.mainloop.run() except KeyboardInterrupt: self.quit() return 1 return 0