1 /* |
1 /* |
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
8 * |
8 * |
9 * Initial Contributors: |
9 * Initial Contributors: |
10 * Nokia Corporation - initial contribution. |
10 * Nokia Corporation - initial contribution. |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 #include <hbprogressdialog.h> |
|
18 #include <hbmessagebox.h> |
17 #include <hbmessagebox.h> |
19 #include <QTimer> |
18 #include <QTimer> |
20 #ifdef Q_CC_NOKIAX86 |
19 #ifdef Q_CC_NOKIAX86 |
21 #include <QFile> |
20 #include <QFile> |
22 #include <QTextStream> |
21 #include <QTextStream> |
|
22 #endif |
|
23 #ifdef HS_WIDGET_ENABLED |
|
24 #include <QSettings> |
23 #endif |
25 #endif |
24 |
26 |
25 #include "irplaycontroller.h" |
27 #include "irplaycontroller.h" |
26 #include "irapplication.h" |
28 #include "irapplication.h" |
27 #include "irqmediaplayer.h" |
29 #include "irqmediaplayer.h" |
32 #include "irqsonghistoryengine.h" |
34 #include "irqsonghistoryengine.h" |
33 #include "irqmetadata.h" |
35 #include "irqmetadata.h" |
34 #include "irqsettings.h" |
36 #include "irqsettings.h" |
35 #include "irqfavoritesdb.h" |
37 #include "irqfavoritesdb.h" |
36 #include "irqstatisticsreporter.h" |
38 #include "irqstatisticsreporter.h" |
37 #include "irenummapper.h" |
39 #include "irenummapper.h" |
|
40 #include "irqlogger.h" |
|
41 #ifdef HS_WIDGET_ENABLED |
|
42 #include "irservicedef.h" |
|
43 #endif |
38 |
44 |
39 #ifdef Q_CC_NOKIAX86 |
45 #ifdef Q_CC_NOKIAX86 |
40 void getRadioServerAddress(QString & aUrl); |
46 void getRadioServerAddress(QString & aUrl); |
41 #endif |
47 #endif |
42 |
48 |
75 #define MAP_TO_ENGINE_ConnectedFrom(ui_enum) \ |
81 #define MAP_TO_ENGINE_ConnectedFrom(ui_enum) \ |
76 MAP_TO_ENGINE_ENUM( IRQConnectedFrom, \ |
82 MAP_TO_ENGINE_ENUM( IRQConnectedFrom, \ |
77 IRQStatisticsReporter::IRConnectedFrom, \ |
83 IRQStatisticsReporter::IRConnectedFrom, \ |
78 ui_enum, KConnectedFromMap ) |
84 ui_enum, KConnectedFromMap ) |
79 |
85 |
|
86 |
|
87 static bool loadStationLogoFlag(); |
|
88 static void saveStationLogoFlag(bool aIsStationLogoAvailable); |
|
89 |
80 // public functions |
90 // public functions |
81 |
91 |
82 /* |
92 /* |
83 * Description : constructor |
93 * Description : constructor |
84 */ |
94 */ |
85 IRPlayController::IRPlayController(IRApplication* aApplication) : |
95 IRPlayController::IRPlayController(IRApplication* aApplication) : |
86 iApplication(aApplication), |
96 iApplication(aApplication), |
87 iMediaPlayer(new IRQMediaPlayer()), |
97 iMediaPlayer(new IRQMediaPlayer()), |
88 iStatisticsReporter(NULL), |
98 iStatisticsReporter(NULL), |
|
99 iGetServerResult(false), |
|
100 iNowPlayingPreset(new IRQPreset()), |
|
101 iNowPlayingPresetBackup(new IRQPreset()), |
89 iConnectedFrom(EIRQIsds), |
102 iConnectedFrom(EIRQIsds), |
90 iGetServerResult(false), |
103 iConnectedFromBackup(EIRQIsds), |
91 iBufferingDialog(NULL), |
104 iStationLogoAvailable(false), |
92 iNowPlayingPreset(new IRQPreset()), |
105 iStationLogoAvailableBackup(false), |
93 iMetaData(NULL), |
106 iMetaData(NULL), |
94 iSongHistoryEngine(IRQSongHistoryEngine::openInstance()), |
107 iSongHistoryEngine(IRQSongHistoryEngine::openInstance()), |
95 iPlayState(EIdle), |
108 iPlayState(EIdle), |
96 iResuming(false), |
109 iResuming(false), |
97 iTryingBitrate(0), |
110 iTryingBitrate(0), |
98 iUrlArray(0), |
111 iUrlArray(0), |
99 iRealBitrate(0), |
112 iRealBitrate(0), |
100 iLastError(EIRQErrorNone), |
113 iLastError(EIRQErrorNone), |
101 iStopReason(EIRQUnknownTermination) |
114 iStopReason(EIRQUnknownTermination), |
102 { |
115 iErrorNote(NULL) |
|
116 { |
|
117 // use the last played station to initiliaze the backup value. |
|
118 // can regard the player is bootup, and initilize its LCD screen with last played station info if available. |
|
119 IRQPreset *lastPlayedPreset = iApplication->getLastPlayedStationInfo()->getLastPlayedStation(); |
|
120 if (lastPlayedPreset) |
|
121 { |
|
122 *iNowPlayingPreset = *lastPlayedPreset; |
|
123 iLastPlayedUrl = getFirstTryUrl(lastPlayedPreset); |
|
124 iConnectedFrom = iApplication->getLastPlayedStationInfo()->connectedFrom(); |
|
125 iStationLogoAvailable = loadStationLogoFlag(); |
|
126 } |
|
127 |
|
128 if (iNowPlayingPreset->getChannelURLCount()) |
|
129 { |
|
130 iPlayState = EStopped; |
|
131 } |
|
132 else |
|
133 { |
|
134 iPlayState = EIdle; |
|
135 } |
|
136 |
103 connectSignalSlot(); |
137 connectSignalSlot(); |
104 iStatisticsReporter = IRQStatisticsReporter::openInstance(); |
138 iStatisticsReporter = IRQStatisticsReporter::openInstance(); |
105 } |
139 } |
106 |
140 |
107 /* |
141 /* |
108 * Description : destructor |
142 * Description : destructor |
109 */ |
143 */ |
110 IRPlayController::~IRPlayController() |
144 IRPlayController::~IRPlayController() |
111 { |
145 { |
112 delete iBufferingDialog; |
|
113 iBufferingDialog = NULL; |
|
114 |
|
115 stop(EIRQUserTerminated); |
146 stop(EIRQUserTerminated); |
116 delete iMediaPlayer; |
147 delete iMediaPlayer; |
117 iMediaPlayer = NULL; |
148 iMediaPlayer = NULL; |
118 |
149 |
119 delete iNowPlayingPreset; |
150 delete iNowPlayingPreset; |
120 iNowPlayingPreset = NULL; |
151 iNowPlayingPreset = NULL; |
|
152 delete iNowPlayingPresetBackup; |
|
153 iNowPlayingPresetBackup = NULL; |
121 |
154 |
122 delete iUrlArray; |
155 delete iUrlArray; |
123 iUrlArray = NULL; |
156 iUrlArray = NULL; |
124 |
157 |
|
158 delete iErrorNote; |
|
159 iErrorNote = NULL; |
|
160 |
|
161 saveStationLogoFlag(iStationLogoAvailable); |
|
162 |
125 if (iSongHistoryEngine) |
163 if (iSongHistoryEngine) |
126 { |
164 { |
127 iSongHistoryEngine->closeInstance(); |
165 iSongHistoryEngine->closeInstance(); |
128 iSongHistoryEngine = NULL; |
166 iSongHistoryEngine = NULL; |
129 } |
167 } |
138 * Description : connect to a channel specified by aPreset. |
176 * Description : connect to a channel specified by aPreset. |
139 * Parameters : aPreset : the preset of the channel |
177 * Parameters : aPreset : the preset of the channel |
140 */ |
178 */ |
141 void IRPlayController::connectToChannel(IRQPreset *aPreset, IRQConnectedFrom aConnectedFrom) |
179 void IRPlayController::connectToChannel(IRQPreset *aPreset, IRQConnectedFrom aConnectedFrom) |
142 { |
180 { |
143 iConnectedFrom = aConnectedFrom; |
|
144 if (!aPreset) |
181 if (!aPreset) |
145 { |
182 { |
146 return; |
183 return; |
147 } |
184 } |
148 |
185 |
149 if (iMediaPlayer) |
186 if (iMediaPlayer) |
150 { |
187 { |
151 // sort the URL by ascending order and get all available rates. |
188 QString firstTryUrl = getFirstTryUrl(aPreset); |
152 // iAvailableBitrate is cleared in getAvailableBitrates(). |
189 if (firstTryUrl.isEmpty()) |
153 aPreset->sortURLArray(); |
|
154 aPreset->getAvailableBitrates(iAvailableBitrate); |
|
155 if (iAvailableBitrate.count() == 0) |
|
156 { |
190 { |
157 return; |
191 return; |
158 } |
192 } |
159 |
193 |
160 int selectedBitRate = 0; |
194 *iNowPlayingPresetBackup = *iNowPlayingPreset; |
161 IRQPreferredQuality preferredQuality = iApplication->getSettings()->getPreferredQuality(); |
195 iLastPlayedUrlBackup = iLastPlayedUrl; |
162 switch(preferredQuality) |
196 iConnectedFromBackup = iConnectedFrom; |
163 { |
197 |
164 case EIRQStandardQuality: |
198 *iNowPlayingPreset = *aPreset; |
165 selectedBitRate = iAvailableBitrate.first(); |
199 iLastPlayedUrl = firstTryUrl; |
166 break; |
200 iConnectedFrom = aConnectedFrom; |
167 case EIRQHighQuality: |
201 iResuming = false; |
168 selectedBitRate = iAvailableBitrate.last(); |
202 doPlay(iLastPlayedUrl); |
169 break; |
203 } |
170 default: |
204 } |
171 selectedBitRate = iAvailableBitrate.first(); |
205 |
172 break; |
206 QString IRPlayController::getFirstTryUrl(IRQPreset *aPreset) |
173 } |
207 { |
174 |
208 QString firstTryUrl; |
175 // get URL to play |
209 // sort the URL by ascending order and get all available rates. |
176 iTryingBitrate = selectedBitRate; |
210 // iAvailableBitrate is cleared in getAvailableBitrates(). |
177 *iNowPlayingPreset = *aPreset; |
211 aPreset->sortURLArray(); |
178 delete iUrlArray; |
212 aPreset->getAvailableBitrates(iAvailableBitrate); |
179 iUrlArray = NULL; |
213 if (iAvailableBitrate.count() == 0) |
180 iUrlArray = iNowPlayingPreset->getURLsForBitrate(selectedBitRate); |
214 { |
181 if (iUrlArray) |
215 return firstTryUrl; |
182 { |
216 } |
183 QString url = iUrlArray->at(0); |
217 |
|
218 int selectedBitRate = 0; |
|
219 IRQPreferredQuality preferredQuality = iApplication->getSettings()->getPreferredQuality(); |
|
220 switch(preferredQuality) |
|
221 { |
|
222 case EIRQStandardQuality: |
|
223 selectedBitRate = iAvailableBitrate.first(); |
|
224 break; |
|
225 case EIRQHighQuality: |
|
226 selectedBitRate = iAvailableBitrate.last(); |
|
227 break; |
|
228 default: |
|
229 selectedBitRate = iAvailableBitrate.first(); |
|
230 break; |
|
231 } |
|
232 |
|
233 // get URL to play |
|
234 iTryingBitrate = selectedBitRate; |
|
235 |
|
236 delete iUrlArray; |
|
237 iUrlArray = NULL; |
|
238 iUrlArray = aPreset->getURLsForBitrate(selectedBitRate); |
|
239 if (iUrlArray) |
|
240 { |
|
241 firstTryUrl = iUrlArray->at(0); |
184 #ifdef Q_CC_NOKIAX86 |
242 #ifdef Q_CC_NOKIAX86 |
185 if (iLastPlayedChannelName != aPreset->name) |
243 firstTryUrl = "http://172.28.182.59:8000"; |
186 { |
244 getRadioServerAddress(firstTryUrl); |
187 emit initializeLogo(); |
|
188 } |
|
189 url = "http://172.28.205.171:8000"; |
|
190 getRadioServerAddress(url); |
|
191 iLastPlayedChannelName = aPreset->name; |
|
192 #else |
|
193 if (iLastPlayedUrl != iUrlArray->at(0)) |
|
194 { |
|
195 emit initializeLogo(); |
|
196 } |
|
197 #endif |
245 #endif |
198 iLastPlayedUrl = url; |
246 } |
199 iResuming = false; |
247 |
200 doPlay(url); |
248 return firstTryUrl; |
201 } |
|
202 } |
|
203 } |
249 } |
204 |
250 |
205 /* |
251 /* |
206 * Description : RESUME playing after play is stopped. |
252 * Description : RESUME playing after play is stopped. |
207 * Use the last played url as station's url. |
253 * Use the last played url as station's url. |
225 /* |
271 /* |
226 * Description : stop playing |
272 * Description : stop playing |
227 */ |
273 */ |
228 void IRPlayController::stop(IRQTerminatedType aStopReason) |
274 void IRPlayController::stop(IRQTerminatedType aStopReason) |
229 { |
275 { |
230 qDebug("IRPlayController::stop, Entering, aStopReason=%d", aStopReason); |
276 qDebug("IRPlayController::stop, Entering, aStopReason=%d", aStopReason); |
231 if (iMediaPlayer) |
277 |
232 { |
278 switch (iPlayState) |
233 iMediaPlayer->disableStereoEffect(); |
279 { |
234 |
280 case EPlaying: |
235 iMediaPlayer->stop(); |
281 iPlayState = EStopped; |
236 |
|
237 if (EPlaying == iPlayState) |
|
238 { |
|
239 iStopReason = aStopReason; |
282 iStopReason = aStopReason; |
|
283 if (iMediaPlayer) |
|
284 { |
|
285 iMediaPlayer->disableStereoEffect(); |
|
286 iMediaPlayer->stop(); |
|
287 } |
240 // playingStarted is emitted while iPlaying is set to true, |
288 // playingStarted is emitted while iPlaying is set to true, |
241 // so when stop() is called and iPlaying is true, playingStopped |
289 // so when stop() is called and iPlaying is true, playingStopped |
242 // should be emitted. |
290 // should be emitted. |
243 qDebug("IRPlayController::stop, emit playingStopped()"); |
291 qDebug("IRPlayController::stop, emit playingStopped()"); |
244 emit playingStopped(); |
292 emit playingStopped(); |
245 } |
293 break; |
246 iPlayState = EStopped; |
294 |
|
295 #ifdef HS_WIDGET_ENABLED |
|
296 case EConnecting: |
|
297 // No need to restore because when connecting occurs, because the connectToChannel() has NOT been invoked yet. |
|
298 // Only need to reset the player state |
|
299 if (iNowPlayingPreset->getChannelURLCount()) |
|
300 { |
|
301 iPlayState = EStopped; |
|
302 } |
|
303 else |
|
304 { |
|
305 iPlayState = EIdle; |
|
306 } |
|
307 |
|
308 iStopReason = aStopReason; |
|
309 |
|
310 // Only need to restore the station logo flag since we may force it to be false when connecting started. |
|
311 // force logo to be default when current view is NOT nowplaying view && is not resuming (start playing a different station.) |
|
312 if (EIRView_PlayingView != iApplication->getViewManager()->currentViewId() |
|
313 && iConnectingStationName != iNowPlayingPreset->name) |
|
314 { |
|
315 iStationLogoAvailable = iStationLogoAvailableBackup; |
|
316 emit stationLogoUpdated(iStationLogoAvailable); |
|
317 } |
|
318 emit connectingCancelled(iNowPlayingPreset->name); |
|
319 break; |
|
320 #endif |
|
321 |
|
322 case EBuffering: |
|
323 if (iMediaPlayer) |
|
324 { |
|
325 iMediaPlayer->disableStereoEffect(); |
|
326 iMediaPlayer->stop(); |
|
327 } |
|
328 // when player is forced to stop in bufferring state, we have to revert to backup preset. |
|
329 // only with exception when current view is nowplaying view. |
|
330 // in IR case, user can only stay in nowplaying view when buffering: |
|
331 // 1. starging view is now playing view; 2. open a pls file with only one url |
|
332 if (EIRView_PlayingView != iApplication->getViewManager()->currentViewId()) |
|
333 { |
|
334 iLastPlayedUrl = iLastPlayedUrlBackup; |
|
335 *iNowPlayingPreset = *iNowPlayingPresetBackup; |
|
336 iConnectedFrom = iConnectedFromBackup; |
|
337 } |
|
338 |
|
339 if (iNowPlayingPreset->getChannelURLCount()) |
|
340 { |
|
341 iPlayState = EStopped; |
|
342 } |
|
343 else |
|
344 { |
|
345 iPlayState = EIdle; |
|
346 } |
|
347 |
|
348 iStopReason = aStopReason; |
|
349 |
|
350 #ifdef HS_WIDGET_ENABLED |
|
351 // Need to restore the station logo flag since we may force it to be false when buffering started. |
|
352 // force logo to be default when current view is NOT nowplaying view && is not resuming (start playing a different station.) |
|
353 if (EIRView_PlayingView != iApplication->getViewManager()->currentViewId() |
|
354 && !iResuming) |
|
355 { |
|
356 iStationLogoAvailable = iStationLogoAvailableBackup; |
|
357 emit stationLogoUpdated(iStationLogoAvailable); |
|
358 } |
|
359 emit bufferingCancelled(iNowPlayingPreset->name); |
|
360 #endif |
|
361 break; |
|
362 |
|
363 |
|
364 case EIdle: |
|
365 case EStopped: |
|
366 default: |
|
367 break; |
247 } |
368 } |
248 endSession(aStopReason); |
369 endSession(aStopReason); |
249 qDebug("IRPlayController::stop, Exiting"); |
370 qDebug("IRPlayController::stop, Exiting"); |
250 } |
371 } |
251 |
372 |
292 iMediaPlayer->setVolume(aVolume); |
413 iMediaPlayer->setVolume(aVolume); |
293 } |
414 } |
294 iApplication->getSettings()->setVolumeSetting(aVolume); |
415 iApplication->getSettings()->setVolumeSetting(aVolume); |
295 } |
416 } |
296 |
417 |
297 /* |
418 #ifdef HS_WIDGET_ENABLED |
298 * Description : enable stereo effect |
419 void IRPlayController::setConnectingStationName(const QString &aStationName, bool aForceConnecting) |
299 */ |
420 { |
300 void IRPlayController::enableStereo() |
421 iConnectingStationName = aStationName; |
301 { |
422 if (aForceConnecting |
302 if (iMediaPlayer) |
423 || !iApplication->getNetworkController()->getNetworkStatus()) |
303 { |
424 { |
304 iMediaPlayer->enableStereoEffect(); |
425 LOG_FORMAT("IRPlayController::setConnectingStationName, the station name is %s", STRING2CHAR(aStationName)); |
305 } |
426 iPlayState = EConnecting; |
306 } |
427 |
307 |
428 // force logo to be default when current view is NOT nowplaying view && is not resuming (start playing a different station.) |
308 /* |
429 if (EIRView_PlayingView != iApplication->getViewManager()->currentViewId() |
309 * Description : disable stereo effect |
430 && iConnectingStationName != iNowPlayingPreset->name) |
310 */ |
431 { |
311 void IRPlayController::disableStereo() |
432 emitStationLogoUpdated(false); |
312 { |
433 } |
313 if (iMediaPlayer) |
434 emit connectingStarted(aStationName); |
314 { |
435 } |
315 iMediaPlayer->disableStereoEffect(); |
436 } |
316 } |
437 |
|
438 QString IRPlayController::getConnectingStationName() const |
|
439 { |
|
440 return iConnectingStationName; |
|
441 } |
|
442 |
|
443 void IRPlayController::reloadNowplayingPreset(IRQPreset *aPreset, bool aIsLogoAvailable, IRQConnectedFrom aConnectedFrom) |
|
444 { |
|
445 if (aPreset) |
|
446 { |
|
447 *iNowPlayingPreset = *aPreset; |
|
448 iLastPlayedUrl = getFirstTryUrl(aPreset); |
|
449 iConnectedFrom = aConnectedFrom; |
|
450 iStationLogoAvailable = aIsLogoAvailable; |
|
451 } |
|
452 |
|
453 if (iNowPlayingPreset->getChannelURLCount()) |
|
454 { |
|
455 iPlayState = EStopped; |
|
456 } |
|
457 else |
|
458 { |
|
459 iPlayState = EIdle; |
|
460 } |
|
461 } |
|
462 |
|
463 bool IRPlayController::isStationLogoAvailable() const |
|
464 { |
|
465 return iStationLogoAvailable; |
|
466 } |
|
467 |
|
468 void IRPlayController::emitStationLogoUpdated(bool aIsLogoAvailable) |
|
469 { |
|
470 iStationLogoAvailableBackup = iStationLogoAvailable; |
|
471 iStationLogoAvailable = aIsLogoAvailable; |
|
472 emit stationLogoUpdated(iStationLogoAvailable); |
|
473 } |
|
474 |
|
475 bool loadStationLogoFlag() |
|
476 { |
|
477 QSettings settings(KIrSettingOrganization, KIrSettingApplication); |
|
478 return settings.value(KIrSettingStationLogoAvailable,false).toBool(); |
|
479 } |
|
480 |
|
481 #endif |
|
482 |
|
483 IRPlayController::EPlayState IRPlayController::state() const |
|
484 { |
|
485 return iPlayState; |
317 } |
486 } |
318 |
487 |
319 /* |
488 /* |
320 * Description : return the flag of playing state |
489 * Description : return the flag of playing state |
321 * Return : true : playing is ongoing |
490 * Return : true : playing is ongoing |
322 * false : playing is stopped |
491 * false : playing is not ongoing |
323 */ |
492 */ |
324 bool IRPlayController::isPlaying() const |
493 bool IRPlayController::isPlaying() const |
325 { |
494 { |
326 return (EPlaying == iPlayState); |
495 return (EPlaying == iPlayState); |
327 } |
496 } |
328 |
497 |
329 /* |
498 /* |
330 * Description : return the flag of stopped state |
499 * Description : return the flag of stopped state |
331 * Return : true : playing is stopped |
500 * Return : true : playing is stopped |
332 * false : playing is ongoing |
501 * false : playing is not stopped |
333 */ |
502 */ |
334 bool IRPlayController::isStopped() const |
503 bool IRPlayController::isStopped() const |
335 { |
504 { |
336 return (EStopped == iPlayState); |
505 return (EStopped == iPlayState); |
|
506 } |
|
507 |
|
508 /* |
|
509 * Description : return the flag of idle state |
|
510 * Return : true : playing is idle |
|
511 * false : playing is not idle |
|
512 */ |
|
513 bool IRPlayController::isIdle() const |
|
514 { |
|
515 return (EIdle == iPlayState); |
337 } |
516 } |
338 |
517 |
339 /* |
518 /* |
340 * Description : return the now playing preset |
519 * Description : return the now playing preset |
341 * Return : pointer to the now playing preset |
520 * Return : pointer to the now playing preset |
365 } |
544 } |
366 |
545 |
367 IRQTerminatedType IRPlayController::getStopReason() const |
546 IRQTerminatedType IRPlayController::getStopReason() const |
368 { |
547 { |
369 return iStopReason; |
548 return iStopReason; |
370 } |
|
371 |
|
372 /* |
|
373 * Description : show a buffering dialog to inform user the buffering stage. |
|
374 * If the dialog is not created yet, create first. |
|
375 */ |
|
376 void IRPlayController::createBufferingDialog(const QObject *aReceiver, const char *aFunc) |
|
377 { |
|
378 if (NULL == iBufferingDialog) |
|
379 { |
|
380 iBufferingDialog = new HbProgressDialog(HbProgressDialog::ProgressDialog); |
|
381 iBufferingDialog->setMinimum(0); |
|
382 iBufferingDialog->setMaximum(100); |
|
383 iBufferingDialog->setModal(true); |
|
384 } |
|
385 |
|
386 //disconnect everything connected to signal cancelled() |
|
387 iBufferingDialog->disconnect(SIGNAL(cancelled())); |
|
388 |
|
389 connect(iBufferingDialog, SIGNAL(cancelled()), aReceiver, aFunc); |
|
390 iBufferingDialog->setProgressValue(0); |
|
391 iBufferingDialog->setText("0%"); |
|
392 iBufferingDialog->show(); |
|
393 } |
|
394 |
|
395 /* |
|
396 * Description : close the buffering dialog |
|
397 */ |
|
398 void IRPlayController::closeBufferingDialog() |
|
399 { |
|
400 if (iBufferingDialog) |
|
401 { |
|
402 iBufferingDialog->close(); |
|
403 delete iBufferingDialog; |
|
404 iBufferingDialog = NULL; |
|
405 } |
|
406 } |
549 } |
407 |
550 |
408 // slot functions |
551 // slot functions |
409 |
552 |
410 /* |
553 /* |
440 * Description : error occurred in media player. Signal is emitted by media player. |
583 * Description : error occurred in media player. Signal is emitted by media player. |
441 * Parameters : aError : error value |
584 * Parameters : aError : error value |
442 */ |
585 */ |
443 void IRPlayController::errorOccured(IRQError aError) |
586 void IRPlayController::errorOccured(IRQError aError) |
444 { |
587 { |
|
588 LOG_METHOD; |
|
589 LOG_FORMAT("the error is occured %d",aError); |
445 iLastError = aError; |
590 iLastError = aError; |
446 |
591 |
447 QTimer::singleShot(1, this, SLOT(handleError())); |
592 QTimer::singleShot(1, this, SLOT(handleError())); |
448 } |
593 } |
449 |
594 |
450 /* |
595 /* |
451 * Description : handle the error async. |
596 * Description : handle the error async. |
452 */ |
597 */ |
453 void IRPlayController::handleError() |
598 void IRPlayController::handleError() |
454 { |
599 { |
|
600 LOG_METHOD; |
|
601 LOG_FORMAT("the last error is %d", iLastError); |
455 qDebug("IRPlayController::handleError(), Entering, iLastError - %d", iLastError); |
602 qDebug("IRPlayController::handleError(), Entering, iLastError - %d", iLastError); |
456 switch (iLastError) |
603 switch (iLastError) |
457 { |
604 { |
458 case EIRQPlayerErrorServerFull: |
605 case EIRQPlayerErrorServerFull: |
459 case EIRQPlayerErrorTimeOut: |
606 case EIRQPlayerErrorTimeOut: |
492 |
639 |
493 case EIRQPlayerErrorConnectionLost: |
640 case EIRQPlayerErrorConnectionLost: |
494 qDebug("IRPlayController::handleError, connection lost"); |
641 qDebug("IRPlayController::handleError, connection lost"); |
495 stop(EIRQNoConnectionToServer); |
642 stop(EIRQNoConnectionToServer); |
496 break; |
643 break; |
497 |
644 |
|
645 case EIRQPlayerErrorAudioDeviceLost: |
|
646 //this is a temporary way to handle the plug-out event |
|
647 iApplication->stopLoadingAnimation(); |
|
648 stop(EIRQCallIsActivated); |
|
649 return; |
|
650 |
498 case EIRQPlayerErrorGeneral: |
651 case EIRQPlayerErrorGeneral: |
499 case EIRQPlayerErrorAudioDeviceLost: |
|
500 default: |
652 default: |
501 stop(EIRQUnknownTermination); |
653 stop(EIRQUnknownTermination); |
502 break; |
654 break; |
503 } |
655 } |
504 |
656 |
505 closeBufferingDialog(); |
657 iApplication->stopLoadingAnimation(); |
506 |
658 popupNote(); |
507 createNote(); |
|
508 qDebug("IRPlayController::handleError(), Exiting"); |
659 qDebug("IRPlayController::handleError(), Exiting"); |
509 } |
660 } |
510 |
661 |
511 /* |
662 /* |
512 * Description : buffering process has updated, change the display of buffering dialog. |
663 * Description : buffering process has updated, change the display of buffering dialog. |
514 * be shown to user. |
665 * be shown to user. |
515 * Parameters : aProgress : progress value, between 0 and 100. |
666 * Parameters : aProgress : progress value, between 0 and 100. |
516 */ |
667 */ |
517 void IRPlayController::updateProgress(int aProgress) |
668 void IRPlayController::updateProgress(int aProgress) |
518 { |
669 { |
519 /* we added this condition for sometimes, the function will be called |
|
520 * when the state is playing. reference cr_9010 |
|
521 */ |
|
522 if( iBufferingDialog && EBuffering == iPlayState ) |
|
523 { |
|
524 iBufferingDialog->setProgressValue(aProgress); |
|
525 iBufferingDialog->setText(QString("%1%").arg(aProgress)); |
|
526 } |
|
527 |
|
528 if (100 == aProgress) |
670 if (100 == aProgress) |
529 { |
671 { |
530 closeBufferingDialog(); |
|
531 |
|
532 //updateProgress(100) sometimes can be called more than one time, to improve performance, |
672 //updateProgress(100) sometimes can be called more than one time, to improve performance, |
533 //we only need to do the following work once. |
673 //we only need to do the following work once. |
534 if (EBuffering == iPlayState) |
674 if (EPlaying == iPlayState) |
535 { |
675 { |
536 iApplication->getViewManager()->activateView(EIRView_PlayingView); |
676 iApplication->stopLoadingAnimation(); |
537 iPlayState = EPlaying; |
677 return; |
538 |
678 } |
539 //update last played station |
679 |
540 IRLastPlayedStationInfo *lastPlayedStationInfo = iApplication->getLastPlayedStationInfo(); |
680 iPlayState = EPlaying; |
541 lastPlayedStationInfo->updateLastPlayedStation(iNowPlayingPreset,iConnectedFrom); |
681 iApplication->stopLoadingAnimation(); |
542 lastPlayedStationInfo->commitLastPlayedStation(); |
682 |
543 |
683 iApplication->getViewManager()->activateView(EIRView_PlayingView); |
544 //increase the played times of current preset |
684 |
545 iApplication->getFavoritesDB()->increasePlayedTimes(*iNowPlayingPreset); |
685 //update last played station |
546 |
686 IRLastPlayedStationInfo *lastPlayedStationInfo = iApplication->getLastPlayedStationInfo(); |
547 emit playingStarted(); |
687 lastPlayedStationInfo->updateLastPlayedStation(iNowPlayingPreset,iConnectedFrom); |
548 |
688 lastPlayedStationInfo->commitLastPlayedStation(); |
549 // if the metadata is available, show it. |
689 |
550 emit metaDataAvailable(iMetaData); |
690 //increase the played times of current preset |
551 |
691 iApplication->getFavoritesDB()->increasePlayedTimes(*iNowPlayingPreset); |
552 // Save the station information to database |
692 |
553 IRQMetaData tmpMetaData; |
693 emit playingStarted(); |
554 tmpMetaData.setBitrate(iRealBitrate); |
694 |
555 tmpMetaData.setStreamUrl(iLastPlayedUrl); |
695 // if the metadata is available, show it. |
556 iSongHistoryEngine->handleMetaDataReceived(tmpMetaData, *iNowPlayingPreset); |
696 emit metaDataAvailable(iMetaData); |
557 // open stereo defaultly |
697 |
558 iMediaPlayer->enableStereoEffect(); |
698 // Save the station information to database |
559 } |
699 IRQMetaData tmpMetaData; |
|
700 tmpMetaData.setBitrate(iRealBitrate); |
|
701 tmpMetaData.setStreamUrl(iLastPlayedUrl); |
|
702 iSongHistoryEngine->handleMetaDataReceived(tmpMetaData, *iNowPlayingPreset); |
|
703 // open stereo defaultly |
|
704 iMediaPlayer->enableStereoEffect(); |
560 } |
705 } |
561 } |
706 } |
562 |
707 |
563 /* |
708 /* |
564 * Description : get volume value from application setting. media player use the value |
709 * Description : get volume value from application setting. media player use the value |
574 * Description : handle the receiption of metadata. Notify now playing view to update display |
719 * Description : handle the receiption of metadata. Notify now playing view to update display |
575 * Parameters : aIRmetaData : the metadata object |
720 * Parameters : aIRmetaData : the metadata object |
576 */ |
721 */ |
577 void IRPlayController::handleMetaDataReceived(IRQMetaData& aIRmetaData) |
722 void IRPlayController::handleMetaDataReceived(IRQMetaData& aIRmetaData) |
578 { |
723 { |
579 |
|
580 |
|
581 iMetaData = &aIRmetaData; |
724 iMetaData = &aIRmetaData; |
582 //TO DO: there maybe a potential bug when the user cancel the play, |
725 //TO DO: there maybe a potential bug when the user cancel the play, |
583 if ((aIRmetaData.getSongName().trimmed() != "") |
726 if ((aIRmetaData.getSongName().trimmed() != "") |
584 || (aIRmetaData.getArtistName().trimmed() != "")) |
727 || (aIRmetaData.getArtistName().trimmed() != "")) |
585 { |
728 { |
586 //when we are play the musicplayer and get the metadata from lower layer, we save the |
729 //when we are play the musicplayer and get the metadata from lower layer, we save the |
587 //song's metadata into the db. After we save it to db, we emit the next signal to notify the UI |
730 //song's metadata into the db. After we save it to db, we emit the next signal to notify the UI |
588 iSongHistoryEngine->handleSongMetaDataReceived(*iMetaData, |
731 iSongHistoryEngine->handleSongMetaDataReceived(*iMetaData, |
589 iNowPlayingPreset->musicStoreStatus); |
732 *iNowPlayingPreset); |
590 } |
733 } |
591 |
734 |
592 if (EPlaying == iPlayState) |
735 if (EPlaying == iPlayState) |
593 { |
736 { |
594 // This signal will cause addBanner() work. Sometimes the metadata will come before |
737 // This signal will cause addBanner() work. Sometimes the metadata will come before |
601 * Description : during buffering stage, cancel playing request |
744 * Description : during buffering stage, cancel playing request |
602 */ |
745 */ |
603 void IRPlayController::cancelBuffering() |
746 void IRPlayController::cancelBuffering() |
604 { |
747 { |
605 stop(EIRQUserTerminated); |
748 stop(EIRQUserTerminated); |
606 if (!iResuming && EIRView_PlayingView == iApplication->getViewManager()->currentViewId()) |
749 iApplication->stopLoadingAnimation(); |
607 { |
|
608 iApplication->getViewManager()->backToPreviousView(); |
|
609 } |
|
610 } |
750 } |
611 |
751 |
612 // private functions |
752 // private functions |
613 |
753 |
614 /* |
754 /* |
615 * Description : show a note to user to inform that error occured. |
755 * Description : show a note to user to inform that error occured. |
616 * |
756 * |
617 */ |
757 */ |
618 void IRPlayController::createNote(const QString &aNote) |
758 void IRPlayController::popupNote(const QString &aNote) |
619 { |
759 { |
620 HbMessageBox::warning(aNote, (QObject*)NULL, NULL); |
760 if (NULL == iErrorNote) |
|
761 { |
|
762 iErrorNote = new HbMessageBox(HbMessageBox::MessageTypeWarning); |
|
763 iErrorNote->setModal(true); |
|
764 iErrorNote->setTimeout(HbPopup::StandardTimeout); |
|
765 } |
|
766 |
|
767 iErrorNote->setText(aNote); |
|
768 // if there is already on error note showing, only change the text |
|
769 if (!iErrorNote->isVisible()) |
|
770 { |
|
771 iErrorNote->show(); |
|
772 } |
621 } |
773 } |
622 |
774 |
623 /* |
775 /* |
624 * Description : establish the signal&slot connection between media player and play controller |
776 * Description : establish the signal&slot connection between media player and play controller |
625 */ |
777 */ |
712 unsigned long apId = 0; |
864 unsigned long apId = 0; |
713 iApplication->getNetworkController()->getIAPId(apId); |
865 iApplication->getNetworkController()->getIAPId(apId); |
714 qDebug("IRPlayController::doPlay, access point : %d", apId); |
866 qDebug("IRPlayController::doPlay, access point : %d", apId); |
715 iMediaPlayer->playStation(aUrl, apId); |
867 iMediaPlayer->playStation(aUrl, apId); |
716 iPlayState = EBuffering; |
868 iPlayState = EBuffering; |
|
869 #ifdef HS_WIDGET_ENABLED |
|
870 // force logo to be default when current view is NOT nowplaying view && is not resuming (start playing a different station.) |
|
871 if (EIRView_PlayingView != iApplication->getViewManager()->currentViewId() |
|
872 && !iResuming) |
|
873 { |
|
874 emitStationLogoUpdated(false); |
|
875 } |
|
876 emit bufferingStarted(iNowPlayingPreset->name); |
|
877 #endif |
717 startSession(); |
878 startSession(); |
718 createBufferingDialog(this, SLOT(cancelBuffering())); |
879 iApplication->startLoadingAnimation(this, SLOT(cancelBuffering())); |
719 } |
880 } |
720 |
881 |
721 /* |
882 /* |
722 * Description : start a session |
883 * Description : start a session |
723 */ |
884 */ |