diff options
author | Eike Ziller <eike.ziller@nokia.com> | 2011-07-25 09:12:10 (GMT) |
---|---|---|
committer | Eike Ziller <eike.ziller@nokia.com> | 2011-07-25 09:17:23 (GMT) |
commit | 58d34f97594d9cbb8c7b60d05c5226f70d286be0 (patch) | |
tree | 5720ed6f1b7ac406a71f71558482e250eb0e826b /src | |
parent | 4bac95354ba73cdbe69f3dfface799fd5fc92c77 (diff) | |
download | Qt-58d34f97594d9cbb8c7b60d05c5226f70d286be0.zip Qt-58d34f97594d9cbb8c7b60d05c5226f70d286be0.tar.gz Qt-58d34f97594d9cbb8c7b60d05c5226f70d286be0.tar.bz2 |
Add some sound support to the uikit platform.
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/platforms/uikit/README | 7 | ||||
-rw-r--r-- | src/plugins/platforms/uikit/phonon_av/avaudiooutput.cpp | 73 | ||||
-rw-r--r-- | src/plugins/platforms/uikit/phonon_av/avaudiooutput.h | 68 | ||||
-rw-r--r-- | src/plugins/platforms/uikit/phonon_av/avbackend.cpp | 127 | ||||
-rw-r--r-- | src/plugins/platforms/uikit/phonon_av/avbackend.h | 73 | ||||
-rw-r--r-- | src/plugins/platforms/uikit/phonon_av/avmediaobject.h | 123 | ||||
-rw-r--r-- | src/plugins/platforms/uikit/phonon_av/avmediaobject.mm | 298 | ||||
-rw-r--r-- | src/plugins/platforms/uikit/phonon_av/phonon_av.pro | 31 | ||||
-rw-r--r-- | src/plugins/platforms/uikit/platform.pro | 27 | ||||
-rw-r--r-- | src/plugins/platforms/uikit/uikit.pro | 29 |
10 files changed, 827 insertions, 29 deletions
diff --git a/src/plugins/platforms/uikit/README b/src/plugins/platforms/uikit/README index ffd31df..8b43201 100644 --- a/src/plugins/platforms/uikit/README +++ b/src/plugins/platforms/uikit/README @@ -18,11 +18,11 @@ After configuring and building Qt you need to also build src/plugins/platforms/u Simulator: ---------- -configure -qpa -xplatform qpa/macx-iphonesimulator-g++ -arch i386 -developer-build -opengl es2 -no-accessibility -no-qt3support -no-multimedia -no-phonon -no-phonon-backend -no-svg -no-webkit -no-scripttools -no-openssl -no-sql-mysql -no-sql-odbc -no-cups -no-iconv -no-dbus -static -nomake tools -nomake demos -nomake docs -nomake examples -nomake translations +configure -qpa -xplatform qpa/macx-iphonesimulator-g++ -arch i386 -developer-build -opengl es2 -no-accessibility -no-qt3support -no-multimedia -no-phonon-backend -no-svg -no-webkit -no-scripttools -no-openssl -no-sql-mysql -no-sql-odbc -no-cups -no-iconv -no-dbus -static -nomake tools -nomake demos -nomake docs -nomake examples -nomake translations Device: ------- -configure -qpa -xplatform qpa/macx-iphonedevice-g++ -arch armv7 -developer-build -release -opengl es2 -no-accessibility -no-qt3support -no-multimedia -no-phonon -no-phonon-backend -no-svg -no-webkit -no-scripttools -no-openssl -no-sql-mysql -no-sql-odbc -no-cups -no-iconv -no-dbus -static -nomake tools -nomake demos -nomake docs -nomake examples -nomake translations +configure -qpa -xplatform qpa/macx-iphonedevice-g++ -arch armv7 -developer-build -release -opengl es2 -no-accessibility -no-qt3support -no-multimedia -no-phonon-backend -no-svg -no-webkit -no-scripttools -no-openssl -no-sql-mysql -no-sql-odbc -no-cups -no-iconv -no-dbus -static -nomake tools -nomake demos -nomake docs -nomake examples -nomake translations 2) XCode setup: - there are examples in the examples subdirectory of the platform plugin @@ -40,6 +40,9 @@ configure -qpa -xplatform qpa/macx-iphonedevice-g++ -arch armv7 -developer-build - add "$(SRCROOT)/../qmltest" to the include search path if you didn't copy but linked to the qmlapplicationviewer - for device set the architecture to armv7 only + - to use sound in your application, Q_IMPORT_PLUGIN(phonon_av), + #include <phonon/private/factory_p.h>, + and call Phonon::Factory::setBackend(qt_plugin_instance_phonon_av()); 3) Done: Build and Run. diff --git a/src/plugins/platforms/uikit/phonon_av/avaudiooutput.cpp b/src/plugins/platforms/uikit/phonon_av/avaudiooutput.cpp new file mode 100644 index 0000000..97ab6c9 --- /dev/null +++ b/src/plugins/platforms/uikit/phonon_av/avaudiooutput.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "avaudiooutput.h" + +AVAudioOutput::AVAudioOutput(QObject *parent) + : QObject(parent), + m_volume(1.) +{ +} + +AVAudioOutput::~AVAudioOutput() +{ +} + +qreal AVAudioOutput::volume() const +{ + return m_volume; +} + +void AVAudioOutput::setVolume(qreal value) +{ + m_volume = value; + emit volumeChanged(value); +} + +int AVAudioOutput::outputDevice() const +{ + return 0; +} + +bool AVAudioOutput::setOutputDevice(int newDevice) +{ + return (newDevice == 0); +} diff --git a/src/plugins/platforms/uikit/phonon_av/avaudiooutput.h b/src/plugins/platforms/uikit/phonon_av/avaudiooutput.h new file mode 100644 index 0000000..4b08b06 --- /dev/null +++ b/src/plugins/platforms/uikit/phonon_av/avaudiooutput.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef AV_AUDIOOUTPUT_H +#define AV_AUDIOOUTPUT_H + +#include <phonon/audiooutputinterface.h> +#include <QtCore/QObject> + +class AVAudioOutput : public QObject, public Phonon::AudioOutputInterface +{ + Q_OBJECT + Q_INTERFACES(Phonon::AudioOutputInterface) +public: + AVAudioOutput(QObject *parent); + ~AVAudioOutput(); + + qreal volume() const; + void setVolume(qreal value); + int outputDevice() const; + bool setOutputDevice(int newDevice); + +Q_SIGNALS: + void audioDeviceFailed(); + void volumeChanged(qreal); +private: + qreal m_volume; +}; + +#endif // AV_AUDIOOUTPUT_H diff --git a/src/plugins/platforms/uikit/phonon_av/avbackend.cpp b/src/plugins/platforms/uikit/phonon_av/avbackend.cpp new file mode 100644 index 0000000..ba1f808 --- /dev/null +++ b/src/plugins/platforms/uikit/phonon_av/avbackend.cpp @@ -0,0 +1,127 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "avbackend.h" +#include "avaudiooutput.h" +#include "avmediaobject.h" + +#include <QtCore/QSet> +#include <QtCore/QSettings> +#include <QtCore/QStringList> +#include <QtCore/QVariant> + +#include <QtCore/QtPlugin> + +AVBackend::AVBackend(QObject *parent) + : QObject(parent) +{ +} + +AVBackend::~AVBackend() +{ +} + +QObject *AVBackend::createObject(BackendInterface::Class c, QObject *parent, const QList<QVariant> &args) +{ + Q_UNUSED(args); + switch (c) + { + case MediaObjectClass: + return new AVMediaObject(parent); + case AudioOutputClass: + return new AVAudioOutput(parent); + default: + return 0; + } +} + +QList<int> AVBackend::objectDescriptionIndexes(Phonon::ObjectDescriptionType type) const +{ + if (type == Phonon::AudioOutputDeviceType) + return QList<int>() << 0; + return QList<int>(); +} + +QHash<QByteArray, QVariant> AVBackend::objectDescriptionProperties(Phonon::ObjectDescriptionType type, int index) const +{ + Q_UNUSED(index); + QHash<QByteArray, QVariant> r; + if (type == Phonon::AudioOutputDeviceType) + r["name"] = QLatin1String("AVAudioPlayer"); + return r; +} + +bool AVBackend::startConnectionChange(QSet<QObject *> connection) +{ + Q_UNUSED(connection) + return true; +} + +bool AVBackend::connectNodes(QObject *node1, QObject *node2) +{ + AVMediaObject *media = qobject_cast<AVMediaObject*>(node1); + AVAudioOutput *output = qobject_cast<AVAudioOutput*>(node2); + if (media && output) + media->setAudioOutput(output); + return true; +} + +bool AVBackend::disconnectNodes(QObject *node1, QObject *node2) +{ + AVMediaObject *media = qobject_cast<AVMediaObject*>(node1); + AVAudioOutput *output = qobject_cast<AVAudioOutput*>(node2); + if (media && output) + media->setAudioOutput(0); + return true; +} + +bool AVBackend::endConnectionChange(QSet<QObject *> connection) +{ + Q_UNUSED(connection) + return true; +} + +QStringList AVBackend::availableMimeTypes() const +{ + return QStringList(); +} + +Q_EXPORT_PLUGIN2(phonon_av, AVBackend) diff --git a/src/plugins/platforms/uikit/phonon_av/avbackend.h b/src/plugins/platforms/uikit/phonon_av/avbackend.h new file mode 100644 index 0000000..cfb1bfc --- /dev/null +++ b/src/plugins/platforms/uikit/phonon_av/avbackend.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef AV_BACKEND_H +#define AV_BACKEND_H + +#include <phonon/backendinterface.h> +#include <phonon/phononnamespace.h> + +#include <QtCore/QList> + +class AVAudioOutput; +class AVMediaObject; + +class AVBackend : public QObject, public Phonon::BackendInterface +{ + Q_OBJECT + Q_INTERFACES(Phonon::BackendInterface) +public: + AVBackend(QObject *parent = 0); + ~AVBackend(); + + QObject *createObject(Phonon::BackendInterface::Class, QObject *parent, const QList<QVariant> &args); + QList<int> objectDescriptionIndexes(Phonon::ObjectDescriptionType type) const; + QHash<QByteArray, QVariant> objectDescriptionProperties(Phonon::ObjectDescriptionType type, int index) const; + + bool startConnectionChange(QSet<QObject *> connection); + bool connectNodes(QObject *node1, QObject *node2); + bool disconnectNodes(QObject *node1, QObject *node2); + bool endConnectionChange(QSet<QObject *> connection); + + QStringList availableMimeTypes() const; +}; + +#endif // AV_BACKEND_H diff --git a/src/plugins/platforms/uikit/phonon_av/avmediaobject.h b/src/plugins/platforms/uikit/phonon_av/avmediaobject.h new file mode 100644 index 0000000..0ca900e --- /dev/null +++ b/src/plugins/platforms/uikit/phonon_av/avmediaobject.h @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef AV_MEDIAOBJECT_H +#define AV_MEDIAOBJECT_H + +#include <phonon/mediaobjectinterface.h> + +#include <QtCore/QMultiMap> + +class AVAudioOutput; +class AVMediaObjectPrivate; + +using namespace Phonon; + +class AVMediaObject : public QObject, public Phonon::MediaObjectInterface +{ + Q_OBJECT + Q_INTERFACES(Phonon::MediaObjectInterface) + +public: + AVMediaObject(QObject *parent); + ~AVMediaObject(); + void play(); + void pause(); + void stop(); + void seek(qint64 milliseconds); + qint32 tickInterval() const; + void setTickInterval(qint32 newTickInterval); + bool hasVideo() const; + bool isSeekable() const; + qint64 currentTime() const; + Phonon::State state() const; + QString errorString() const; + Phonon::ErrorType errorType() const; + qint64 totalTime() const; + Phonon::MediaSource source() const; + void setSource(const Phonon::MediaSource &source); + void setNextSource(const Phonon::MediaSource &source); + + qint32 prefinishMark() const; + void setPrefinishMark(qint32 newPrefinishMark); + qint32 transitionTime() const; + void setTransitionTime(qint32); + +Q_SIGNALS: + void stateChanged(Phonon::State newstate, Phonon::State oldstate); + void totalTimeChanged(qint64 length); + void currentSourceChanged(const MediaSource&); + void aboutToFinish(); + void finished(); + //TODO + void tick(qint64 time); + +// unused + void seekableChanged(bool); + void hasVideoChanged(bool); + void bufferStatus(int); + void prefinishMarkReached(qint32); + void metaDataChanged(const QMultiMap<QString, QString> &); + +public: + void setAudioOutput(AVAudioOutput *audioOutput); + void handlePlayerFinished(); + +private Q_SLOTS: + void setVolume(qreal newVolume); + +private: + void changeState(Phonon::State state); + bool checkPlayer() const; + + qint32 m_tickInterval; + Phonon::State m_state; + mutable QString m_errorString; + mutable Phonon::ErrorType m_errorType; + Phonon::MediaSource m_mediaSource; + + AVAudioOutput *m_output; + AVMediaObjectPrivate *d; +}; + +QT_END_NAMESPACE + +#endif // PHONON_MEDIAOBJECT_H diff --git a/src/plugins/platforms/uikit/phonon_av/avmediaobject.mm b/src/plugins/platforms/uikit/phonon_av/avmediaobject.mm new file mode 100644 index 0000000..39d062b --- /dev/null +++ b/src/plugins/platforms/uikit/phonon_av/avmediaobject.mm @@ -0,0 +1,298 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "avmediaobject.h" +#include "avaudiooutput.h" + +#include <QtCore/QUrl> +#import <Foundation/NSString.h> +#import <Foundation/NSURL.h> +#import <AVFoundation/AVAudioPlayer.h> + +@interface AudioPlayerDelegate : NSObject <AVAudioPlayerDelegate> { + AVMediaObject *mediaObject; +} + +- (id)initWithMediaObject:(AVMediaObject *)obj; +- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag; + +@end + +@implementation AudioPlayerDelegate + +- (id)initWithMediaObject:(AVMediaObject *)obj +{ + if (self = [self init]) { + mediaObject = obj; + } + return self; +} + +- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag +{ + Q_UNUSED(flag) + Q_UNUSED(player) + mediaObject->handlePlayerFinished(); +} + +@end + +class AVMediaObjectPrivate { +public: + AVMediaObjectPrivate(AVMediaObject *parent) + : player(0) + { + delegate = [[AudioPlayerDelegate alloc] initWithMediaObject:parent]; + } + ~AVMediaObjectPrivate() + { + [delegate release]; + } + + AVAudioPlayer *player; + AudioPlayerDelegate *delegate; +}; + +AVMediaObject::AVMediaObject(QObject *parent) + : QObject(parent), + m_tickInterval(0), + m_state(Phonon::LoadingState), + m_errorType(Phonon::NoError), + m_output(0), + d(new AVMediaObjectPrivate(this)) +{ +} + +AVMediaObject::~AVMediaObject() +{ + if (m_state == Phonon::PlayingState) + stop(); + [d->player release]; + delete d; +} + +void AVMediaObject::changeState(Phonon::State state) +{ + if (m_state == state) + return; + Phonon::State oldState = m_state; + m_state = state; + emit stateChanged(m_state, oldState); +} + +bool AVMediaObject::checkPlayer() const +{ + if (!d->player) { + m_errorType = Phonon::NormalError; + m_errorString = tr("Media source has not been set."); + return false; + } + return true; +} + +void AVMediaObject::play() +{ + if (!checkPlayer()) + return; + if (![d->player play]) { + m_errorType = Phonon::NormalError; + m_errorString = tr("Failed to play media source."); + return; + } + changeState(Phonon::PlayingState); +} + +void AVMediaObject::pause() +{ + if (!checkPlayer()) + return; + [d->player pause]; + changeState(Phonon::PausedState); +} + +void AVMediaObject::stop() +{ + if (!checkPlayer()) + return; + [d->player stop]; + d->player.currentTime = 0; + changeState(Phonon::StoppedState); +} + +void AVMediaObject::seek(qint64 milliseconds) +{ + if (!checkPlayer()) + return; + d->player.currentTime = milliseconds/1000.; +} + +qint32 AVMediaObject::tickInterval() const +{ + return m_tickInterval; +} + +void AVMediaObject::setTickInterval(qint32 newTickInterval) +{ + m_tickInterval = newTickInterval; + //TODO +} + +bool AVMediaObject::hasVideo() const +{ + return false; +} + +bool AVMediaObject::isSeekable() const +{ + return true; +} + +qint64 AVMediaObject::currentTime() const +{ + if (!checkPlayer()) + return 0; + return (qint64)(d->player.currentTime * 1000); +} + +Phonon::State AVMediaObject::state() const +{ + return m_state; +} + +QString AVMediaObject::errorString() const +{ + return m_errorString; +} + +Phonon::ErrorType AVMediaObject::errorType() const +{ + return m_errorType; +} + +qint64 AVMediaObject::totalTime() const +{ + if (!checkPlayer()) + return 0; + return d->player.duration; +} + +Phonon::MediaSource AVMediaObject::source() const +{ + return m_mediaSource; +} + +void AVMediaObject::setSource(const Phonon::MediaSource &source) +{ + if (d->player) { + stop(); + [d->player release]; + d->player = 0; + } + m_mediaSource = source; + NSString *urlString = [NSString stringWithCString:source.url().toEncoded().constData() + encoding:NSASCIIStringEncoding]; + NSURL *url = [NSURL URLWithString:urlString]; + d->player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:NULL]; + if (!d->player) { + m_errorString = tr("Failed to create player for '%1'").arg(source.url().toString()); + changeState(Phonon::ErrorState); + return; + } + d->player.delegate = d->delegate; + [d->player prepareToPlay]; + changeState(Phonon::StoppedState); + emit currentSourceChanged(m_mediaSource); + emit totalTimeChanged((qint64)(d->player.duration * 1000)); +} + +void AVMediaObject::setNextSource(const Phonon::MediaSource &source) +{ + setSource(source); +} + +qint32 AVMediaObject::prefinishMark() const +{ + // not implemented + return 0; +} + +void AVMediaObject::setPrefinishMark(qint32) +{ + // not implemented +} + +qint32 AVMediaObject::transitionTime() const +{ + // not implemented + return 0; +} + +void AVMediaObject::setTransitionTime(qint32) +{ + // not implemented +} + +void AVMediaObject::setAudioOutput(AVAudioOutput *audioOutput) +{ + if (m_output) { + disconnect(m_output, SIGNAL(volumeChanged(qreal)), this, SLOT(setVolume(qreal))); + } + m_output = audioOutput; + if (m_output) { + connect(m_output, SIGNAL(volumeChanged(qreal)), this, SLOT(setVolume(qreal))); + setVolume(m_output->volume()); + } +} + +void AVMediaObject::setVolume(qreal newVolume) +{ + if (!d->player) // do nothing, will be set when player is created + return; + [d->player setVolume:qMin((float)1.0, (float)newVolume)]; +} + +void AVMediaObject::handlePlayerFinished() +{ + emit aboutToFinish(); + changeState(Phonon::StoppedState); + emit finished(); + NSLog(@"finished!"); +} diff --git a/src/plugins/platforms/uikit/phonon_av/phonon_av.pro b/src/plugins/platforms/uikit/phonon_av/phonon_av.pro new file mode 100644 index 0000000..05af5a3 --- /dev/null +++ b/src/plugins/platforms/uikit/phonon_av/phonon_av.pro @@ -0,0 +1,31 @@ +DESTDIR = $$QT_BUILD_TREE/plugins/phonon_backend +QT += phonon +TARGET = phonon_av +include(../../../qpluginbase.pri) + +DEFINES += PHONON_MAKE_QT_ONLY_BACKEND + +HEADERS += avaudiooutput.h \ + avbackend.h \ + avmediaobject.h + +SOURCES += avaudiooutput.cpp \ + avbackend.cpp + +OBJECTIVE_SOURCES += avmediaobject.mm + +LIBS += -framework AVFoundation + +target.path = $$[QT_INSTALL_PLUGINS]/phonon_backend +INSTALLS += target + + + + + + + + + + + diff --git a/src/plugins/platforms/uikit/platform.pro b/src/plugins/platforms/uikit/platform.pro new file mode 100644 index 0000000..273c00d --- /dev/null +++ b/src/plugins/platforms/uikit/platform.pro @@ -0,0 +1,27 @@ +TARGET = quikit +include(../../qpluginbase.pri) +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforms + +QT += opengl + +OBJECTIVE_SOURCES = main.mm \ + quikitintegration.mm \ + quikitwindow.mm \ + quikitscreen.mm \ + quikiteventloop.mm \ + quikitwindowsurface.mm + +OBJECTIVE_HEADERS = quikitintegration.h \ + quikitwindow.h \ + quikitscreen.h \ + quikiteventloop.h \ + quikitwindowsurface.h + +HEADERS = quikitsoftwareinputhandler.h + +#add libz for freetype. +LIBS += -lz + +include(../fontdatabases/genericunix/genericunix.pri) +target.path += $$[QT_INSTALL_PLUGINS]/platforms +INSTALLS += target diff --git a/src/plugins/platforms/uikit/uikit.pro b/src/plugins/platforms/uikit/uikit.pro index 273c00d..5cfd8b8 100644 --- a/src/plugins/platforms/uikit/uikit.pro +++ b/src/plugins/platforms/uikit/uikit.pro @@ -1,27 +1,2 @@ -TARGET = quikit -include(../../qpluginbase.pri) -QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforms - -QT += opengl - -OBJECTIVE_SOURCES = main.mm \ - quikitintegration.mm \ - quikitwindow.mm \ - quikitscreen.mm \ - quikiteventloop.mm \ - quikitwindowsurface.mm - -OBJECTIVE_HEADERS = quikitintegration.h \ - quikitwindow.h \ - quikitscreen.h \ - quikiteventloop.h \ - quikitwindowsurface.h - -HEADERS = quikitsoftwareinputhandler.h - -#add libz for freetype. -LIBS += -lz - -include(../fontdatabases/genericunix/genericunix.pri) -target.path += $$[QT_INSTALL_PLUGINS]/platforms -INSTALLS += target +TEMPLATE = subdirs +SUBDIRS += platform.pro phonon_av |