1
/*  This file is part of the KDE project.
2
3
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
5
This library is free software: you can redistribute it and/or modify
6
it under the terms of the GNU Lesser General Public License as published by
7
the Free Software Foundation, either version 2.1 or 3 of the License.
8
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
GNU Lesser General Public License for more details.
13
14
You should have received a copy of the GNU Lesser General Public License
15
along with this library.  If not, see <http://www.gnu.org/licenses/>.
16
17
*/
18
19
#ifndef PHONON_MMF_ABSTRACTPLAYER_H
20
#define PHONON_MMF_ABSTRACTPLAYER_H
21
22
#include <phonon/phononnamespace.h>
23
#include <phonon/mediasource.h>
24
25
#include <QObject>
26
27
#include "abstractvideooutput.h"
28
29
QT_BEGIN_NAMESPACE
30
31
namespace Phonon
32
{
33
namespace MMF
34
{
35
36
/**
37
 * @short Interface which abstracts from MediaObject the current
38
 * media type
39
 *
40
 * This may be:
41
 *  -   Nothing, in which case this interface is implemented by
42
 *      DummyPlayer
43
 *  -   Audio, in which case the implementation is AudioPlayer
44
 *  -   Video, in which case the implementation is VideoPlayer
45
 */
46
class AbstractPlayer : public QObject
47
{
48
    // Required although this class has no signals or slots
49
    // Without this, qobject_cast will fail
50
    Q_OBJECT
51
52
public:
53
    AbstractPlayer(const AbstractPlayer *player);
54
55
    virtual void open() = 0;
56
    virtual void close() = 0;
57
58
    // MediaObjectInterface (implemented)
59
    qint32 tickInterval() const;
60
    void setTickInterval(qint32);
61
    void setTransitionTime(qint32);
62
    qint32 transitionTime() const;
63
    void setPrefinishMark(qint32);
64
    qint32 prefinishMark() const;
65
66
    // MediaObjectInterface (abstract)
67
    virtual void play() = 0;
68
    virtual void pause() = 0;
69
    virtual void stop() = 0;
70
    virtual void seek(qint64 milliseconds) = 0;
71
    virtual bool hasVideo() const = 0;
72
    virtual bool isSeekable() const = 0;
73
    virtual qint64 currentTime() const = 0;
74
    virtual Phonon::ErrorType errorType() const;
75
    virtual QString errorString() const;
76
    virtual qint64 totalTime() const = 0;
77
78
    virtual void volumeChanged(qreal volume);
79
80
    void setVideoOutput(AbstractVideoOutput *videoOutput);
81
82
    /**
83
     * Records error message and changes state to ErrorState
84
     */
85
    void setError(const QString &errorMessage);
86
87
    /**
88
     * Records error message and changes state to ErrorState
89
     *
90
     * Appends a human-readable version of symbianErrorCode to the error message,
91
     * e.g.
92
     * @code
93
     *      setError("Opening file failed", KErrPermissionDenied)
94
     * @endcode
95
     * results in the following error message:
96
     *      "Opening file failed: permission denied"
97
     */
98
    void setError(const QString &errorMessage, int symbianErrorCode);
99
100
    Phonon::State state() const;
101
102
Q_SIGNALS:
103
    void totalTimeChanged(qint64 length);
104
    void finished();
105
    void tick(qint64 time);
106
    void bufferStatus(int percentFilled);
107
    void stateChanged(Phonon::State newState,
108
                      Phonon::State oldState);
109
    void metaDataChanged(const QMultiMap<QString, QString>& metaData);
110
    void aboutToFinish();
111
    void prefinishMarkReached(qint32 remaining);
112
113
protected:
114
    /**
115
     * Defined private state enumeration in order to add GroundState
116
     */
117
    enum PrivateState {
118
        LoadingState    = Phonon::LoadingState,
119
        StoppedState    = Phonon::StoppedState,
120
        PlayingState    = Phonon::PlayingState,
121
        BufferingState  = Phonon::BufferingState,
122
        PausedState     = Phonon::PausedState,
123
        ErrorState      = Phonon::ErrorState,
124
        GroundState
125
    };
126
127
    /**
128
     * Converts PrivateState into the corresponding Phonon::State
129
     */
130
    Phonon::State phononState() const;
131
132
    /**
133
     * Converts PrivateState into the corresponding Phonon::State
134
     */
135
    virtual Phonon::State phononState(PrivateState state) const;
136
137
    virtual void videoOutputChanged();
138
139
    PrivateState privateState() const;
140
141
    /**
142
     * Changes state and emits stateChanged()
143
     */
144
    virtual void changeState(PrivateState newState);
145
146
    /**
147
     * Modifies m_state directly. Typically you want to call changeState(),
148
     * which performs the business logic.
149
     */
150
    void setState(PrivateState newState);
151
152
private:
153
    virtual void doSetTickInterval(qint32 interval) = 0;
154
155
protected:
156
    // Not owned
157
    AbstractVideoOutput*        m_videoOutput;
158
159
    qreal                       m_volume;
160
161
private:
162
    PrivateState                m_state;
163
    Phonon::ErrorType           m_error;
164
    QString                     m_errorString;
165
    qint32                      m_tickInterval;
166
    qint32                      m_transitionTime;
167
    qint32                      m_prefinishMark;
168
169
};
170
}
171
}
172
173
QT_END_NAMESPACE
174
175
#endif