Replaced Phonon with QtMultimedia

preferencesAboutTextFull
Craig Watson 9 years ago
parent bedf11cc2d
commit cdb56333f3
  1. 8
      src/adaptors/UBSvgSubsetAdaptor.cpp
  2. 2
      src/domain/UBGraphicsItemDelegate.cpp
  3. 62
      src/domain/UBGraphicsMediaItem.cpp
  4. 23
      src/domain/UBGraphicsMediaItem.h
  5. 123
      src/domain/UBGraphicsMediaItemDelegate.cpp
  6. 14
      src/domain/UBGraphicsMediaItemDelegate.h
  7. 2
      src/domain/UBGraphicsScene.cpp

@ -1991,9 +1991,9 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::audioItemToLinkedAudio(UBGraphicsMed
graphicsItemToSvg(audioItem);
if (audioItem->mediaObject()->state() == Phonon::PausedState && audioItem->mediaObject()->remainingTime() > 0)
if (audioItem->mediaObject()->state() == QMediaPlayer::PausedState && (audioItem->mediaObject()->duration() - audioItem->mediaObject()->position()) > 0)
{
qint64 pos = audioItem->mediaObject()->currentTime();
qint64 pos = audioItem->mediaObject()->position();
mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "position", QString("%1").arg(pos));
}
@ -2020,9 +2020,9 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::videoItemToLinkedVideo(UBGraphicsMed
graphicsItemToSvg(videoItem);
if (videoItem->mediaObject()->state() == Phonon::PausedState && videoItem->mediaObject()->remainingTime() > 0)
if (videoItem->mediaObject()->state() == QMediaPlayer::PausedState && (videoItem->mediaObject()->duration() - videoItem->mediaObject()->position()) > 0)
{
qint64 pos = videoItem->mediaObject()->currentTime();
qint64 pos = videoItem->mediaObject()->position();
mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "position", QString("%1").arg(pos));
}

@ -1442,7 +1442,7 @@ void DelegateMediaControl::seekToMousePos(QPointF mousePos)
&& mDelegate->mediaObject() && mDelegate->mediaObject()->isSeekable())
{
qint64 tickPos = (mTotalTimeInMs/length)* (mouseX - minX);
mDelegate->mediaObject()->seek(tickPos);
mDelegate->mediaObject()->setPosition(tickPos);
//OSX is a bit lazy
updateTicker(tickPos);

@ -24,10 +24,12 @@
#include <QUrl>
#include "UBGraphicsGroupContainerItem.h"
#include "UBGraphicsMediaItem.h"
#include "UBGraphicsMediaItemDelegate.h"
#include "UBGraphicsItemDelegate.h"
#include "UBGraphicsScene.h"
#include "UBGraphicsDelegateFrame.h"
#include "document/UBDocumentProxy.h"
@ -49,7 +51,7 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte
{
update();
mMediaObject = new Phonon::MediaObject(this);
mMediaPlayer = new QMediaPlayer(this);
QString mediaPath = pMediaFileUrl.toString();
if ("" == mediaPath)
@ -59,10 +61,11 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte
{
mMediaType = mediaType_Video;
mAudioOutput = new Phonon::AudioOutput(Phonon::VideoCategory, this);
mMediaObject->setTickInterval(50);
mVideoWidget = new Phonon::VideoWidget(); // owned and destructed by the scene ...
Phonon::createPath(mMediaObject, mVideoWidget);
mAudioOutput = new QAudioOutput(QAudioFormat(), this);
mMediaPlayer->setNotifyInterval(50);
mVideoWidget = new QVideoWidget();
mMediaPlayer->setVideoOutput(mVideoWidget);
if(mVideoWidget->sizeHint() == QSize(1,1)){
mVideoWidget->resize(320,240);
@ -74,9 +77,9 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte
}
else if (mediaPath.toLower().contains("audios")){
mMediaType = mediaType_Audio;
mAudioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
mAudioOutput = new QAudioOutput(QAudioFormat(), this);
mMediaObject->setTickInterval(1000);
mMediaPlayer->setNotifyInterval(1000);
mAudioWidget = new QWidget();
mAudioWidget->resize(320,26);
mAudioWidget->setMinimumSize(150,26);
@ -84,15 +87,8 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte
haveLinkedImage = false;
}
Phonon::createPath(mMediaObject, mAudioOutput);
mSource = Phonon::MediaSource(pMediaFileUrl);
mMediaObject->setCurrentSource(mSource);
// we should create delegate after media objects because delegate uses his properties at creation.
setDelegate(new UBGraphicsMediaItemDelegate(this, mMediaObject));
setDelegate(new UBGraphicsMediaItemDelegate(this, mMediaPlayer));
// delegate should be created earler because we setWidget calls resize event for graphics proxy widgt.
// resize uses delegate.
@ -113,15 +109,18 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly
connect(Delegate(), SIGNAL(showOnDisplayChanged(bool)), this, SLOT(showOnDisplayChanged(bool)));
connect(mMediaObject, SIGNAL(hasVideoChanged(bool)), this, SLOT(hasMediaChanged(bool)));
connect(Delegate(), &UBGraphicsItemDelegate::showOnDisplayChanged,
this, &UBGraphicsMediaItem::showOnDisplayChanged);
connect(mMediaPlayer, &QMediaPlayer::videoAvailableChanged,
this, &UBGraphicsMediaItem::hasMediaChanged);
}
UBGraphicsMediaItem::~UBGraphicsMediaItem()
{
if (mMediaObject)
mMediaObject->stop();
if (mMediaPlayer)
mMediaPlayer->stop();
}
@ -143,13 +142,13 @@ QVariant UBGraphicsMediaItem::itemChange(GraphicsItemChange change, const QVaria
|| (change == QGraphicsItem::ItemSceneChange)
|| (change == QGraphicsItem::ItemVisibleChange))
{
if (mMediaObject && (!isEnabled() || !isVisible() || !scene()))
mMediaObject->pause();
if (mMediaPlayer && (!isEnabled() || !isVisible() || !scene()))
mMediaPlayer->pause();
}
else if (change == QGraphicsItem::ItemSceneHasChanged)
{
if (!scene())
mMediaObject->stop();
mMediaPlayer->stop();
else {
QString absoluteMediaFilename;
@ -159,7 +158,7 @@ QVariant UBGraphicsMediaItem::itemChange(GraphicsItemChange change, const QVaria
absoluteMediaFilename = mMediaFileUrl.toLocalFile();
if (absoluteMediaFilename.length() > 0)
mMediaObject->setCurrentSource(Phonon::MediaSource(absoluteMediaFilename));
mMediaPlayer->setMedia(QUrl::fromLocalFile(absoluteMediaFilename));
}
}
@ -193,7 +192,12 @@ void UBGraphicsMediaItem::toggleMute()
void UBGraphicsMediaItem::setMute(bool bMute)
{
mMuted = bMute;
mAudioOutput->setMuted(mMuted);
if (bMute)
mAudioOutput->setVolume(0);
else
mAudioOutput->setVolume(mVolume);
mMutedByUserAction = mMuted;
sIsMutedByDefault = mMuted;
}
@ -201,9 +205,9 @@ void UBGraphicsMediaItem::setMute(bool bMute)
void UBGraphicsMediaItem::hasMediaChanged(bool hasMedia)
{
if(hasMedia && mMediaObject->isSeekable())
if(hasMedia && mMediaPlayer->isSeekable())
{
mMediaObject->seek(mInitialPos);
mMediaPlayer->setPosition(mInitialPos);
UBGraphicsMediaItemDelegate *med = dynamic_cast<UBGraphicsMediaItemDelegate *>(Delegate());
if (med)
med->updateTicker(initialPos());
@ -220,7 +224,7 @@ UBGraphicsScene* UBGraphicsMediaItem::scene()
void UBGraphicsMediaItem::activeSceneChanged()
{
if (UBApplication::boardController->activeScene() != scene())
mMediaObject->pause();
mMediaPlayer->pause();
}
@ -229,12 +233,12 @@ void UBGraphicsMediaItem::showOnDisplayChanged(bool shown)
if (!shown)
{
mMuted = true;
mAudioOutput->setMuted(mMuted);
mAudioOutput->setVolume(0);
}
else if (!mMutedByUserAction)
{
mMuted = false;
mAudioOutput->setMuted(mMuted);
mAudioOutput->setVolume(mVolume);
}
}

@ -28,10 +28,12 @@
#ifndef UBGRAPHICSMEDIAITEM_H
#define UBGRAPHICSMEDIAITEM_H
#include <QAudioOutput>
#include <QMediaPlayer>
#include <QVideoWidget>
#include "UBGraphicsProxyWidget.h"
#include <phonon/AudioOutput>
#include <phonon/MediaObject>
#include <phonon/VideoWidget>
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "frameworks/UBFileSystemUtils.h"
@ -63,9 +65,9 @@ public:
virtual void mediaFileUrl(QUrl url){mMediaFileUrl=url;}
Phonon::MediaObject* mediaObject() const
QMediaPlayer* mediaObject() const
{
return mMediaObject;
return mMediaPlayer;
}
void setInitialPos(qint64 p) {
@ -80,7 +82,7 @@ public:
return mMuted;
}
Phonon::VideoWidget* videoWidget() const
QVideoWidget* videoWidget() const
{
return mVideoWidget;
}
@ -115,10 +117,10 @@ protected:
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void clearSource();
Phonon::MediaObject *mMediaObject;
Phonon::VideoWidget *mVideoWidget;
Phonon::AudioOutput *mAudioOutput;
Phonon::MediaSource mSource;
QMediaPlayer* mMediaPlayer;
QVideoWidget* mVideoWidget;
QAudioOutput* mAudioOutput;
QWidget *mAudioWidget;
private:
@ -126,6 +128,7 @@ private:
bool mMuted;
bool mMutedByUserAction;
static bool sIsMutedByDefault;
qreal mVolume;
QUrl mMediaFileUrl;
QString mMediaSource;

@ -43,7 +43,7 @@
#include "core/memcheck.h"
UBGraphicsMediaItemDelegate::UBGraphicsMediaItemDelegate(UBGraphicsMediaItem* pDelegated, Phonon::MediaObject* pMedia, QObject * parent)
UBGraphicsMediaItemDelegate::UBGraphicsMediaItemDelegate(UBGraphicsMediaItem* pDelegated, QMediaPlayer* pMedia, QObject * parent)
: UBGraphicsItemDelegate(pDelegated, parent, GF_COMMON
| GF_RESPECT_RATIO
| GF_TOOLBAR_USED
@ -56,11 +56,22 @@ UBGraphicsMediaItemDelegate::UBGraphicsMediaItemDelegate(UBGraphicsMediaItem* pD
QPalette palette;
palette.setBrush ( QPalette::Light, Qt::darkGray );
mMedia->setTickInterval(50);
connect(mMedia, SIGNAL(stateChanged (Phonon::State, Phonon::State)), this, SLOT(mediaStateChanged (Phonon::State, Phonon::State)));
connect(mMedia, SIGNAL(finished()), this, SLOT(updatePlayPauseState()));
connect(mMedia, SIGNAL(tick(qint64)), this, SLOT(updateTicker(qint64)));
connect(mMedia, SIGNAL(totalTimeChanged(qint64)), this, SLOT(totalTimeChanged(qint64)));
mMedia->setNotifyInterval(50);
connect(mMedia, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
this, SLOT(mediaStatusChanged(QMediaPlayer::MediaStatus)));
connect(mMedia, SIGNAL(stateChanged(QMediaPlayer::State)),
this, SLOT(mediaStateChanged(QMediaPlayer::State)));
connect(mMedia, static_cast<void(QMediaPlayer::*)(QMediaPlayer::Error)>(&QMediaPlayer::error),
this, &UBGraphicsMediaItemDelegate::mediaError);
connect(mMedia, SIGNAL(positionChanged(qint64)),
this, SLOT(updateTicker(qint64)));
connect(mMedia, SIGNAL(durationChanged(qint64)),
this, SLOT(totalTimeChanged(qint64)));
if (delegated()->hasLinkedImage())
{
@ -95,10 +106,12 @@ void UBGraphicsMediaItemDelegate::buildButtons()
{
if(!mPlayPauseButton){
mPlayPauseButton = new DelegateButton(":/images/play.svg", mDelegated, mToolBarItem, Qt::TitleBarArea);
connect(mPlayPauseButton, SIGNAL(clicked(bool)), this, SLOT(togglePlayPause()));
connect(mPlayPauseButton, SIGNAL(clicked(bool)),
this, SLOT(togglePlayPause()));
mStopButton = new DelegateButton(":/images/stop.svg", mDelegated, mToolBarItem, Qt::TitleBarArea);
connect(mStopButton, SIGNAL(clicked(bool)), mMedia, SLOT(stop()));
connect(mStopButton, SIGNAL(clicked(bool)),
mMedia, SLOT(stop()));
mMediaControl = new DelegateMediaControl(delegated(), mToolBarItem);
mMediaControl->setFlag(QGraphicsItem::ItemIsSelectable, true);
@ -109,8 +122,10 @@ void UBGraphicsMediaItemDelegate::buildButtons()
else
mMuteButton = new DelegateButton(":/images/soundOn.svg", mDelegated, mToolBarItem, Qt::TitleBarArea);
connect(mMuteButton, SIGNAL(clicked(bool)), delegated(), SLOT(toggleMute()));
connect(mMuteButton, SIGNAL(clicked(bool)), this, SLOT(toggleMute())); // for changing button image
connect(mMuteButton, SIGNAL(clicked(bool)),
delegated(), SLOT(toggleMute()));
connect(mMuteButton, SIGNAL(clicked(bool)),
this, SLOT(toggleMute())); // for changing button image
mToolBarButtons << mPlayPauseButton << mStopButton << mMuteButton;
@ -120,10 +135,17 @@ void UBGraphicsMediaItemDelegate::buildButtons()
if (mToolBarShowTimer)
{
connect(mPlayPauseButton, SIGNAL(clicked(bool)), mToolBarShowTimer, SLOT(start()));
connect(mStopButton, SIGNAL(clicked(bool)), mToolBarShowTimer, SLOT(start()));
connect(mMediaControl, SIGNAL(used()), mToolBarShowTimer, SLOT(start()));
connect(mMuteButton, SIGNAL(clicked(bool)), mToolBarShowTimer, SLOT(start()));
connect(mPlayPauseButton, SIGNAL(clicked(bool)),
mToolBarShowTimer, SLOT(start()));
connect(mStopButton, SIGNAL(clicked(bool)),
mToolBarShowTimer, SLOT(start()));
connect(mMediaControl, SIGNAL(used()),
mToolBarShowTimer, SLOT(start()));
connect(mMuteButton, SIGNAL(clicked(bool)),
mToolBarShowTimer, SLOT(start()));
}
@ -195,55 +217,82 @@ UBGraphicsMediaItem* UBGraphicsMediaItemDelegate::delegated()
return dynamic_cast<UBGraphicsMediaItem*>(mDelegated);
}
void UBGraphicsMediaItemDelegate::togglePlayPause()
{
if (delegated() && delegated()->mediaObject()) {
Phonon::MediaObject* media = delegated()->mediaObject();
if (media->state() == Phonon::StoppedState) {
QMediaPlayer * media = delegated()->mediaObject();
if (media->state() == QMediaPlayer::StoppedState)
media->play();
} else if (media->state() == Phonon::PlayingState) {
if (media->remainingTime() <= 0) {
else if (media->state() == QMediaPlayer::PlayingState) {
if ((media->duration() - media->position()) <= 0) {
media->stop();
media->play();
} else {
}
else {
media->pause();
if(delegated()->scene())
delegated()->scene()->setModified(true);
}
} else if (media->state() == Phonon::PausedState) {
if (media->remainingTime() <= 0) {
media->stop();
}
else if (media->state() == QMediaPlayer::PausedState) {
if ((media->duration() - media->position()) <= 0)
media->stop();
media->play();
} else if ( media->state() == Phonon::LoadingState ) {
delegated()->mediaObject()->setCurrentSource(delegated()->mediaFileUrl());
}
else if ( media->mediaStatus() == QMediaPlayer::LoadingMedia) {
delegated()->mediaObject()->setMedia(delegated()->mediaFileUrl());
media->play();
} else if (media->state() == Phonon::ErrorState){
qDebug() << "Error appeared." << media->errorString();
}
else if (media->error())
qDebug() << "Error appeared." << media->errorString();
}
}
void UBGraphicsMediaItemDelegate::mediaStateChanged ( Phonon::State newstate, Phonon::State oldstate )
void UBGraphicsMediaItemDelegate::mediaStatusChanged(QMediaPlayer::MediaStatus status)
{
Q_UNUSED(newstate);
Q_UNUSED(oldstate);
// Possible statuses are: UnknownMediaStatus, NoMedia, LoadingMedia, LoadedMedia,
// StalledMedia, BufferingMedia, BufferedMedia, EndOfMedia, InvalidMedia
if (oldstate == Phonon::LoadingState)
{
mMediaControl->totalTimeChanged(delegated()->mediaObject()->totalTime());
if (status == QMediaPlayer::LoadedMedia)
mMediaControl->totalTimeChanged(delegated()->mediaObject()->duration());
// in most cases, the only necessary action is to update the play/pause state
updatePlayPauseState();
}
void UBGraphicsMediaItemDelegate::mediaStateChanged(QMediaPlayer::State state)
{
// Possible states are StoppedState, PlayingState and PausedState
// updatePlayPauseState handles this functionality
updatePlayPauseState();
}
void UBGraphicsMediaItemDelegate::mediaError(QMediaPlayer::Error error)
{
// Possible errors are NoError, ResourceError, FormatError, NetworkError, AccessDeniedError,
// ServiceMissingError
Q_UNUSED(error);
qDebug() << "Error appeared." << mMedia->errorString();
}
void UBGraphicsMediaItemDelegate::updatePlayPauseState()
{
Phonon::MediaObject* media = delegated()->mediaObject();
QMediaPlayer * media = delegated()->mediaObject();
if (media->state() == Phonon::PlayingState)
if (media->state() == QMediaPlayer::PlayingState)
mPlayPauseButton->setFileName(":/images/pause.svg");
else
mPlayPauseButton->setFileName(":/images/play.svg");
@ -252,8 +301,8 @@ void UBGraphicsMediaItemDelegate::updatePlayPauseState()
void UBGraphicsMediaItemDelegate::updateTicker(qint64 time)
{
Phonon::MediaObject* media = delegated()->mediaObject();
mMediaControl->totalTimeChanged(media->totalTime());
QMediaPlayer* media = delegated()->mediaObject();
mMediaControl->totalTimeChanged(media->duration());
mMediaControl->updateTicker(time);
}

@ -29,8 +29,8 @@
#define UBGRAPHICSMEDIAITEMDELEGATE_H_
#include <QtGui>
#include <phonon/MediaObject>
#include <QTimer>
#include <QtMultimedia>
#include "core/UB.h"
#include "UBGraphicsItemDelegate.h"
@ -43,7 +43,7 @@ class UBGraphicsMediaItemDelegate : public UBGraphicsItemDelegate
Q_OBJECT
public:
UBGraphicsMediaItemDelegate(UBGraphicsMediaItem* pDelegated, Phonon::MediaObject* pMedia, QObject * parent = 0);
UBGraphicsMediaItemDelegate(UBGraphicsMediaItem* pDelegated, QMediaPlayer* pMedia, QObject * parent = 0);
virtual ~UBGraphicsMediaItemDelegate();
virtual void positionHandles();
@ -61,14 +61,18 @@ class UBGraphicsMediaItemDelegate : public UBGraphicsItemDelegate
void togglePlayPause();
void mediaStateChanged ( Phonon::State newstate, Phonon::State oldstate );
void updatePlayPauseState();
void totalTimeChanged(qint64 newTotalTime);
void hideToolBar();
void mediaStatusChanged(QMediaPlayer::MediaStatus status);
void mediaStateChanged(QMediaPlayer::State state);
void mediaError(QMediaPlayer::Error error);
protected:
virtual void buildButtons();
@ -79,7 +83,7 @@ class UBGraphicsMediaItemDelegate : public UBGraphicsItemDelegate
DelegateButton* mMuteButton;
DelegateMediaControl* mMediaControl;
Phonon::MediaObject* mMedia;
QMediaPlayer* mMedia; // mMedia belongs to the associated UBGraphicsMediaItem (mDelegated)
QTimer* mToolBarShowTimer;
int m_iToolBarShowingInterval;

@ -1340,7 +1340,7 @@ UBGraphicsMediaItem* UBGraphicsScene::addMedia(const QUrl& pMediaFileUrl, bool s
if (!shouldPlayAsap)
{
mediaItem->mediaObject()->pause();
mediaItem->mediaObject()->seek(0);
mediaItem->mediaObject()->setPosition(0);
}
setDocumentUpdated();

Loading…
Cancel
Save