qtinternetradio/ui/src/irplaycontroller.cpp
changeset 14 896e9dbc5f19
parent 12 608f67c22514
child 17 38bbf2dcd608
equal deleted inserted replaced
12:608f67c22514 14:896e9dbc5f19
   102     iConnectedFrom(EIRQIsds),
   102     iConnectedFrom(EIRQIsds),
   103     iConnectedFromBackup(EIRQIsds),
   103     iConnectedFromBackup(EIRQIsds),
   104     iStationLogoAvailable(false),
   104     iStationLogoAvailable(false),
   105     iStationLogoAvailableBackup(false),
   105     iStationLogoAvailableBackup(false),
   106     iMetaData(NULL),
   106     iMetaData(NULL),
   107     iSongHistoryEngine(IRQSongHistoryEngine::openInstance()),
   107     iSongHistoryEngine(NULL),
   108     iPlayState(EIdle),
   108     iPlayState(EIdle),
   109     iResuming(false),
   109     iResuming(false),
   110     iTryingBitrate(0),
   110     iTryingBitrate(0),
   111     iUrlArray(0),
   111     iUrlArray(0),
   112     iRealBitrate(0),
   112     iRealBitrate(0),
   114     iStopReason(EIRQUnknownTermination),
   114     iStopReason(EIRQUnknownTermination),
   115     iErrorNote(NULL)
   115     iErrorNote(NULL)
   116 {
   116 {
   117     // use the last played station to initiliaze the backup value.
   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.
   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();
   119     IRQPreset *lastPlayedPreset = NULL;
       
   120     if( !iApplication->isEmbeddedInstance() )
       
   121     {
       
   122         lastPlayedPreset = iApplication->getLastPlayedStationInfo()->getLastPlayedStation();        
       
   123     }
       
   124     
   120     if (lastPlayedPreset)
   125     if (lastPlayedPreset)
   121     {
   126     {
   122         *iNowPlayingPreset      =   *lastPlayedPreset;
   127         *iNowPlayingPreset      =   *lastPlayedPreset;
   123         iLastPlayedUrl          =   getFirstTryUrl(lastPlayedPreset);
   128         iLastPlayedUrl          =   getFirstTryUrl(lastPlayedPreset);
   124         iConnectedFrom          =   iApplication->getLastPlayedStationInfo()->connectedFrom();
   129         iConnectedFrom          =   iApplication->getLastPlayedStationInfo()->connectedFrom();
   134         iPlayState = EIdle;
   139         iPlayState = EIdle;
   135     }    
   140     }    
   136     
   141     
   137     connectSignalSlot(); 
   142     connectSignalSlot(); 
   138     iStatisticsReporter = IRQStatisticsReporter::openInstance();
   143     iStatisticsReporter = IRQStatisticsReporter::openInstance();
       
   144 	
       
   145 	if( !iApplication->isEmbeddedInstance() )
       
   146     {
       
   147         iSongHistoryEngine = IRQSongHistoryEngine::openInstance();
       
   148     }
   139 }
   149 }
   140 
   150 
   141 /*
   151 /*
   142  * Description : destructor
   152  * Description : destructor
   143  */
   153  */
   238     iUrlArray = aPreset->getURLsForBitrate(selectedBitRate);
   248     iUrlArray = aPreset->getURLsForBitrate(selectedBitRate);
   239     if (iUrlArray)
   249     if (iUrlArray)
   240     {
   250     {
   241         firstTryUrl = iUrlArray->at(0);
   251         firstTryUrl = iUrlArray->at(0);
   242 #ifdef Q_CC_NOKIAX86
   252 #ifdef Q_CC_NOKIAX86
   243         firstTryUrl = "http://172.28.182.59:8000";
   253         firstTryUrl = "http://172.28.205.171:8000";
   244         getRadioServerAddress(firstTryUrl);
   254         getRadioServerAddress(firstTryUrl);
   245 #endif
   255 #endif
   246     }
   256     }
   247     
   257     
   248     return firstTryUrl;
   258     return firstTryUrl;
   292             emit playingStopped();              
   302             emit playingStopped();              
   293             break;
   303             break;
   294 
   304 
   295 #ifdef HS_WIDGET_ENABLED			
   305 #ifdef HS_WIDGET_ENABLED			
   296         case EConnecting:     
   306         case EConnecting:     
       
   307             iStopReason = aStopReason;
       
   308             if (iMediaPlayer)
       
   309             {
       
   310                 iMediaPlayer->disableStereoEffect();
       
   311                 iMediaPlayer->stop(); 
       
   312             }            
   297             // No need to restore because when connecting occurs, because the connectToChannel() has NOT been invoked yet. 
   313             // No need to restore because when connecting occurs, because the connectToChannel() has NOT been invoked yet. 
   298             // Only need to reset the player state                  
   314             // Only need to reset the player state                  
   299             if (iNowPlayingPreset->getChannelURLCount())
   315             if (iNowPlayingPreset->getChannelURLCount())
   300             {
   316             {
   301                 iPlayState = EStopped;
   317                 iPlayState = EStopped;
   302             }
   318             }
   303             else
   319             else
   304             {
   320             {
   305                 iPlayState = EIdle;
   321                 iPlayState = EIdle;
   306             }
   322             }
   307             
       
   308             iStopReason = aStopReason;  
       
   309             
   323             
   310             // Only need to restore the station logo flag since we may force it to be false when connecting started.   
   324             // 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.) 
   325             // 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()
   326             if (EIRView_PlayingView != iApplication->getViewManager()->currentViewId()
   313                 && iConnectingStationName != iNowPlayingPreset->name)
   327                 && iConnectingStationName != iNowPlayingPreset->name)
   618             break;
   632             break;
   619         }
   633         }
   620 
   634 
   621         if (iResuming)
   635         if (iResuming)
   622         {
   636         {
   623             HbMessageBox::information(tr("Connecting failed, try next URL"), (QObject*)NULL, NULL);
   637 #ifdef SUBTITLE_STR_BY_LOCID
       
   638             HbMessageBox::information(hbTrId("txt_irad_connecting_failed_try_next_address"), (QObject*)NULL, NULL, HbMessageBox::Ok);
       
   639 #else
       
   640             HbMessageBox::information("Connecting failed, try next URL", (QObject*)NULL, NULL, HbMessageBox::Ok);
       
   641 #endif
   624             connectToChannel(iNowPlayingPreset,iConnectedFrom);
   642             connectToChannel(iNowPlayingPreset,iConnectedFrom);
   625             iResuming = false;
   643             iResuming = false;
   626             return;
   644             return;
   627         }
   645         }
   628 
   646 
   679         
   697         
   680         iPlayState = EPlaying;
   698         iPlayState = EPlaying;
   681         iApplication->stopLoadingAnimation();
   699         iApplication->stopLoadingAnimation();
   682 
   700 
   683         iApplication->getViewManager()->activateView(EIRView_PlayingView);
   701         iApplication->getViewManager()->activateView(EIRView_PlayingView);
   684 
   702         if( !iApplication->isEmbeddedInstance() )
   685         //update last played station
   703         {
   686         IRLastPlayedStationInfo *lastPlayedStationInfo = iApplication->getLastPlayedStationInfo();
   704             //update last played station
   687         lastPlayedStationInfo->updateLastPlayedStation(iNowPlayingPreset,iConnectedFrom);
   705             IRLastPlayedStationInfo *lastPlayedStationInfo = iApplication->getLastPlayedStationInfo();
   688         lastPlayedStationInfo->commitLastPlayedStation();
   706             lastPlayedStationInfo->updateLastPlayedStation(iNowPlayingPreset,iConnectedFrom);
       
   707             lastPlayedStationInfo->commitLastPlayedStation();
       
   708         }        
   689 
   709 
   690         //increase the played times of current preset
   710         //increase the played times of current preset
   691         iApplication->getFavoritesDB()->increasePlayedTimes(*iNowPlayingPreset);
   711         iApplication->getFavoritesDB()->increasePlayedTimes(*iNowPlayingPreset);
   692 
   712 
   693         emit playingStarted();
   713         emit playingStarted();
   694 
   714 
   695         // if the metadata is available, show it.
   715         // if the metadata is available, show it.
   696         emit metaDataAvailable(iMetaData);
   716         emit metaDataAvailable(iMetaData);
   697 
   717         
   698         // Save the station information to database
   718         if( !iApplication->isEmbeddedInstance() )
   699         IRQMetaData tmpMetaData;
   719         {
   700         tmpMetaData.setBitrate(iRealBitrate);
   720             // Save the station information to database
   701         tmpMetaData.setStreamUrl(iLastPlayedUrl);
   721             IRQMetaData tmpMetaData;
   702         iSongHistoryEngine->handleMetaDataReceived(tmpMetaData, *iNowPlayingPreset);
   722             tmpMetaData.setBitrate(iRealBitrate);
       
   723             tmpMetaData.setStreamUrl(iLastPlayedUrl);
       
   724             iSongHistoryEngine->handleMetaDataReceived(tmpMetaData, *iNowPlayingPreset);            
       
   725         }
       
   726 
   703         // open stereo defaultly
   727         // open stereo defaultly
   704         iMediaPlayer->enableStereoEffect();
   728         iMediaPlayer->enableStereoEffect();
   705     }
   729     }
   706 }
   730 }
   707 
   731 
   779 {
   803 {
   780     connect(iMediaPlayer, SIGNAL(connectionEstablished(int)), this, SLOT(connectionEstablished(int)));
   804     connect(iMediaPlayer, SIGNAL(connectionEstablished(int)), this, SLOT(connectionEstablished(int)));
   781     connect(iMediaPlayer, SIGNAL(errorOccured(IRQError)), this, SLOT(errorOccured(IRQError)));
   805     connect(iMediaPlayer, SIGNAL(errorOccured(IRQError)), this, SLOT(errorOccured(IRQError)));
   782     connect(iMediaPlayer, SIGNAL(percentageBuffered(int)), this, SLOT(updateProgress(int)));
   806     connect(iMediaPlayer, SIGNAL(percentageBuffered(int)), this, SLOT(updateProgress(int)));
   783     connect(iMediaPlayer, SIGNAL(volumeExpected(int&)), this, SLOT(fetchVolume(int&)));
   807     connect(iMediaPlayer, SIGNAL(volumeExpected(int&)), this, SLOT(fetchVolume(int&)));
   784     connect(iMediaPlayer, SIGNAL(metaDataReceived(IRQMetaData&)),
   808     
   785             this, SLOT(handleMetaDataReceived(IRQMetaData&)));
   809     if( !iApplication->isEmbeddedInstance() )
       
   810     {
       
   811         connect(iMediaPlayer, SIGNAL(metaDataReceived(IRQMetaData&)),
       
   812                 this, SLOT(handleMetaDataReceived(IRQMetaData&)));        
       
   813     } 
   786 }
   814 }
   787 
   815 
   788 /*
   816 /*
   789  * Description : try to play the next url in the preset.
   817  * Description : try to play the next url in the preset.
   790  * return value: true: it will play next URL; false, not.
   818  * return value: true: it will play next URL; false, not.
   827                     break;
   855                     break;
   828             }        
   856             }        
   829             
   857             
   830             if(tryingContinue)
   858             if(tryingContinue)
   831             {
   859             {
   832                 HbMessageBox::information(tr("Connecting failed, try next URL"), (QObject*)NULL, NULL); 
   860 #ifdef SUBTITLE_STR_BY_LOCID
       
   861                 HbMessageBox::information(hbTrId("txt_irad_connecting_failed_try_next_address"), (QObject*)NULL, NULL, HbMessageBox::Ok);
       
   862 #else
       
   863                 HbMessageBox::information("Connecting failed, try next URL", (QObject*)NULL, NULL, HbMessageBox::Ok);
       
   864 #endif                 
   833                 delete iUrlArray;
   865                 delete iUrlArray;
   834                 iUrlArray = iNowPlayingPreset->getURLsForBitrate(iTryingBitrate);
   866                 iUrlArray = iNowPlayingPreset->getURLsForBitrate(iTryingBitrate);
   835                 iLastPlayedUrl = iUrlArray->at(0);
   867                 iLastPlayedUrl = iUrlArray->at(0);
       
   868                 // Set the status to EStopped because it didn't start to play at all and need not to 
       
   869                 // do stop action.
       
   870                 iPlayState = EStopped;
   836                 doPlay(iLastPlayedUrl);
   871                 doPlay(iLastPlayedUrl);
   837                 return true;
   872                 return true;
   838             }
   873             }
   839         }
   874         }
   840 
   875 
   841     }
   876     }
   842     else // try next url in iUrlArray
   877     else // try next url in iUrlArray
   843     {
   878     {
       
   879 #ifdef SUBTITLE_STR_BY_LOCID
       
   880         HbMessageBox::information(hbTrId("txt_irad_connecting_failed_try_next_address"), (QObject*)NULL, NULL, HbMessageBox::Ok);
       
   881 #else
       
   882         HbMessageBox::information("Connecting failed, try next URL", (QObject*)NULL, NULL, HbMessageBox::Ok);
       
   883 #endif   
   844         iLastPlayedUrl = iUrlArray->at(0);
   884         iLastPlayedUrl = iUrlArray->at(0);
       
   885         // Set the status to EStopped because it didn't start to play at all and need not to 
       
   886         // do stop action. 
       
   887         iPlayState = EStopped;
   845         doPlay(iLastPlayedUrl);
   888         doPlay(iLastPlayedUrl);
   846 
   889 
   847         HbMessageBox::information(tr("Connecting failed, try next URL"), (QObject*)NULL, NULL);
       
   848         return true;
   890         return true;
   849     }
   891     }
   850     
   892     
   851     return false;
   893     return false;
   852 }
   894 }
   853 
   895 
   854 /*
   896 /*
   855  * Description : complete the play action
   897  * Description : complete the play action
   856  */
   898  */
   857 void IRPlayController::doPlay(const QString& aUrl)
   899 void IRPlayController::doPlay(const QString aUrl)
   858 {
   900 {
   859     // stop player, disable stereo effect, emit playstopped signal 
   901     // stop player, disable stereo effect, emit playstopped signal 
   860     stop(EIRQUserTerminated);
   902     stop(EIRQUserTerminated);
   861 
   903 
   862     //call getIAPId() every time before refering to it, because in ALR, the access point can 
   904     //call getIAPId() every time before refering to it, because in ALR, the access point can