seopardy/video.py

43 lines
1.0 KiB
Python

from __future__ import print_function
from PySide import phonon
class VideoPlayer(object):
def __init__(self, video, audio=False):
self._videoFile = video
self._audio = audio
self._widget = None
self._media_obj = phonon.Phonon.MediaObject()
self._media_src = phonon.Phonon.MediaSource(self._videoFile)
self._audio_out = None
# setup media object
self._media_obj.setCurrentSource(self._media_src)
# make media object loop
self._media_obj.finished.connect(lambda: self._media_obj.play())
if self._audio:
self._audio_out = phonon.Phonon.AudioOutput(phonon.Phonon.VideoCategory)
phonon.Phonon.createPath(self._media_obj, self._audio_out)
def get_widget(self):
if self._widget == None:
self._widget = phonon.Phonon.VideoWidget()
self._widget.setScaleMode(phonon.Phonon.VideoWidget.ScaleAndCrop)
phonon.Phonon.createPath(self._media_obj, self._widget)
return self._widget
def play(self):
self._media_obj.play()
def pause(self):
self._media_obj.pause()
def stop(self):
self._media_obj.stop()