46a5dc0b3bbf9bdb954dfe3c1deb54555ab8b8a7 | 59d90cc404fa30376ef3172fbd6a4e70a8c81b0a | ||
---|---|---|---|
40 | player (0), | 40 | player (0), |
41 | recTime (10.0), | 41 | recTime (10.0), |
42 | tick (0.0), | 42 | tick (0.0), |
43 | secsLeft (0.0), | 43 | secsLeft (0.0) |
44 | playLimitTimer (0) | ||
45 | { | 44 | { |
46 | audioSource = new QAudioCaptureSource (this); | 45 | audioSource = new QAudioCaptureSource (this); |
47 | recorder = new QMediaRecorder (audioSource, this); | 46 | recorder = new QMediaRecorder (audioSource, this); |
48 | player = new QMediaPlayer (this); | 47 | player = new QMediaPlayer (this); |
49 | ui.setupUi (this); | 48 | ui.setupUi (this); |
50 | playLimitTimer = new QTimer (this); | ||
51 | hide (); | 49 | hide (); |
52 | clock.start (); | 50 | clock.start (); |
53 | inStateText[0] = QString("Stopper"); | 51 | inStateText[0] = QString("Stopper"); |
... | ... | ||
181 | void | 179 | void |
182 | MobiAudiMessage::StartPlay () | 180 | MobiAudiMessage::StartPlay () |
183 | { | 181 | { |
184 | qDebug () << __PRETTY_FUNCTION__ << "Play audio message"; | 182 | qDebug () << __PRETTY_FUNCTION__ << "Play audio message " << inFile.fileName(); |
185 | if (player == 0) { | 183 | if (player == 0) { |
186 | return; | 184 | return; |
187 | } | 185 | } |
188 | player->setMedia (QMediaContent (QUrl::fromLocalFile (inFile.fileName()))); | 186 | if (playList.isEmpty()) { |
187 | return; | ||
188 | } | ||
189 | PlayItem item = playList.takeFirst(); | ||
190 | if (item.filename.isEmpty() || item.duration < 1) { | ||
191 | return; | ||
192 | } | ||
193 | qDebug () << " readable ? " << QFileInfo (item.filename).isReadable(); | ||
194 | player->setMedia (QMediaContent (QUrl::fromLocalFile (item.filename))); | ||
189 | 195 | ||
190 | emit PlayStarting (); | 196 | emit PlayStarting (); |
191 | player->setVolume (50); | 197 | player->setVolume (50); |
192 | player->setPosition (0); | 198 | player->setPosition (0); |
193 | player->play (); | 199 | player->play (); |
194 | qDebug () << " playing " << player->media().canonicalUrl(); | 200 | qDebug () << __PRETTY_FUNCTION__ ; |
201 | qDebug () << " playing " << player->media().canonicalUrl(); | ||
202 | qDebug () << " have audio " << player->isAudioAvailable (); | ||
203 | qDebug () << " mime " << player->media().canonicalResource().mimeType(); | ||
204 | qDebug () << " codec " << player->media().canonicalResource().audioCodec(); | ||
205 | qDebug () << " bitrate " << player->media().canonicalResource().audioBitRate(); | ||
206 | qDebug () << " null ? " << player->media().isNull(); | ||
195 | qDebug () << " duration " << player->duration(); | 207 | qDebug () << " duration " << player->duration(); |
208 | qDebug () << " position " << player->position(); | ||
196 | qDebug () << " err " << player->errorString(); | 209 | qDebug () << " err " << player->errorString(); |
197 | int playtime = (player->duration() / 1000) + 1000; | 210 | qDebug () << " rate " << player->playbackRate(); |
198 | // playLimitTimer->start (playtime); | 211 | int playtime = item.duration; |
199 | QTimer::singleShot (playtime, this, SLOT (StopPlay())); | 212 | qDebug () << " play tiemout set to " << playtime; |
213 | QTimer::singleShot (playtime, this, SLOT (TimeoutPlay())); | ||
200 | } | 214 | } |
201 | 215 | ||
202 | void | 216 | void |
... | ... | ||
206 | qDebug () << " " << player->errorString(); | 220 | qDebug () << " " << player->errorString(); |
207 | } | 221 | } |
208 | 222 | ||
209 | #if 0 | ||
210 | void | ||
211 | MobiAudiMessage::CheckPlayState () | ||
212 | { | ||
213 | static qint64 oldWork (0); | ||
214 | if (player) { | ||
215 | QAudio::State state = player->state (); | ||
216 | if (state == QAudio::IdleState) { | ||
217 | StopPlay (); | ||
218 | } else { | ||
219 | qint64 workdone = player->processedUSecs (); | ||
220 | if (workdone <= oldWork) { // nothing done in 2 secs, shut it down | ||
221 | StopPlay (); | ||
222 | qDebug () << " forcing audio player stop"; | ||
223 | } else { | ||
224 | oldWork = workdone; | ||
225 | } | ||
226 | } | ||
227 | } | ||
228 | } | ||
229 | #endif | ||
230 | 223 | ||
231 | void | 224 | void |
232 | MobiAudiMessage::PlayerStateChanged (QMediaPlayer::State state) | 225 | MobiAudiMessage::PlayerStateChanged (QMediaPlayer::State state) |
233 | { | 226 | { |
234 | qDebug () << __PRETTY_FUNCTION__ << " state " << state; | 227 | qDebug () << __PRETTY_FUNCTION__ << " new state " << state; |
228 | qDebug () << " playing " << player->media().canonicalUrl(); | ||
229 | qDebug () << " have audio " << player->isAudioAvailable (); | ||
230 | qDebug () << " mime " << player->media().canonicalResource().mimeType(); | ||
231 | qDebug () << " codec " << player->media().canonicalResource().audioCodec(); | ||
232 | qDebug () << " bitrate " << player->media().canonicalResource().audioBitRate(); | ||
233 | qDebug () << " null ? " << player->media().isNull(); | ||
234 | qDebug () << " duration " << player->duration(); | ||
235 | qDebug () << " position " << player->position(); | ||
236 | qDebug () << " err " << player->errorString(); | ||
237 | qDebug () << " rate " << player->playbackRate(); | ||
235 | switch (state) { | 238 | switch (state) { |
236 | case QMediaPlayer::PlayingState: | 239 | case QMediaPlayer::PlayingState: |
237 | break; | 240 | break; |
... | ... | ||
243 | } | 246 | } |
244 | } | 247 | } |
245 | 248 | ||
249 | void | ||
250 | MobiAudiMessage::TimeoutPlay () | ||
251 | { | ||
252 | qDebug () << __PRETTY_FUNCTION__ ; | ||
253 | if (player && player->state() != QMediaPlayer::StoppedState) { | ||
254 | StopPlay(); | ||
255 | } | ||
256 | } | ||
257 | |||
246 | 258 | ||
247 | void | 259 | void |
248 | MobiAudiMessage::StopPlay () | 260 | MobiAudiMessage::StopPlay () |
... | ... | ||
256 | } | 268 | } |
257 | busyReceive = false; | 269 | busyReceive = false; |
258 | emit PlayFinished (); | 270 | emit PlayFinished (); |
259 | playLimitTimer->stop (); | ||
260 | qDebug () << __PRETTY_FUNCTION__ << " done playing audio message"; | 271 | qDebug () << __PRETTY_FUNCTION__ << " done playing audio message"; |
261 | } | 272 | } |
262 | 273 | ||
... | ... | ||
283 | } | 294 | } |
284 | 295 | ||
285 | void | 296 | void |
286 | MobiAudiMessage::FinishReceive () | 297 | MobiAudiMessage::FinishReceive (const QString & filename, qint64 duration) |
287 | { | 298 | { |
288 | StartPlay (); | 299 | qDebug () << __PRETTY_FUNCTION__ << filename << duration; |
300 | playList.append (PlayItem (filename, duration)); | ||
301 | QTimer::singleShot (100, this, SLOT (StartPlay ())); | ||
289 | } | 302 | } |
290 | 303 | ||
291 | QString | 304 | QString |