Play ha un comportamento più sensato
Leonardo Robol [2009-11-06 07:33]
Play ha un comportamento più sensato
diff --git a/RaiTV/ChannelLoader.py b/RaiTV/ChannelLoader.py
index 492168a..e224386 100644
--- a/RaiTV/ChannelLoader.py
+++ b/RaiTV/ChannelLoader.py
@@ -43,9 +43,7 @@ class ChannelList():
if url_array is not []:
self.channels.append((name, url_array[0]))
-
-
-
+
def getChannel(self, channel):
"""Ottiene il vero canale da cui guardare.. :)"""
@@ -77,9 +75,13 @@ class ChannelList():
it = self.channels.get_iter(path)
url = self.channels.get_value(it, 1)
- print "url: " + url
+ return self.urlToMms(url)
+ def getChannelFromIter(self, it):
+
+ url = self.channels.get_value(it, 1)
return self.urlToMms(url)
+
def urlToMms(self, url):
"""Converte un URL nello streaming MMS"""
@@ -90,6 +92,7 @@ class ChannelList():
r = urllib2.urlopen(req)
mms = r.read()
mms = re.search(r"HREF=\"(\S*)\"", mms).group(1)
+ print "mms url // " + mms
return mms
diff --git a/RaiTV/Interface.py b/RaiTV/Interface.py
index 9c86c39..29a718d 100644
--- a/RaiTV/Interface.py
+++ b/RaiTV/Interface.py
@@ -81,9 +81,18 @@ class UI():
def connect_buttons(self):
"""Connette i bottoni con le relative azioni"""
self.stop_btn.connect("clicked", lambda w: self.videowidget.stop() )
- self.play_btn.connect("clicked", lambda w: self.videowidget.play() )
+ self.play_btn.connect("clicked", lambda w: self.play() )
self.pause_btn.connect("clicked", lambda w: self.videowidget.pause() )
self.updatelist.connect("clicked", lambda w: self.updateChannels() )
+
+ def play(self):
+ if not self.videowidget.playing:
+ treeselection = self.listacanali.get_selection()
+ model, treeiter = treeselection.get_selected()
+ mmsurl = self.channellist.getChannelFromIter(treeiter)
+ self.videowidget.load_video(mmsurl)
+ else:
+ self.videowidget.play()
def updateChannels(self):
"""Aggiorna la lista dei canali scaricandola direttamente da quella
diff --git a/RaiTV/VideoWidget.py b/RaiTV/VideoWidget.py
index 6c319b1..c14cb7a 100644
--- a/RaiTV/VideoWidget.py
+++ b/RaiTV/VideoWidget.py
@@ -38,6 +38,13 @@ class GstPlayer(threading.Thread):
if message.type == gst.MESSAGE_ERROR:
err, debug = message.parse_error()
print err, debug
+ elif message.type == gst.MESSAGE_LATENCY:
+ print message.parse_latency()
+ elif message.type == gst.MESSAGE_BUFFERING:
+ if message.parse_buffering() is 100:
+ self.play()
+ self.loading = False
+
def is_loading(self):
return self.loading
@@ -53,16 +60,18 @@ class GstPlayer(threading.Thread):
bus.connect("message", self.on_message)
self.loading = True
+
self.player.set_property("uri", self.video)
- self.player.set_state(gst.STATE_PLAYING)
- self.loading = False
+ self.pause()
+
while not self.exit_required:
pass
self.player.set_state(gst.STATE_NULL)
def exit(self):
+ self.player.set_state(gst.STATE_NULL)
self.exit_required = True
def pause(self):
@@ -70,6 +79,7 @@ class GstPlayer(threading.Thread):
def play(self):
self.player.set_state(gst.STATE_PLAYING)
+ self.loading = False
class VideoWidget(gtk.DrawingArea):
@@ -138,9 +148,11 @@ class VideoWidget(gtk.DrawingArea):
self.player = GstPlayer(self.window.xid, uri)
print " => Player creato"
self.player.start()
+ self.player.pause()
print " => Player avviato"
self.playing = True
+
## Aspettiamo 5 secondi
@@ -152,15 +164,18 @@ class VideoWidget(gtk.DrawingArea):
self.playing = False
if self.player is not None:
self.player.exit()
- self.player.join(timeout=2)
+ self.player.join(2)
if self.player.isAlive():
print " => Ops, l'ho ucciso brutalmente"
del self.player
def play(self):
- self.playing = True
- self.player.play()
+ if self.player is not None:
+ self.playing = True
+ self.player.play()
+
+
def reset(self):