[Pyxine-checkins] pyxine/examples player.py,1.1.1.1,1.2 tkplayer.py,1.1.1.1,1.2
Status: Pre-Alpha
Brought to you by:
dairiki
From: <da...@us...> - 2003-02-13 19:51:30
|
Update of /cvsroot/pyxine/pyxine/examples In directory sc8-pr-cvs1:/tmp/cvs-serv15179/examples Modified Files: player.py tkplayer.py Log Message: Abstract some higher-level playing functionality into new class pyxine.player.Player. Index: player.py =================================================================== RCS file: /cvsroot/pyxine/pyxine/examples/player.py,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- player.py 8 Feb 2003 00:42:18 -0000 1.1.1.1 +++ player.py 13 Feb 2003 19:51:27 -0000 1.2 @@ -27,6 +27,7 @@ from Xlib import X, Xutil, threaded, display, XK import pyxine +import pyxine.player import sys, os, os.path @@ -86,47 +87,15 @@ self.xine_visual = pyxine.XlibDrawable(self.window) -class Player: +class Player(pyxine.player.Player): def __init__(self, window): xine = pyxine.Xine(cfg_filename=XINECFG) ao = xine.open_audio_driver() vo = xine.open_video_driver(data=window.xine_visual) #vo = xine.open_video_driver("xv", visual="X11", data=vis) stream = xine.stream_new(ao, vo) - self.stream = stream - self.play(LOGO) + self.set_stream(stream) - def play(self, mrl, pos=0, time=0): - stream = self.stream - stream.open(mrl) - if stream.has_video: - self.degoomify() - else: - self.goomify() - stream.play(pos, time) - - def stop(self): - self.stream.stop() - - def pause(self): - stream = self.stream - if stream.speed == "NORMAL": - stream.speed = "PAUSE" - else: - stream.speed = "NORMAL" - - def degoomify(self): - stream = self.stream - stream.audio_source.wire(stream.ao) - - def goomify(self): - stream = self.stream - from pyxine import post - goom = post.Post(stream, "goom", - audio_target=stream.ao, - video_target=stream.vo) - stream.audio_source.wire(goom.inputs["audio in"]) - class Quit(Exception): pass @@ -185,7 +154,8 @@ raise Quit def play(self): - self.player.play(self.playlist[0]) + if self.playlist: + self.player.play(self.playlist[0]) def stop(self): self.player.stop() @@ -194,18 +164,20 @@ self.player.pause() def play_next(self): - self.playlist.append(self.playlist.pop(0)) - self.play() + if self.playlist: + self.playlist.append(self.playlist.pop(0)) + self.play() def play_prev(self): - self.playlist.insert(0, self.playlist.pop()) - self.play() + if self.playlist: + self.playlist.insert(0, self.playlist.pop()) + self.play() def handle_ClientMessage(self, e): if e.client_type == window.WM_PROTOCOLS: fmt, data = e.data - if fmt == 32 and data[0] == window.WM_DELETE_WINDOW: - raise Quit + if fmt == 32 and data[0] == window.WM_DELETE_WINDOW: + raise Quit if __name__ == '__main__': Index: tkplayer.py =================================================================== RCS file: /cvsroot/pyxine/pyxine/examples/tkplayer.py,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- tkplayer.py 8 Feb 2003 00:42:18 -0000 1.1.1.1 +++ tkplayer.py 13 Feb 2003 19:51:27 -0000 1.2 @@ -21,13 +21,11 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. from Tkinter import * -import pyxine -from pyxine import constwrap +import pyxine, pyxine.player import os, os.path XINECFG = os.path.join(os.environ['HOME'], '.xine/config2') -LOGO = "/usr/share/xine/skins/xine-ui_logo.mpv" # Callbacks from pyxine happen asynchronously. # Tkinter doesn't seem to be thread-safe. @@ -84,10 +82,10 @@ lock = theTkMutex() return pyxine.TkWidget.frame_output_cb(self, *args) -class Player(Frame): +class Player(Frame, pyxine.player.Player): def __init__(self, master=None): Frame.__init__(self, master, bg='gray10', width=100, height=100) - + self.stream = None vidwin = Frame(self, bg='') @@ -103,26 +101,16 @@ return xine = pyxine.Xine(cfg_filename=XINECFG) visual = X11Visual(self.vidwin) + self.visual = visual vo = xine.open_video_driver("xv", data=visual) stream = xine.stream_new(vo=vo) - self.listener = stream.new_event_listener(self.xine_event_cb) - self.stream = stream - self.visual = visual - self.play(LOGO) - + self.set_stream(stream) + print "STREAM OPEN" + def close_stream(self): self.listener = None - self.stream = None self.visual = None - - def xine_event_cb(self, event): - if event.type == "FRAME_FORMAT_CHANGE": - self.frame_format_change(event.data) - elif event.type == "UI_PLAYBACK_FINISHED": - print "PLAYBACK DONE" - self.stop() - else: - print "Unhandled event", event + self.set_stream(None) def frame_format_change(self, format): video_geometry = format.get_video_geometry() @@ -142,55 +130,6 @@ top.geometry("%dx%d" % (fwidth, fheight)) print "FRAME SIZE CHANGE", (width, height), (fwidth, fheight) - def play(self, mrl): - stream = self.stream - stream.close() - print "OPEN" - stream.open(mrl) - self.current_mrl = mrl - if stream.has_video: - self.degoomify() - else: - self.goomify() - print "PLAY" - stream.play() - - def stop(self): - stream = self.stream - if self.current_mrl != LOGO: - self.play(LOGO) - else: - self.stream.close() - - def pause(self): - stream = self.stream - if stream.speed == "NORMAL": - stream.speed = "PAUSE" - else: - stream.speed = "NORMAL" - - def seek(self, pos): - stream = self.stream - stream.stop() - stream.play(pos) - - def seekrel(self, secs): - stream = self.stream - pos = stream.get_pos_length()[1] - stream.stop() - stream.play(start_time = pos + secs) - - def degoomify(self): - stream = self.stream - stream.audio_source.wire(stream.ao) - - def goomify(self): - stream = self.stream - from pyxine import post - goom = post.Post(stream, "goom", - audio_target=stream.ao, - video_target=stream.vo) - stream.audio_source.wire(goom.inputs["audio in"]) class Main(Tk): def __init__(self): |