2007-11-13 05:03:39 -08:00
|
|
|
import sys, clutter, clutter.cluttergst, gst, pygst, gtk, pygtk, gobject
|
2007-08-29 06:35:13 -07:00
|
|
|
import threading
|
2007-11-22 02:41:29 -08:00
|
|
|
import os
|
2008-04-23 06:50:11 -07:00
|
|
|
from multimedia.MediaController import MediaController
|
2007-08-28 15:03:35 -07:00
|
|
|
|
2008-04-23 06:50:11 -07:00
|
|
|
class AudioController(MediaController):
|
2008-02-19 05:56:45 -08:00
|
|
|
|
2008-01-21 03:09:17 -08:00
|
|
|
def __init__(self, glossMgr):
|
2008-04-23 06:50:11 -07:00
|
|
|
MediaController.__init__(self, glossMgr)
|
2008-05-01 07:04:34 -07:00
|
|
|
self.isPlaying = False
|
2008-05-22 05:41:04 -07:00
|
|
|
|
2008-04-23 06:50:11 -07:00
|
|
|
# Primary audio object
|
|
|
|
self.audio = clutter.cluttergst.Audio()
|
|
|
|
self.audio.connect("eos", self.stream_complete)
|
|
|
|
self.media_element = self.audio
|
2008-05-22 05:41:04 -07:00
|
|
|
|
2008-04-23 06:50:11 -07:00
|
|
|
#self.osd = osd(glossMgr)
|
2007-12-11 02:50:45 -08:00
|
|
|
|
2007-08-29 06:35:13 -07:00
|
|
|
|
2007-08-30 06:48:01 -07:00
|
|
|
def on_key_press_event(self, event):
|
2007-08-31 07:55:09 -07:00
|
|
|
if event.keyval == clutter.keysyms.Left:
|
|
|
|
self.skip(-20)
|
|
|
|
if event.keyval == clutter.keysyms.Right:
|
|
|
|
self.skip(20)
|
|
|
|
|
2007-09-02 06:35:44 -07:00
|
|
|
#self.osd.enter()
|
2007-08-30 06:48:01 -07:00
|
|
|
|
2008-04-23 06:50:11 -07:00
|
|
|
def play_audio(self, uri):
|
2008-05-01 07:04:34 -07:00
|
|
|
if self.isPlaying:
|
|
|
|
self.audio.set_playing(False)
|
2008-05-22 05:41:04 -07:00
|
|
|
|
|
|
|
"""
|
2008-04-28 16:05:13 -07:00
|
|
|
# Primary audio object
|
|
|
|
self.audio = clutter.cluttergst.Audio()
|
|
|
|
self.audio.connect("eos", self.stream_complete)
|
|
|
|
self.media_element = self.audio
|
2008-05-22 05:41:04 -07:00
|
|
|
"""
|
2008-04-28 16:05:13 -07:00
|
|
|
|
2008-04-23 06:50:11 -07:00
|
|
|
self.audio.set_uri(uri)
|
|
|
|
self.audio.set_playing(True)
|
2007-11-13 05:03:39 -08:00
|
|
|
|
2007-08-30 06:48:01 -07:00
|
|
|
self.isPlaying = True
|
2008-04-23 06:50:11 -07:00
|
|
|
#self.stage.add(self.audio)
|
2007-12-02 02:18:18 -08:00
|
|
|
|
2008-02-19 05:56:45 -08:00
|
|
|
self.emit("playing")
|
2008-04-23 06:50:11 -07:00
|
|
|
return self.audio
|
2007-08-29 06:35:13 -07:00
|
|
|
|
2008-04-23 06:50:11 -07:00
|
|
|
def stream_complete(self, audio):
|
2008-04-28 16:05:13 -07:00
|
|
|
|
|
|
|
self.isPlaying = False
|
|
|
|
self.audio.set_playing(False)
|
2008-04-23 06:50:11 -07:00
|
|
|
self.emit("completed")
|
2008-04-28 16:05:13 -07:00
|
|
|
#self.stop_audio
|
2007-12-11 02:50:45 -08:00
|
|
|
|
2008-04-23 06:50:11 -07:00
|
|
|
def stop_audio(self):
|
|
|
|
if self.audio.get_playing():
|
|
|
|
self.isPlaying = False
|
|
|
|
self.audio.set_playing(False)
|
|
|
|
self.emit("stopped")
|
|
|
|
|
2007-08-31 07:55:09 -07:00
|
|
|
|
2008-04-23 06:50:11 -07:00
|
|
|
def pause_audio(self, use_backdrop):
|
2008-02-17 03:23:38 -08:00
|
|
|
if use_backdrop:
|
|
|
|
#Use the overlay to go over show
|
|
|
|
if self.overlay == None:
|
|
|
|
self.overlay = clutter.Rectangle()
|
|
|
|
self.overlay.set_color(clutter.color_parse('Black'))
|
|
|
|
self.overlay.set_size(self.stage.get_width(), self.stage.get_height())
|
|
|
|
self.stage.add(self.overlay)
|
|
|
|
self.overlay.set_opacity(0)
|
|
|
|
self.overlay.show()
|
|
|
|
|
|
|
|
|
|
|
|
#self.video_texture.lower_actor(self.overlay)
|
|
|
|
#self.overlay.raise_actor(self.video_texture)
|
|
|
|
#Fade the overlay in
|
|
|
|
timeline_overlay = clutter.Timeline(10,30)
|
|
|
|
alpha = clutter.Alpha(timeline_overlay, clutter.ramp_inc_func)
|
|
|
|
self.overlay_behaviour = clutter.BehaviourOpacity(opacity_start=0, opacity_end=200, alpha=alpha)
|
|
|
|
self.overlay_behaviour.apply(self.overlay)
|
|
|
|
#video_behaviour.apply(self.video_texture)
|
|
|
|
timeline_overlay.start()
|
2007-09-02 06:35:44 -07:00
|
|
|
|
|
|
|
#Pause the video
|
2007-08-31 07:55:09 -07:00
|
|
|
self.video_texture.set_playing(False)
|
2007-09-02 06:35:44 -07:00
|
|
|
|
2008-04-23 06:50:11 -07:00
|
|
|
def unpause_audio(self):
|
2008-02-17 03:23:38 -08:00
|
|
|
if not self.overlay is None:
|
|
|
|
#Fade the backdrop in
|
|
|
|
timeline_unpause = clutter.Timeline(10,30)
|
|
|
|
alpha = clutter.Alpha(timeline_unpause, clutter.ramp_inc_func)
|
|
|
|
self.overlay_behaviour = clutter.BehaviourOpacity(opacity_start=200, opacity_end=0, alpha=alpha)
|
|
|
|
self.overlay_behaviour.apply(self.overlay)
|
|
|
|
#video_behaviour.apply(self.video_texture)
|
|
|
|
timeline_unpause.start()
|
|
|
|
|
2007-09-02 06:35:44 -07:00
|
|
|
#Resume the video
|
|
|
|
self.video_texture.set_playing(True)
|
|
|
|
|
|
|
|
def skip(self, amount):
|
2007-08-31 07:55:09 -07:00
|
|
|
if not self.video_texture.get_can_seek():
|
|
|
|
return
|
2007-09-02 06:35:44 -07:00
|
|
|
|
2008-01-21 05:10:27 -08:00
|
|
|
#current_pos = self.video_texture.get_position()
|
|
|
|
current_pos = self.video_texture.get_property("position")
|
2008-01-15 04:58:09 -08:00
|
|
|
new_pos = int(int(current_pos) + int(amount))
|
2007-08-31 07:55:09 -07:00
|
|
|
|
|
|
|
if new_pos >= self.video_texture.get_duration():
|
2007-09-02 06:35:44 -07:00
|
|
|
new_pos = self.video_texture.get_duration()-1
|
2007-08-31 07:55:09 -07:00
|
|
|
if new_pos <= 0:
|
|
|
|
new_pos = 1
|
|
|
|
|
|
|
|
# There's apparently a collision in the python bindings with the following method. Change this when its fixed in the bindings
|
|
|
|
#self.video_texture.set_position(new_pos)
|
|
|
|
#Until then use:
|
2007-09-02 06:35:44 -07:00
|
|
|
self.video_texture.set_property("position", int(new_pos))
|
|
|
|
self.osd.shift_video(self.video_texture, amount)
|
2008-04-23 06:50:11 -07:00
|
|
|
|