1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 // |
|
43 // W A R N I N G |
|
44 // ------------- |
|
45 // |
|
46 // This file is not part of the Qt API. It exists purely as an |
|
47 // implementation detail. This header file may change from version to |
|
48 // version without notice, or even be removed. |
|
49 // |
|
50 // We mean it. |
|
51 // |
|
52 |
|
53 #include <QtCore/qcoreapplication.h> |
|
54 |
|
55 #include "qmediacontent.h" |
|
56 #include "qmediaplayer.h" |
|
57 |
|
58 #include "qsoundeffect_p.h" |
|
59 #include "qsoundeffect_qmedia_p.h" |
|
60 |
|
61 |
|
62 QSoundEffectPrivate::QSoundEffectPrivate(QObject* parent): |
|
63 QObject(parent), |
|
64 m_muted(false), |
|
65 m_volume(100), |
|
66 m_player(0) |
|
67 { |
|
68 } |
|
69 |
|
70 QSoundEffectPrivate::~QSoundEffectPrivate() |
|
71 { |
|
72 if (m_player) delete m_player; |
|
73 } |
|
74 |
|
75 qint64 QSoundEffectPrivate::duration() const |
|
76 { |
|
77 if (m_player) return m_player->duration(); |
|
78 |
|
79 return 0; |
|
80 } |
|
81 |
|
82 int QSoundEffectPrivate::volume() const |
|
83 { |
|
84 if (m_player) return m_player->volume(); |
|
85 |
|
86 return m_volume; |
|
87 } |
|
88 |
|
89 bool QSoundEffectPrivate::isMuted() const |
|
90 { |
|
91 if (m_player) return m_player->isMuted(); |
|
92 |
|
93 return m_muted; |
|
94 } |
|
95 |
|
96 QMediaContent QSoundEffectPrivate::media() const |
|
97 { |
|
98 if (m_player) return m_player->media(); |
|
99 |
|
100 return QMediaContent(); |
|
101 } |
|
102 |
|
103 QMediaPlayer::State QSoundEffectPrivate::state() const |
|
104 { |
|
105 if (m_player) return m_player->state(); |
|
106 |
|
107 return QMediaPlayer::StoppedState; |
|
108 } |
|
109 |
|
110 QMediaPlayer::MediaStatus QSoundEffectPrivate::mediaStatus() const |
|
111 { |
|
112 if (m_player) return m_player->mediaStatus(); |
|
113 |
|
114 return QMediaPlayer::UnknownMediaStatus; |
|
115 } |
|
116 |
|
117 void QSoundEffectPrivate::play() |
|
118 { |
|
119 if (m_player && !m_player->isMuted()) |
|
120 m_player->play(); |
|
121 } |
|
122 |
|
123 void QSoundEffectPrivate::stop() |
|
124 { |
|
125 if (m_player) |
|
126 m_player->stop(); |
|
127 } |
|
128 |
|
129 void QSoundEffectPrivate::setVolume(int volume) |
|
130 { |
|
131 m_volume = volume; |
|
132 |
|
133 if (m_player) |
|
134 m_player->setVolume(volume); |
|
135 } |
|
136 |
|
137 void QSoundEffectPrivate::setMuted(bool muted) |
|
138 { |
|
139 m_muted = muted; |
|
140 |
|
141 if (m_player) |
|
142 m_player->setMuted(muted); |
|
143 } |
|
144 |
|
145 void QSoundEffectPrivate::setMedia(const QMediaContent &media) |
|
146 { |
|
147 if (media.isNull()) |
|
148 return; |
|
149 |
|
150 if (m_player == 0) { |
|
151 m_player = new QMediaPlayer(this, QMediaPlayer::LowLatency); |
|
152 m_player->setVolume(m_volume); |
|
153 m_player->setMuted(m_muted); |
|
154 |
|
155 connect(m_player, SIGNAL(volumeChanged(int)), SIGNAL(volumeChanged(int))); |
|
156 connect(m_player, SIGNAL(mutedChanged(bool)), SIGNAL(mutedChanged(bool))); |
|
157 connect(m_player, SIGNAL(durationChanged(qint64)), SIGNAL(durationChanged(qint64))); |
|
158 connect(m_player, SIGNAL(stateChanged(QMediaPlayer::State)), SIGNAL(stateChanged(QMediaPlayer::State))); |
|
159 } |
|
160 |
|
161 m_player->setMedia(media.canonicalUrl()); |
|
162 } |
|
163 |
|