qtinternetradio/ui/src/irplaycontroller.cpp
changeset 8 3b03c28289e6
parent 5 0930554dc389
child 12 608f67c22514
equal deleted inserted replaced
5:0930554dc389 8:3b03c28289e6
    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     iNowPlayingPreset(new IRQPreset()),
    91     iNowPlayingPreset(new IRQPreset()),
       
    92     iNowPlayingPresetBackup(new IRQPreset()),
    92     iMetaData(NULL),
    93     iMetaData(NULL),
    93     iSongHistoryEngine(IRQSongHistoryEngine::openInstance()),
    94     iSongHistoryEngine(IRQSongHistoryEngine::openInstance()),
    94     iPlayState(EIdle),
    95     iPlayState(EIdle),
    95     iResuming(false),
    96     iResuming(false),
    96     iTryingBitrate(0),
    97     iTryingBitrate(0),
   112     delete iMediaPlayer;
   113     delete iMediaPlayer;
   113     iMediaPlayer = NULL;
   114     iMediaPlayer = NULL;
   114 
   115 
   115     delete iNowPlayingPreset;
   116     delete iNowPlayingPreset;
   116     iNowPlayingPreset = NULL;
   117     iNowPlayingPreset = NULL;
       
   118     delete iNowPlayingPresetBackup;
       
   119     iNowPlayingPresetBackup = NULL;
   117 
   120 
   118     delete iUrlArray;
   121     delete iUrlArray;
   119     iUrlArray = NULL;
   122     iUrlArray = NULL;
   120 
   123 
   121     if (iSongHistoryEngine)
   124     if (iSongHistoryEngine)
   168                 break;
   171                 break;
   169         }
   172         }
   170 
   173 
   171         // get URL to play
   174         // get URL to play
   172         iTryingBitrate = selectedBitRate;
   175         iTryingBitrate = selectedBitRate;
       
   176         
       
   177         //reserve the info in nowplay view
       
   178         *iNowPlayingPresetBackup = *iNowPlayingPreset;
   173         *iNowPlayingPreset = *aPreset;
   179         *iNowPlayingPreset = *aPreset;
       
   180         
   174         delete iUrlArray;
   181         delete iUrlArray;
   175         iUrlArray = NULL;
   182         iUrlArray = NULL;
   176         iUrlArray = iNowPlayingPreset->getURLsForBitrate(selectedBitRate);
   183         iUrlArray = iNowPlayingPreset->getURLsForBitrate(selectedBitRate);
   177         if (iUrlArray)
   184         if (iUrlArray)
   178         {
   185         {
   189             if (iLastPlayedUrl != iUrlArray->at(0))
   196             if (iLastPlayedUrl != iUrlArray->at(0))
   190             {
   197             {
   191                 emit initializeLogo();
   198                 emit initializeLogo();
   192             }
   199             }
   193 #endif
   200 #endif
       
   201             //reserve the info in nowplay view
       
   202             iLastPlayedUrlBackup = iLastPlayedUrl;
   194             iLastPlayedUrl = url;
   203             iLastPlayedUrl = url;
   195             iResuming = false;
   204             iResuming = false;
   196             doPlay(url);
   205             doPlay(url);
   197         }
   206         }
   198     }
   207     }
   417         }
   426         }
   418 		
   427 		
   419         // if there's NO other URL to try, show warning.
   428         // if there's NO other URL to try, show warning.
   420         if (iNowPlayingPreset->getChannelURLCount() == 1)
   429         if (iNowPlayingPreset->getChannelURLCount() == 1)
   421         {
   430         {
       
   431             //here recover info in nowplay view, only for cases:
       
   432             //1/a channel has one url. 2/ invoked by "go to station" view.
       
   433             //if a channel has more than one url, here can't be reached.
       
   434             iLastPlayedUrl = iLastPlayedUrlBackup;
       
   435             *iNowPlayingPreset = *iNowPlayingPresetBackup;
   422 		    stop(EIRQNoConnectionToServer);
   436 		    stop(EIRQNoConnectionToServer);
   423             break;
   437             break;
   424         }
   438         }
   425 
   439 
   426         if (iResuming)
   440         if (iResuming)
   447         stop(EIRQNoConnectionToServer);
   461         stop(EIRQNoConnectionToServer);
   448         break;
   462         break;
   449         
   463         
   450     case EIRQPlayerErrorAudioDeviceLost:
   464     case EIRQPlayerErrorAudioDeviceLost:
   451         //this is a temporary way to handle the plug-out event
   465         //this is a temporary way to handle the plug-out event
   452         iApplication->closeLoadingDialog();
   466         iApplication->stopLoadingAnimation();
   453 		stop(EIRQCallIsActivated);
   467 		stop(EIRQCallIsActivated);
   454         return;
   468         return;
   455         
   469         
   456     case EIRQPlayerErrorGeneral:
   470     case EIRQPlayerErrorGeneral:
   457     default:
   471     default:
   458         stop(EIRQUnknownTermination);
   472         stop(EIRQUnknownTermination);
   459         break;
   473         break;
   460     }
   474     }
   461 
   475 
   462     iApplication->closeLoadingDialog();
   476     iApplication->stopLoadingAnimation();
   463 
       
   464     createNote();
   477     createNote();
   465     qDebug("IRPlayController::handleError(), Exiting");
   478     qDebug("IRPlayController::handleError(), Exiting");
   466 }
   479 }
   467 
   480 
   468 /*
   481 /*
   473  */
   486  */
   474 void IRPlayController::updateProgress(int aProgress)
   487 void IRPlayController::updateProgress(int aProgress)
   475 {
   488 {
   476     if (100 == aProgress)
   489     if (100 == aProgress)
   477     {
   490     {
   478         iApplication->closeLoadingDialog();
   491         iApplication->stopLoadingAnimation();
   479 
   492 
   480         //updateProgress(100) sometimes can be called more than one time, to improve performance,
   493         //updateProgress(100) sometimes can be called more than one time, to improve performance,
   481         //we only need to do the following work once.
   494         //we only need to do the following work once.
   482         if (EBuffering == iPlayState)
   495         if (EBuffering == iPlayState)
   483         {
   496         {
   530             || (aIRmetaData.getArtistName().trimmed() != ""))
   543             || (aIRmetaData.getArtistName().trimmed() != ""))
   531     {
   544     {
   532         //when we are play the musicplayer and get the metadata from lower layer, we save the 
   545         //when we are play the musicplayer and get the metadata from lower layer, we save the 
   533         //song's metadata into the db.  After we save it to db, we emit the next signal to notify the UI         
   546         //song's metadata into the db.  After we save it to db, we emit the next signal to notify the UI         
   534         iSongHistoryEngine->handleSongMetaDataReceived(*iMetaData,
   547         iSongHistoryEngine->handleSongMetaDataReceived(*iMetaData,
   535                 iNowPlayingPreset->musicStoreStatus);  
   548                 *iNowPlayingPreset);  
   536     }   
   549     }   
   537 
   550 
   538     if (EPlaying == iPlayState)
   551     if (EPlaying == iPlayState)
   539     {
   552     {
   540         // This signal will cause addBanner() work. Sometimes the metadata will come before
   553         // This signal will cause addBanner() work. Sometimes the metadata will come before
   547  * Description : during buffering stage, cancel playing request
   560  * Description : during buffering stage, cancel playing request
   548  */
   561  */
   549 void IRPlayController::cancelBuffering()
   562 void IRPlayController::cancelBuffering()
   550 {
   563 {
   551     stop(EIRQUserTerminated);
   564     stop(EIRQUserTerminated);
   552     iApplication->closeLoadingDialog();
   565     iApplication->stopLoadingAnimation();
   553 }
   566 }
   554 
   567 
   555 //                                       private functions
   568 //                                       private functions
   556 
   569 
   557 /*
   570 /*
   656     iApplication->getNetworkController()->getIAPId(apId);
   669     iApplication->getNetworkController()->getIAPId(apId);
   657     qDebug("IRPlayController::doPlay, access point : %d", apId);
   670     qDebug("IRPlayController::doPlay, access point : %d", apId);
   658     iMediaPlayer->playStation(aUrl, apId);
   671     iMediaPlayer->playStation(aUrl, apId);
   659     iPlayState = EBuffering;
   672     iPlayState = EBuffering;
   660     startSession();
   673     startSession();
   661     iApplication->createLoadingDialog(this, SLOT(cancelBuffering()));
   674     iApplication->startLoadingAnimation(this, SLOT(cancelBuffering()));
   662 }
   675 }
   663 
   676 
   664 /*
   677 /*
   665  * Description : start a session
   678  * Description : start a session
   666  */
   679  */