File indexing completed on 2024-04-21 04:43:20

0001 /*  This file is part of the KDE project
0002     Copyright (C) 2004-2007 Matthias Kretz <kretz@kde.org>
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Lesser General Public
0006     License as published by the Free Software Foundation; either
0007     version 2.1 of the License, or (at your option) version 3, or any
0008     later version accepted by the membership of KDE e.V. (or its
0009     successor approved by the membership of KDE e.V.), Nokia Corporation 
0010     (or its successors, if any) and the KDE Free Qt Foundation, which shall
0011     act as a proxy defined in Section 6 of version 3 of the license.
0012 
0013     This library is distributed in the hope that it will be useful,
0014     but WITHOUT ANY WARRANTY; without even the implied warranty of
0015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0016     Lesser General Public License for more details.
0017 
0018     You should have received a copy of the GNU Lesser General Public 
0019     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0020 
0021 */
0022 
0023 #ifndef Phonon_VIDEOPLAYER_H
0024 #define Phonon_VIDEOPLAYER_H
0025 
0026 #include "phonon_export.h"
0027 #include "phononnamespace.h"
0028 #include "mediasource.h"
0029 #include <QWidget>
0030 
0031 
0032 #ifndef QT_NO_PHONON_VIDEOPLAYER
0033 
0034 namespace Phonon
0035 {
0036 class VideoPlayerPrivate;
0037 class MediaObject;
0038 class AudioOutput;
0039 class VideoWidget;
0040 
0041 /** \class VideoPlayer videoplayer.h phonon/VideoPlayer
0042  * \short Playback class for simple tasks.
0043  *
0044  * With %VideoPlayer you can get results quickly and easily. You can do the standard
0045  * playback tasks like play, pause and stop, but also set a playback volume and
0046  * seek (there's no guarantee that the seek will work, though).
0047  *
0048  * Keep in mind that when the %VideoPlayer instance is deleted the playback will
0049  * stop.
0050  *
0051  * A play and forget code example:
0052  * \code
0053  * VideoPlayer *player = new VideoPlayer(parentWidget);
0054  * connect(player, SIGNAL(finished()), player, SLOT(deleteLater()));
0055  * player->play(url);
0056  * \endcode
0057  *
0058  * \ingroup Playback
0059  * \ingroup PhononVideo
0060  * \author Matthias Kretz <kretz@kde.org>
0061  */
0062 class PHONON_EXPORT VideoPlayer : public QWidget
0063 {
0064     Q_OBJECT
0065     public:
0066         /**
0067          * Constructs a new %VideoPlayer instance.
0068          *
0069          * \param category The category used for the audio output device.
0070          * \param parent The QObject parent.
0071          */
0072         explicit VideoPlayer(Phonon::Category category, QWidget *parent = nullptr);
0073 
0074         /**
0075          * Constructs a new video widget with a \p parent
0076          * using Phonon::VideoCategory as its category.
0077          *
0078          * \param parent The QObject parent.
0079          */
0080         VideoPlayer(QWidget *parent = nullptr);
0081 
0082         /**
0083          * On destruction the playback is stopped, also the audio output is
0084          * removed so that the desktop mixer will not show the application
0085          * anymore. If you need a persistent audio output don't use
0086          * %VideoPlayer but MediaObject, VideoPath and VideoOutput.
0087          */
0088         ~VideoPlayer() override;
0089 
0090         /**
0091          * Get the total time (in milliseconds) of the file currently being played.
0092          */
0093         qint64 totalTime() const;
0094         /**
0095          * Get the current time (in milliseconds) of the file currently being played.
0096          */
0097         qint64 currentTime() const;
0098         /**
0099          * This is the current volume of the output as voltage factor.
0100          *
0101          * 1.0 means 100%, 0.5 means 50% voltage/25% power, 0.0 means 0%
0102          */
0103         float volume() const;
0104 
0105         /**
0106          * \returns \c true if it is currently playing
0107          * \returns \c false if it is currently stopped or paused
0108          */
0109         bool isPlaying() const;
0110         /**
0111          * \returns \c true if it is currently paused
0112          * \returns \c false if it is currently playing or stopped
0113          */
0114         bool isPaused() const;
0115 
0116         /**
0117          * getter for the MediaObject.
0118          */
0119         MediaObject *mediaObject() const;
0120 
0121         /**
0122          * getter for the AudioOutput.
0123          */
0124         AudioOutput *audioOutput() const;
0125 
0126         /**
0127          * getter for the VideoWidget.
0128          */
0129         VideoWidget *videoWidget() const;
0130 
0131     public Q_SLOTS:
0132         /**
0133          * Starts preloading the media data and fill audiobuffers in the
0134          * backend.
0135          *
0136          * When there's already a media playing (or paused) it will be stopped
0137          * (the finished signal will not be emitted).
0138          */
0139         void load(const Phonon::MediaSource &source);
0140 
0141         /**
0142          * Play the media at the given URL. Starts playback as fast as possible.
0143          * This can take a considerable time depending on the URL and the
0144          * backend.
0145          *
0146          * If you need low latency between calling play() and the sound actually
0147          * starting to play on your output device you need to use MediaObject
0148          * and be able to set the URL before calling play(). Note that
0149          * \code
0150          * audioPlayer->load(url);
0151          * audioPlayer->play();
0152          * \endcode
0153          * doesn't make a difference: the application should be idle between the
0154          * load and play calls so that the backend can start preloading the
0155          * media and fill audio buffers.
0156          */
0157         void play(const Phonon::MediaSource &source);
0158 
0159         /**
0160          * Continues playback of a paused media. Restarts playback of a stopped
0161          * media.
0162          */
0163         void play();
0164         /**
0165          * Pauses the playback.
0166          */
0167         void pause();
0168         /**
0169          * Stops the playback.
0170          */
0171         void stop();
0172 
0173         /**
0174          * Seeks to the requested time. Note that the backend is free to ignore
0175          * the seek request if the media source isn't seekable.
0176          *
0177          * \param ms Time in milliseconds from the start of the media.
0178          */
0179         void seek(qint64 ms);
0180         /**
0181          * Sets the volume of the output as voltage factor.
0182          *
0183          * 1.0 means 100%, 0.5 means 50% voltage/25% power, 0.0 means 0%
0184          */
0185         void setVolume(float volume);
0186 
0187     Q_SIGNALS:
0188         /**
0189          * This signal is emitted when the playback finished.
0190          */
0191         void finished();
0192 
0193     protected:
0194         bool event(QEvent *) override;
0195         VideoPlayerPrivate *const d;
0196 };
0197 
0198 } //namespace Phonon
0199 
0200 #endif //QT_NO_PHONON_VIDEOPLAYER
0201 
0202 
0203 #endif // Phonon_VIDEOPLAYER_H
0204 // vim: sw=4 ts=4 tw=80