qtinternetradio/ui/src/irplaycontroller.cpp
changeset 5 0930554dc389
parent 3 ee64f059b8e1
child 8 3b03c28289e6
equal deleted inserted replaced
3:ee64f059b8e1 5:0930554dc389
     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>
    32 #include "irqsonghistoryengine.h"
    31 #include "irqsonghistoryengine.h"
    33 #include "irqmetadata.h"
    32 #include "irqmetadata.h"
    34 #include "irqsettings.h"
    33 #include "irqsettings.h"
    35 #include "irqfavoritesdb.h"
    34 #include "irqfavoritesdb.h"
    36 #include "irqstatisticsreporter.h"
    35 #include "irqstatisticsreporter.h"
    37 #include "irenummapper.h"
    36 #include "irenummapper.h" 
       
    37 #include "irqlogger.h"
    38 
    38 
    39 #ifdef Q_CC_NOKIAX86
    39 #ifdef Q_CC_NOKIAX86
    40 void getRadioServerAddress(QString & aUrl);
    40 void getRadioServerAddress(QString & aUrl);
    41 #endif
    41 #endif
    42 
    42 
    86     iApplication(aApplication),
    86     iApplication(aApplication),
    87     iMediaPlayer(new IRQMediaPlayer()),
    87     iMediaPlayer(new IRQMediaPlayer()),
    88     iStatisticsReporter(NULL),
    88     iStatisticsReporter(NULL),
    89     iConnectedFrom(EIRQIsds),
    89     iConnectedFrom(EIRQIsds),
    90     iGetServerResult(false),
    90     iGetServerResult(false),
    91     iBufferingDialog(NULL),
       
    92     iNowPlayingPreset(new IRQPreset()),
    91     iNowPlayingPreset(new IRQPreset()),
    93     iMetaData(NULL),
    92     iMetaData(NULL),
    94     iSongHistoryEngine(IRQSongHistoryEngine::openInstance()),
    93     iSongHistoryEngine(IRQSongHistoryEngine::openInstance()),
    95     iPlayState(EIdle),
    94     iPlayState(EIdle),
    96     iResuming(false),
    95     iResuming(false),
   107 /*
   106 /*
   108  * Description : destructor
   107  * Description : destructor
   109  */
   108  */
   110 IRPlayController::~IRPlayController()
   109 IRPlayController::~IRPlayController()
   111 {
   110 {
   112     delete iBufferingDialog;
       
   113     iBufferingDialog = NULL;
       
   114 
       
   115     stop(EIRQUserTerminated);
   111     stop(EIRQUserTerminated);
   116     delete iMediaPlayer;
   112     delete iMediaPlayer;
   117     iMediaPlayer = NULL;
   113     iMediaPlayer = NULL;
   118 
   114 
   119     delete iNowPlayingPreset;
   115     delete iNowPlayingPreset;
   293     }
   289     }
   294     iApplication->getSettings()->setVolumeSetting(aVolume);
   290     iApplication->getSettings()->setVolumeSetting(aVolume);
   295 }
   291 }
   296 
   292 
   297 /*
   293 /*
   298  * Description : enable stereo effect
       
   299  */
       
   300 void IRPlayController::enableStereo()
       
   301 {
       
   302     if (iMediaPlayer)
       
   303     {
       
   304         iMediaPlayer->enableStereoEffect();
       
   305     }
       
   306 }
       
   307 
       
   308 /*
       
   309  * Description : disable stereo effect
       
   310  */
       
   311 void IRPlayController::disableStereo()
       
   312 {
       
   313     if (iMediaPlayer)
       
   314     {
       
   315         iMediaPlayer->disableStereoEffect();
       
   316     }
       
   317 }
       
   318 
       
   319 /*
       
   320  * Description : return the flag of playing state
   294  * Description : return the flag of playing state
   321  * Return      : true  : playing is ongoing
   295  * Return      : true  : playing is ongoing
   322  *               false : playing is stopped
   296  *               false : playing is not ongoing
   323  */
   297  */
   324 bool IRPlayController::isPlaying() const
   298 bool IRPlayController::isPlaying() const
   325 {
   299 {
   326     return (EPlaying == iPlayState);
   300     return (EPlaying == iPlayState);
   327 }
   301 }
   328 
   302 
   329 /*
   303 /*
   330  * Description : return the flag of stopped state
   304  * Description : return the flag of stopped state
   331  * Return      : true  : playing is stopped
   305  * Return      : true  : playing is stopped
   332  *               false : playing is ongoing
   306  *               false : playing is not stopped
   333  */
   307  */
   334 bool IRPlayController::isStopped() const
   308 bool IRPlayController::isStopped() const
   335 {
   309 {
   336     return (EStopped == iPlayState);
   310     return (EStopped == iPlayState);
       
   311 }
       
   312 
       
   313 /*
       
   314  * Description : return the flag of idle state
       
   315  * Return      : true  : playing is idle
       
   316  *               false : playing is not idle
       
   317  */
       
   318 bool IRPlayController::isIdle() const
       
   319 {
       
   320     return (EIdle == iPlayState);
   337 }
   321 }
   338 
   322 
   339 /*
   323 /*
   340  * Description : return the now playing preset
   324  * Description : return the now playing preset
   341  * Return      : pointer to the now playing preset
   325  * Return      : pointer to the now playing preset
   365 }
   349 }
   366 
   350 
   367 IRQTerminatedType IRPlayController::getStopReason() const
   351 IRQTerminatedType IRPlayController::getStopReason() const
   368 {
   352 {
   369     return iStopReason;
   353     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 }
   354 }
   407 
   355 
   408 //                                           slot  functions
   356 //                                           slot  functions
   409 
   357 
   410 /*
   358 /*
   440  * Description : error occurred in media player. Signal is emitted by media player.
   388  * Description : error occurred in media player. Signal is emitted by media player.
   441  * Parameters  : aError : error value
   389  * Parameters  : aError : error value
   442  */
   390  */
   443 void IRPlayController::errorOccured(IRQError aError)
   391 void IRPlayController::errorOccured(IRQError aError)
   444 {
   392 {
       
   393     LOG_METHOD;
       
   394     LOG_FORMAT("the error is occured %d",aError);
   445     iLastError = aError;
   395     iLastError = aError;
   446 
   396 
   447     QTimer::singleShot(1, this, SLOT(handleError()));
   397     QTimer::singleShot(1, this, SLOT(handleError()));
   448 }
   398 }
   449 
   399 
   450 /*
   400 /*
   451  * Description : handle the error async.
   401  * Description : handle the error async.
   452  */
   402  */
   453 void IRPlayController::handleError()
   403 void IRPlayController::handleError()
   454 {
   404 {
       
   405     LOG_METHOD;
       
   406     LOG_FORMAT("the last error is %d", iLastError);
   455     qDebug("IRPlayController::handleError(), Entering, iLastError - %d", iLastError);
   407     qDebug("IRPlayController::handleError(), Entering, iLastError - %d", iLastError);
   456     switch (iLastError)
   408     switch (iLastError)
   457     {
   409     {
   458     case EIRQPlayerErrorServerFull:
   410     case EIRQPlayerErrorServerFull:
   459     case EIRQPlayerErrorTimeOut:
   411     case EIRQPlayerErrorTimeOut:
   492 
   444 
   493     case EIRQPlayerErrorConnectionLost:
   445     case EIRQPlayerErrorConnectionLost:
   494         qDebug("IRPlayController::handleError, connection lost");
   446         qDebug("IRPlayController::handleError, connection lost");
   495         stop(EIRQNoConnectionToServer);
   447         stop(EIRQNoConnectionToServer);
   496         break;
   448         break;
   497 		
   449         
       
   450     case EIRQPlayerErrorAudioDeviceLost:
       
   451         //this is a temporary way to handle the plug-out event
       
   452         iApplication->closeLoadingDialog();
       
   453 		stop(EIRQCallIsActivated);
       
   454         return;
       
   455         
   498     case EIRQPlayerErrorGeneral:
   456     case EIRQPlayerErrorGeneral:
   499     case EIRQPlayerErrorAudioDeviceLost:
       
   500     default:
   457     default:
   501         stop(EIRQUnknownTermination);
   458         stop(EIRQUnknownTermination);
   502         break;
   459         break;
   503     }
   460     }
   504 
   461 
   505     closeBufferingDialog();
   462     iApplication->closeLoadingDialog();
   506 
   463 
   507     createNote();
   464     createNote();
   508     qDebug("IRPlayController::handleError(), Exiting");
   465     qDebug("IRPlayController::handleError(), Exiting");
   509 }
   466 }
   510 
   467 
   514  *               be shown to user.
   471  *               be shown to user.
   515  * Parameters  : aProgress : progress value, between 0 and 100.
   472  * Parameters  : aProgress : progress value, between 0 and 100.
   516  */
   473  */
   517 void IRPlayController::updateProgress(int aProgress)
   474 void IRPlayController::updateProgress(int aProgress)
   518 {
   475 {
   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)
   476     if (100 == aProgress)
   529     {
   477     {
   530         closeBufferingDialog();
   478         iApplication->closeLoadingDialog();
   531 
   479 
   532         //updateProgress(100) sometimes can be called more than one time, to improve performance,
   480         //updateProgress(100) sometimes can be called more than one time, to improve performance,
   533         //we only need to do the following work once.
   481         //we only need to do the following work once.
   534         if (EBuffering == iPlayState)
   482         if (EBuffering == iPlayState)
   535         {
   483         {
   574  * Description : handle the receiption of metadata. Notify now playing view to update display
   522  * Description : handle the receiption of metadata. Notify now playing view to update display
   575  * Parameters  : aIRmetaData : the metadata object
   523  * Parameters  : aIRmetaData : the metadata object
   576  */
   524  */
   577 void IRPlayController::handleMetaDataReceived(IRQMetaData& aIRmetaData)
   525 void IRPlayController::handleMetaDataReceived(IRQMetaData& aIRmetaData)
   578 {
   526 {
   579     
       
   580     
       
   581     iMetaData = &aIRmetaData;
   527     iMetaData = &aIRmetaData;
   582     //TO DO: there maybe a potential bug when the user cancel the play, 	
   528     //TO DO: there maybe a potential bug when the user cancel the play, 	
   583     if ((aIRmetaData.getSongName().trimmed() != "")
   529     if ((aIRmetaData.getSongName().trimmed() != "")
   584             || (aIRmetaData.getArtistName().trimmed() != ""))
   530             || (aIRmetaData.getArtistName().trimmed() != ""))
   585     {
   531     {
   601  * Description : during buffering stage, cancel playing request
   547  * Description : during buffering stage, cancel playing request
   602  */
   548  */
   603 void IRPlayController::cancelBuffering()
   549 void IRPlayController::cancelBuffering()
   604 {
   550 {
   605     stop(EIRQUserTerminated);
   551     stop(EIRQUserTerminated);
   606     if (!iResuming && EIRView_PlayingView == iApplication->getViewManager()->currentViewId())
   552     iApplication->closeLoadingDialog();
   607     {
       
   608         iApplication->getViewManager()->backToPreviousView();
       
   609     }
       
   610 }
   553 }
   611 
   554 
   612 //                                       private functions
   555 //                                       private functions
   613 
   556 
   614 /*
   557 /*
   713     iApplication->getNetworkController()->getIAPId(apId);
   656     iApplication->getNetworkController()->getIAPId(apId);
   714     qDebug("IRPlayController::doPlay, access point : %d", apId);
   657     qDebug("IRPlayController::doPlay, access point : %d", apId);
   715     iMediaPlayer->playStation(aUrl, apId);
   658     iMediaPlayer->playStation(aUrl, apId);
   716     iPlayState = EBuffering;
   659     iPlayState = EBuffering;
   717     startSession();
   660     startSession();
   718     createBufferingDialog(this, SLOT(cancelBuffering()));
   661     iApplication->createLoadingDialog(this, SLOT(cancelBuffering()));
   719 }
   662 }
   720 
   663 
   721 /*
   664 /*
   722  * Description : start a session
   665  * Description : start a session
   723  */
   666  */