2011-04-18 19:50:12 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# Copyright (c) 2008-2011 Raoul Snyman #
|
|
|
|
# Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael #
|
|
|
|
# Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, Armin Köhler, #
|
|
|
|
# Andreas Preikschat, Mattias Põldaru, Christian Richter, Philip Ridout, #
|
|
|
|
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Frode Woldsund #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# 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; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# 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, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
|
|
|
|
2011-04-21 13:54:44 +00:00
|
|
|
import sys
|
2011-05-17 19:50:00 +00:00
|
|
|
try:
|
|
|
|
import vlc
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
from PyQt4 import QtCore, QtGui
|
2011-05-10 20:39:17 +00:00
|
|
|
from openlp.plugins.media.lib import MediaController, MediaState
|
2011-04-18 19:50:12 +00:00
|
|
|
|
2011-04-19 12:03:36 +00:00
|
|
|
class VlcController(MediaController):
|
2011-04-18 19:50:12 +00:00
|
|
|
"""
|
2011-04-19 12:03:36 +00:00
|
|
|
Specialiced MediaController class
|
|
|
|
to reflect Features of the Vlc backend
|
2011-04-18 19:50:12 +00:00
|
|
|
"""
|
2011-04-21 13:54:44 +00:00
|
|
|
def __init__(self, parent):
|
|
|
|
MediaController.__init__(self, parent)
|
2011-05-10 20:39:17 +00:00
|
|
|
self.parent = parent
|
2011-05-17 19:50:00 +00:00
|
|
|
|
|
|
|
def setup(self, display):
|
|
|
|
display.vlcWidget = QtGui.QFrame(display)
|
|
|
|
# creating a basic vlc instance
|
|
|
|
display.vlcInstance = vlc.Instance()
|
|
|
|
display.vlcInstance.set_log_verbosity(2)
|
|
|
|
# creating an empty vlc media player
|
|
|
|
display.vlcMediaPlayer = display.vlcInstance.media_player_new()
|
|
|
|
display.vlcWidget.resize(display.size())
|
|
|
|
display.vlcWidget.raise_()
|
|
|
|
display.vlcWidget.hide()
|
|
|
|
self.hasOwnWidget = True
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def is_available():
|
|
|
|
try:
|
|
|
|
import vlc
|
|
|
|
return True
|
|
|
|
except:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get_supported_file_types(self):
|
2011-05-10 20:39:17 +00:00
|
|
|
self.supported_file_types = ['avi']
|
|
|
|
self.additional_extensions = {
|
|
|
|
u'audio/ac3': [u'.ac3'],
|
|
|
|
u'audio/flac': [u'.flac'],
|
|
|
|
u'audio/x-m4a': [u'.m4a'],
|
|
|
|
u'audio/midi': [u'.mid', u'.midi'],
|
|
|
|
u'audio/x-mp3': [u'.mp3'],
|
|
|
|
u'audio/mpeg': [u'.mp3', u'.mp2', u'.mpga', u'.mpega', u'.m4a'],
|
|
|
|
u'audio/qcelp': [u'.qcp'],
|
|
|
|
u'audio/x-wma': [u'.wma'],
|
|
|
|
u'audio/x-ms-wma': [u'.wma'],
|
|
|
|
u'video/x-flv': [u'.flv'],
|
|
|
|
u'video/x-matroska': [u'.mpv', u'.mkv'],
|
|
|
|
u'video/x-wmv': [u'.wmv'],
|
|
|
|
u'video/x-ms-wmv': [u'.wmv']}
|
2011-04-18 19:50:12 +00:00
|
|
|
|
|
|
|
def load(self, display, path, volume):
|
2011-04-21 13:54:44 +00:00
|
|
|
print "load vid in Vlc Controller"
|
|
|
|
vol = float(volume) / float(10)
|
|
|
|
|
|
|
|
# create the media
|
2011-05-17 19:50:00 +00:00
|
|
|
#display.vlcMedia = display.vlcInstance.media_new(unicode(path))
|
|
|
|
display.vlcMedia = display.vlcInstance.media_new_path(unicode(path))
|
2011-04-21 13:54:44 +00:00
|
|
|
# put the media in the media player
|
|
|
|
display.vlcMediaPlayer.set_media(display.vlcMedia)
|
|
|
|
|
|
|
|
# parse the metadata of the file
|
|
|
|
display.vlcMedia.parse()
|
|
|
|
|
|
|
|
# the media player has to be 'connected' to the QFrame
|
|
|
|
# (otherwise a video would be displayed in it's own window)
|
|
|
|
# this is platform specific!
|
|
|
|
# you have to give the id of the QFrame (or similar object) to
|
|
|
|
# vlc, different platforms have different functions for this
|
|
|
|
if sys.platform == "linux2": # for Linux using the X Server
|
|
|
|
display.vlcMediaPlayer.set_xwindow(int(display.vlcWidget.winId()))
|
|
|
|
elif sys.platform == "win32": # for Windows
|
|
|
|
display.vlcMediaPlayer.set_hwnd(int(display.vlcWidget.winId()))
|
|
|
|
elif sys.platform == "darwin": # for MacOS
|
|
|
|
display.vlcMediaPlayer.set_agl(int(display.vlcWidget.winId()))
|
2011-05-10 20:39:17 +00:00
|
|
|
|
2011-05-17 19:50:00 +00:00
|
|
|
def resize(self, display, controller):
|
2011-05-10 20:39:17 +00:00
|
|
|
display.vlcWidget.resize(display.size())
|
2011-04-18 19:50:12 +00:00
|
|
|
|
|
|
|
def play(self, display):
|
2011-05-17 19:50:00 +00:00
|
|
|
self.set_visible(display, True)
|
2011-04-21 13:54:44 +00:00
|
|
|
display.vlcMediaPlayer.play()
|
2011-05-10 20:39:17 +00:00
|
|
|
self.state = MediaState.Playing
|
2011-04-18 19:50:12 +00:00
|
|
|
|
2011-04-21 13:54:44 +00:00
|
|
|
def pause(self, display):
|
|
|
|
display.vlcMediaPlayer.pause()
|
2011-05-10 20:39:17 +00:00
|
|
|
self.state = MediaState.Paused
|
2011-04-18 19:50:12 +00:00
|
|
|
|
2011-04-21 13:54:44 +00:00
|
|
|
def stop(self, display):
|
|
|
|
display.vlcMediaPlayer.stop()
|
2011-05-10 20:39:17 +00:00
|
|
|
self.state = MediaState.Stopped
|
|
|
|
|
|
|
|
def volume(self, display, vol):
|
|
|
|
pass
|
2011-04-18 19:50:12 +00:00
|
|
|
|
2011-04-19 12:03:36 +00:00
|
|
|
def seek(self, display, seekVal):
|
2011-04-21 13:54:44 +00:00
|
|
|
if display.vlcMediaPlayer.is_seekable():
|
|
|
|
display.vlcMediaPlayer.set_position(seekVal/1000.0)
|
2011-04-19 12:03:36 +00:00
|
|
|
|
2011-04-21 13:54:44 +00:00
|
|
|
def reset(self, display):
|
2011-05-17 19:50:00 +00:00
|
|
|
display.vlcMediaPlayer.stop()
|
2011-05-10 20:39:17 +00:00
|
|
|
display.vlcWidget.setVisible(False)
|
2011-05-17 19:50:00 +00:00
|
|
|
self.state = MediaState.Off
|
|
|
|
|
|
|
|
def set_visible(self, display, status):
|
|
|
|
print display.vlcWidget.isVisible(), status
|
|
|
|
if self.hasOwnWidget:
|
|
|
|
display.vlcWidget.setVisible(status)
|
2011-04-19 12:03:36 +00:00
|
|
|
|
2011-05-10 20:39:17 +00:00
|
|
|
def update_ui(self, controller, display):
|
|
|
|
controller.seekSlider.setMaximum(1000)
|
|
|
|
if not controller.seekSlider.isSliderDown():
|
2011-04-21 13:54:44 +00:00
|
|
|
currentPos = display.vlcMediaPlayer.get_position() * 1000
|
2011-05-10 20:39:17 +00:00
|
|
|
controller.seekSlider.setSliderPosition(currentPos)
|
2011-04-21 13:54:44 +00:00
|
|
|
|
2011-05-10 20:39:17 +00:00
|
|
|
def get_supported_file_types(self):
|
2011-04-18 19:50:12 +00:00
|
|
|
pass
|