forked from openlp/openlp
Video items have a preview shown
This commit is contained in:
parent
45d9f436ab
commit
5e8ff0214e
@ -35,14 +35,18 @@ class ListWithPreviews(QtCore.QAbstractListModel):
|
|||||||
self.items = []
|
self.items = []
|
||||||
self.rowheight = 50
|
self.rowheight = 50
|
||||||
self.maximagewidth = self.rowheight * 16 / 9.0;
|
self.maximagewidth = self.rowheight * 16 / 9.0;
|
||||||
if new_preview_function is not None:
|
self.preview_function = new_preview_function
|
||||||
self.make_preview=new_preview_function
|
|
||||||
else:
|
|
||||||
self.make_preview=self.preview_function
|
|
||||||
|
|
||||||
def preview_function(self, filename):
|
def make_preview(self, filename):
|
||||||
if os.path.exists(filename):
|
if os.path.exists(filename):
|
||||||
preview = QtGui.QImage(filename)
|
if self.preview_function is not None:
|
||||||
|
preview=self.preview_function(filename)
|
||||||
|
else:
|
||||||
|
preview = QtGui.QImage(filename)
|
||||||
|
else:
|
||||||
|
preview = None
|
||||||
|
|
||||||
|
if preview is not None:
|
||||||
w = self.maximagewidth;
|
w = self.maximagewidth;
|
||||||
h = self.rowheight
|
h = self.rowheight
|
||||||
preview = preview.scaled(w, h, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)
|
preview = preview.scaled(w, h, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)
|
||||||
|
@ -18,7 +18,7 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|||||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
"""
|
"""
|
||||||
import types
|
import types
|
||||||
|
import os
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
from openlp.core.lib.toolbar import *
|
from openlp.core.lib.toolbar import *
|
||||||
from openlp.core.lib import translate
|
from openlp.core.lib import translate
|
||||||
@ -123,6 +123,8 @@ class MediaManagerItem(QtGui.QWidget):
|
|||||||
# each plugin needs to inherit a class from this and pass that *class* (not an instance) to here
|
# each plugin needs to inherit a class from this and pass that *class* (not an instance) to here
|
||||||
# via the ListViewWithDnD_class member
|
# via the ListViewWithDnD_class member
|
||||||
# self.ServiceItemIconName - string referring to an icon file or a resource icon
|
# self.ServiceItemIconName - string referring to an icon file or a resource icon
|
||||||
|
# self.PreviewFunction - a function which returns a QImage to represent the item (a preview usually) - no scaling required - that's done later
|
||||||
|
# If this fn is not defined, a default will be used (treat the filename as an image)
|
||||||
|
|
||||||
# The assumption is that given that at least two plugins are of the form
|
# The assumption is that given that at least two plugins are of the form
|
||||||
# "text with an icon" then all this will help
|
# "text with an icon" then all this will help
|
||||||
@ -168,7 +170,10 @@ class MediaManagerItem(QtGui.QWidget):
|
|||||||
#Add the List widget
|
#Add the List widget
|
||||||
self.ListView = self.ListViewWithDnD_class()
|
self.ListView = self.ListViewWithDnD_class()
|
||||||
self.ListView.uniformItemSizes = True
|
self.ListView.uniformItemSizes = True
|
||||||
self.ListData = ListWithPreviews()
|
try:
|
||||||
|
self.ListData = ListWithPreviews(self.PreviewFunction)
|
||||||
|
except AttributeError:
|
||||||
|
self.ListData = ListWithPreviews(None)
|
||||||
self.ListView.setModel(self.ListData)
|
self.ListView.setModel(self.ListData)
|
||||||
self.ListView.setGeometry(QtCore.QRect(10, 100, 256, 591))
|
self.ListView.setGeometry(QtCore.QRect(10, 100, 256, 591))
|
||||||
self.ListView.setSpacing(1)
|
self.ListView.setSpacing(1)
|
||||||
|
@ -19,7 +19,13 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import tempfile
|
||||||
|
try:
|
||||||
|
import gst
|
||||||
|
except:
|
||||||
|
log = logging.getLogger(u'MediaMediaItemSetup')
|
||||||
|
log.warning(u'Can\'t generate Vidoe previews - import gst failed');
|
||||||
|
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
|
|
||||||
from openlp.core.lib import MediaManagerItem, translate
|
from openlp.core.lib import MediaManagerItem, translate
|
||||||
@ -51,8 +57,45 @@ class MediaMediaItem(MediaManagerItem):
|
|||||||
# be instanced by the base MediaManagerItem
|
# be instanced by the base MediaManagerItem
|
||||||
self.ListViewWithDnD_class = MediaListView
|
self.ListViewWithDnD_class = MediaListView
|
||||||
self.ServiceItemIconName = u':/media/media_image.png'
|
self.ServiceItemIconName = u':/media/media_image.png'
|
||||||
|
self.PreviewFunction = self.video_get_preview
|
||||||
MediaManagerItem.__init__(self, parent, icon, title)
|
MediaManagerItem.__init__(self, parent, icon, title)
|
||||||
|
|
||||||
|
def video_get_preview(self, filename):
|
||||||
|
|
||||||
|
"""Gets a preview of the first frame of a video file using
|
||||||
|
GSTREAMER (non-portable??? - Can't figure out how to do with
|
||||||
|
Phonon - returns a QImage"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Define your pipeline, just as you would at the command prompt.
|
||||||
|
# This is much easier than trying to create and link each gstreamer element in Python.
|
||||||
|
# This is great for pipelines that end with a filesink (i.e. there is no audible or visual output)
|
||||||
|
log.info ("Video preview %s"%( filename))
|
||||||
|
outfile=tempfile.NamedTemporaryFile(suffix='.png')
|
||||||
|
cmd=u'filesrc location="%s" ! decodebin ! ffmpegcolorspace ! pngenc ! filesink location="%s"'% (filename, outfile.name)
|
||||||
|
pipe = gst.parse_launch(cmd)
|
||||||
|
# Get a reference to the pipeline's bus
|
||||||
|
bus = pipe.get_bus()
|
||||||
|
|
||||||
|
# Set the pipeline's state to PLAYING
|
||||||
|
pipe.set_state(gst.STATE_PLAYING)
|
||||||
|
|
||||||
|
# Listen to the pipeline's bus indefinitely until we receive a EOS (end of stream) message.
|
||||||
|
# This is a super important step, or the pipeline might not work as expected. For example,
|
||||||
|
# in my example pipeline above, the pngenc will not export an actual image unless you have
|
||||||
|
# this line of code. It just exports a 0 byte png file. So... don't forget this step.
|
||||||
|
bus.poll(gst.MESSAGE_EOS, -1)
|
||||||
|
img=QtGui.QImage(outfile.name)
|
||||||
|
outfile.close()
|
||||||
|
# os.unlink(outfile.name)
|
||||||
|
pipe.set_state(gst.STATE_NULL)
|
||||||
|
return img
|
||||||
|
except:
|
||||||
|
log.info("Can't generate video preview for some reason");
|
||||||
|
import sys
|
||||||
|
print sys.exc_info()
|
||||||
|
return QtGui.QImage()
|
||||||
|
|
||||||
|
|
||||||
def generateSlideData(self, service_item):
|
def generateSlideData(self, service_item):
|
||||||
indexes = self.ListView.selectedIndexes()
|
indexes = self.ListView.selectedIndexes()
|
||||||
@ -66,9 +109,9 @@ class MediaMediaItem(MediaManagerItem):
|
|||||||
|
|
||||||
def onPreviewClick(self):
|
def onPreviewClick(self):
|
||||||
log.debug(u'Media Preview Button pressed')
|
log.debug(u'Media Preview Button pressed')
|
||||||
items = self.MediaListView.selectedIndexes()
|
items = self.ListView.selectedIndexes()
|
||||||
for item in items:
|
for item in items:
|
||||||
text = self.MediaListData.getValue(item)
|
text = self.ListData.getValue(item)
|
||||||
print text
|
print text
|
||||||
|
|
||||||
def onMediaLiveClick(self):
|
def onMediaLiveClick(self):
|
||||||
|
@ -22,7 +22,7 @@ from PyQt4 import QtCore, QtGui
|
|||||||
|
|
||||||
from openlp.core.lib import Plugin, MediaManagerItem, SettingsTab
|
from openlp.core.lib import Plugin, MediaManagerItem, SettingsTab
|
||||||
from openlp.plugins.media.lib import MediaTab,MediaMediaItem
|
from openlp.plugins.media.lib import MediaTab,MediaMediaItem
|
||||||
|
from video_preview import video_get_preview
|
||||||
class MediaPlugin(Plugin):
|
class MediaPlugin(Plugin):
|
||||||
|
|
||||||
def __init__(self, plugin_helpers):
|
def __init__(self, plugin_helpers):
|
||||||
|
@ -1,69 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
|
||||||
"""
|
|
||||||
OpenLP - Open Source Lyrics Projection
|
|
||||||
Copyright (c) 2008 Raoul Snyman
|
|
||||||
Portions copyright (c) 2008 Martin Thompson, Tim Bentley,
|
|
||||||
|
|
||||||
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
|
|
||||||
"""
|
|
||||||
import os
|
|
||||||
from PyQt4 import QtCore, QtGui
|
|
||||||
|
|
||||||
# xxx this needs a try, except once we've decided what to do if it fails
|
|
||||||
from PyQt4.phonon import Phonon
|
|
||||||
|
|
||||||
# from openlp.core.lib import Plugin, MediaManagerItem, SettingsTab
|
|
||||||
# from openlp.plugins.media.lib import MediaTab,MediaMediaItem
|
|
||||||
|
|
||||||
"""Renders a video to some surface or other """
|
|
||||||
|
|
||||||
class w(QtGui.QMainWindow):
|
|
||||||
def __init__(self, parent=None):
|
|
||||||
super(QtGui.QMainWindow, self).__init__(parent)
|
|
||||||
self.resize(640,480)
|
|
||||||
self.setWindowTitle(u'simple media player')
|
|
||||||
self.show()
|
|
||||||
|
|
||||||
if __name__==u'__main__':
|
|
||||||
app = QtGui.QApplication([])
|
|
||||||
# widget = QtGui.QWidget()
|
|
||||||
# widget.resize(320, 240)
|
|
||||||
# widget.setWindowTitle(u'simple')
|
|
||||||
# widget.show()
|
|
||||||
# QCore.QCoreApplication.setApplicationName(u'OpenLP')
|
|
||||||
mainwindow=w()
|
|
||||||
widget=QtGui.QWidget(mainwindow)
|
|
||||||
mainwindow.setCentralWidget(widget)
|
|
||||||
widget.setLayout(QtGui.QVBoxLayout(widget))
|
|
||||||
# videofile=u'r-128.rm'
|
|
||||||
videofile=u'/extra_space/Download/coa360download56Kbps240x160.mpg'
|
|
||||||
source=Phonon.MediaSource(videofile)
|
|
||||||
|
|
||||||
media=Phonon.MediaObject(widget)
|
|
||||||
media.setCurrentSource(source)
|
|
||||||
|
|
||||||
video=Phonon.VideoWidget(widget)
|
|
||||||
audio=Phonon.AudioOutput(Phonon.MusicCategory)
|
|
||||||
# controller=Phonon.MediaController(media)
|
|
||||||
Phonon.createPath(media, video);
|
|
||||||
Phonon.createPath(media, audio);
|
|
||||||
# player=Phonon.VideoPlayer(Phonon.VideoCategory, widget)
|
|
||||||
slider=Phonon.SeekSlider(media, mainwindow)
|
|
||||||
widget.layout().addWidget(slider)
|
|
||||||
widget.layout().addWidget(video)
|
|
||||||
slider.show()
|
|
||||||
|
|
||||||
video.show()
|
|
||||||
media.play()
|
|
||||||
app.exec_()
|
|
Loading…
Reference in New Issue
Block a user