videoplayback/videohelix/src/mpxvideoplaybackstate.cpp
changeset 36 8aed59de29f9
parent 35 3738fe97f027
child 37 4eb2df7f7cbe
equal deleted inserted replaced
35:3738fe97f027 36:8aed59de29f9
    13 *
    13 *
    14 * Description:  This class plays local video file
    14 * Description:  This class plays local video file
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 // Version : %version: e003sa33#36 %
    18 
       
    19 // Version : %version: 39 %
    19 
    20 
    20 
    21 
    21 //
    22 //
    22 //  INCLUDE FILES
    23 //  INCLUDE FILES
    23 //
    24 //
   114     MPX_DEBUG(_L("CMPXVideoPlaybackState::HandlePlay()"));
   115     MPX_DEBUG(_L("CMPXVideoPlaybackState::HandlePlay()"));
   115 }
   116 }
   116 
   117 
   117 //  ------------------------------------------------------------------------------------------------
   118 //  ------------------------------------------------------------------------------------------------
   118 //    CMPXVideoPlaybackState::HandlePause()
   119 //    CMPXVideoPlaybackState::HandlePause()
   119 //
       
   120 //   @@FP for now we are assuming that Pause is only valid for Playing state
       
   121 //  ------------------------------------------------------------------------------------------------
   120 //  ------------------------------------------------------------------------------------------------
   122 void CMPXVideoPlaybackState::HandlePause()
   121 void CMPXVideoPlaybackState::HandlePause()
   123 {
   122 {
   124     MPX_DEBUG(_L("CMPXVideoPlaybackState::HandlePause()"));
   123     MPX_DEBUG(_L("CMPXVideoPlaybackState::HandlePause()"));
   125 }
   124 }
   185 //    CMPXVideoPlaybackState::HandleBackground()
   184 //    CMPXVideoPlaybackState::HandleBackground()
   186 //  ------------------------------------------------------------------------------------------------
   185 //  ------------------------------------------------------------------------------------------------
   187 void CMPXVideoPlaybackState::HandleBackground()
   186 void CMPXVideoPlaybackState::HandleBackground()
   188 {
   187 {
   189     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackState::HandleBackground()"));
   188     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackState::HandleBackground()"));
   190 
       
   191     // Just pause the plackback
       
   192     HandlePause();
   189     HandlePause();
   193 }
   190 }
   194 
   191 
   195 //  ------------------------------------------------------------------------------------------------
   192 //  ------------------------------------------------------------------------------------------------
   196 //    CMPXVideoPlaybackState::HandleOpenComplete()
   193 //    CMPXVideoPlaybackState::HandleOpenComplete()
   524     {
   521     {
   525         aMedia->SetTObjectValueL<TInt>(
   522         aMedia->SetTObjectValueL<TInt>(
   526             TMPXAttribute( KMPXMediaVideoDrmProtected ),
   523             TMPXAttribute( KMPXMediaVideoDrmProtected ),
   527             iVideoPlaybackCtlr->iFileDetails->iDrmProtected );
   524             iVideoPlaybackCtlr->iFileDetails->iDrmProtected );
   528     }
   525     }
   529     
   526 
   530     //
   527     //
   531     //  Description
   528     //  Description
   532     //
   529     //
   533     if ( ( attrV & KMPXMediaVideoDescription.iAttributeId ) &&
   530     if ( ( attrV & KMPXMediaVideoDescription.iAttributeId ) &&
   534          ( iVideoPlaybackCtlr->iFileDetails->iDescription ) )
   531          ( iVideoPlaybackCtlr->iFileDetails->iDescription ) )
   535     {
   532     {
   536         aMedia->SetTextValueL(
   533         aMedia->SetTextValueL(
   537             TMPXAttribute( KMPXMediaVideoDescription ),
   534             TMPXAttribute( KMPXMediaVideoDescription ),
   538             *( iVideoPlaybackCtlr->iFileDetails->iDescription ) );
   535             *( iVideoPlaybackCtlr->iFileDetails->iDescription ) );
   539     }
   536     }
   540     
   537 
   541     //
   538     //
   542     //  Location
   539     //  Location
   543     //
   540     //
   544     if ( ( attrV & KMPXMediaVideoLocation.iAttributeId ) &&
   541     if ( ( attrV & KMPXMediaVideoLocation.iAttributeId ) &&
   545          ( iVideoPlaybackCtlr->iFileDetails->iLocation ) )
   542          ( iVideoPlaybackCtlr->iFileDetails->iLocation ) )
   546     {
   543     {
   547         aMedia->SetTextValueL(
   544         aMedia->SetTextValueL(
   548             TMPXAttribute( KMPXMediaVideoLocation ),
   545             TMPXAttribute( KMPXMediaVideoLocation ),
   549             *( iVideoPlaybackCtlr->iFileDetails->iLocation ) );
   546             *( iVideoPlaybackCtlr->iFileDetails->iLocation ) );
   550     }
   547     }
   551     
   548 
   552     //
   549     //
   553     //  Copyright
   550     //  Copyright
   554     //
   551     //
   555     if ( ( attrV & KMPXMediaVideoCopyright.iAttributeId ) &&
   552     if ( ( attrV & KMPXMediaVideoCopyright.iAttributeId ) &&
   556          ( iVideoPlaybackCtlr->iFileDetails->iCopyright ) )
   553          ( iVideoPlaybackCtlr->iFileDetails->iCopyright ) )
   557     {
   554     {
   558         aMedia->SetTextValueL(
   555         aMedia->SetTextValueL(
   559             TMPXAttribute( KMPXMediaVideoCopyright ),
   556             TMPXAttribute( KMPXMediaVideoCopyright ),
   560             *( iVideoPlaybackCtlr->iFileDetails->iCopyright ) );
   557             *( iVideoPlaybackCtlr->iFileDetails->iCopyright ) );
   561     }
   558     }
   562  
   559 
   563     //
   560     //
   564     //  Language
   561     //  Language
   565     //
   562     //
   566     if ( ( attrV & KMPXMediaVideoLanguage.iAttributeId ) &&
   563     if ( ( attrV & KMPXMediaVideoLanguage.iAttributeId ) &&
   567          ( iVideoPlaybackCtlr->iFileDetails->iLanguage ) )
   564          ( iVideoPlaybackCtlr->iFileDetails->iLanguage ) )
   568     {
   565     {
   569         aMedia->SetTextValueL(
   566         aMedia->SetTextValueL(
   570             TMPXAttribute( KMPXMediaVideoLanguage ),
   567             TMPXAttribute( KMPXMediaVideoLanguage ),
   571             *( iVideoPlaybackCtlr->iFileDetails->iLanguage ) );
   568             *( iVideoPlaybackCtlr->iFileDetails->iLanguage ) );
   572     }
   569     }
   573      
   570 
   574     //
   571     //
   575     //  Keywords
   572     //  Keywords
   576     //
   573     //
   577     if ( ( attrV & KMPXMediaVideoKeywords.iAttributeId ) &&
   574     if ( ( attrV & KMPXMediaVideoKeywords.iAttributeId ) &&
   578          ( iVideoPlaybackCtlr->iFileDetails->iKeywords ) )
   575          ( iVideoPlaybackCtlr->iFileDetails->iKeywords ) )
   579     {
   576     {
   580         aMedia->SetTextValueL(
   577         aMedia->SetTextValueL(
   581             TMPXAttribute( KMPXMediaVideoKeywords ),
   578             TMPXAttribute( KMPXMediaVideoKeywords ),
   582             *( iVideoPlaybackCtlr->iFileDetails->iKeywords ) );
   579             *( iVideoPlaybackCtlr->iFileDetails->iKeywords ) );
   583     }        
   580     }
       
   581     
       
   582     //
       
   583     //  Creation date/time 
       
   584     //
       
   585     if ( attrV & KMPXMediaVideoCreated.iAttributeId )
       
   586     {
       
   587         aMedia->SetTObjectValueL<TInt>(
       
   588             TMPXAttribute( KMPXMediaVideoCreated ),
       
   589             iVideoPlaybackCtlr->iFileDetails->iCreationTime );
       
   590     }
       
   591 
       
   592     //
       
   593     //  Last Modified date/time 
       
   594     //
       
   595     if ( attrV & KMPXMediaVideoLastModified.iAttributeId )
       
   596     {
       
   597         aMedia->SetTObjectValueL<TInt>(
       
   598             TMPXAttribute( KMPXMediaVideoLastModified ),
       
   599             iVideoPlaybackCtlr->iFileDetails->iModificationTime );
       
   600     }
       
   601 
   584 }
   602 }
   585 
   603 
   586 //  ------------------------------------------------------------------------------------------------
   604 //  ------------------------------------------------------------------------------------------------
   587 //    CMPXVideoPlaybackState::SendErrorToViewL
   605 //    CMPXVideoPlaybackState::SendErrorToViewL
   588 //  ------------------------------------------------------------------------------------------------
   606 //  ------------------------------------------------------------------------------------------------
   671 //  ------------------------------------------------------------------------------------------------
   689 //  ------------------------------------------------------------------------------------------------
   672 void  CMPXVideoPlaybackState::CommandHandleBackground()
   690 void  CMPXVideoPlaybackState::CommandHandleBackground()
   673 {
   691 {
   674     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackState::CommandHandleBackground()"));
   692     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackState::CommandHandleBackground()"));
   675 
   693 
       
   694     //
       
   695     //  Block playback in the following cases:
       
   696     //  -  App is not in foreground
       
   697     //  -  Alarm
       
   698     //  -  Phone call
       
   699     //  -  Video call
       
   700     //
   676     if ( !iVideoPlaybackCtlr->iAppInForeground ||
   701     if ( !iVideoPlaybackCtlr->iAppInForeground ||
   677          iVideoPlaybackCtlr->IsAlarm() ||
   702          iVideoPlaybackCtlr->IsAlarm() ||
   678          iVideoPlaybackCtlr->IsPhoneCall() ||
   703          iVideoPlaybackCtlr->IsPhoneCall() ||
   679          iVideoPlaybackCtlr->IsVideoCall() )
   704          iVideoPlaybackCtlr->IsVideoCall() )
   680     {
   705     {
   687 //  ------------------------------------------------------------------------------------------------
   712 //  ------------------------------------------------------------------------------------------------
   688 void  CMPXVideoPlaybackState::CommandHandleForeground()
   713 void  CMPXVideoPlaybackState::CommandHandleForeground()
   689 {
   714 {
   690     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackState::CommandHandleForeground()"));
   715     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackState::CommandHandleForeground()"));
   691 
   716 
   692     if ( !iVideoPlaybackCtlr->IsActivePhoneCall() )
   717     if ( ! iVideoPlaybackCtlr->IsActivePhoneCall() )
   693     {
   718     {
   694         iVideoPlaybackCtlr->iAllowAutoPlay = ETrue;
   719         iVideoPlaybackCtlr->iAllowAutoPlay = ETrue;
   695     }
   720     }
   696 }
   721 }
   697 
   722 
   977         _L("error = %d"), aError );
  1002         _L("error = %d"), aError );
   978 
  1003 
   979     if ( aError == KErrNone )
  1004     if ( aError == KErrNone )
   980     {
  1005     {
   981         iVideoPlaybackCtlr->iPlaybackMode->HandleOpenComplete();
  1006         iVideoPlaybackCtlr->iPlaybackMode->HandleOpenComplete();
   982 		
  1007 
   983         //
  1008         //
   984 		//  call setposition with converted value saved in openfile
  1009         //  call setposition with converted value saved in openfile
   985         //
  1010         //
   986 		if ( iVideoPlaybackCtlr->iSavedPosition > 0 )
  1011         if ( iVideoPlaybackCtlr->iSavedPosition > 0 )
   987         {    
  1012         {
   988             MPX_DEBUG(_L("CMPXInitialisingState::HandleOpenComplete()  iSavedPosition %d"), iVideoPlaybackCtlr->iSavedPosition );
  1013             MPX_DEBUG(_L("CMPXInitialisingState::HandleOpenComplete()  iSavedPosition %d"), iVideoPlaybackCtlr->iSavedPosition );
   989                 
  1014 
   990             TInt64 pos( iVideoPlaybackCtlr->iSavedPosition );
  1015             TInt64 pos( iVideoPlaybackCtlr->iSavedPosition );
   991             pos *= KPbMilliMultiplier;
  1016             pos *= KPbMilliMultiplier;
   992             
  1017 
   993             MPX_TRAPD( err, iVideoPlaybackCtlr->iPlayer->SetPositionL( pos ) );
  1018             MPX_TRAPD( err, iVideoPlaybackCtlr->iPlayer->SetPositionL( pos ) );
   994         }
  1019         }
   995                
  1020 
   996         MPX_DEBUG(_L("CMPXInitialisingState::HandleOpenComplete()  Sending Prepare()"));
  1021         MPX_DEBUG(_L("CMPXInitialisingState::HandleOpenComplete()  Sending Prepare()"));
   997 
  1022 
   998         iVideoPlaybackCtlr->iPlayer->Prepare();
  1023         iVideoPlaybackCtlr->iPlayer->Prepare();
   999     }
  1024     }
  1000     else
  1025     else
  1711 {
  1736 {
  1712     MPX_DEBUG(_L("CMPXBufferingState::~CMPXBufferingState()"));
  1737     MPX_DEBUG(_L("CMPXBufferingState::~CMPXBufferingState()"));
  1713 }
  1738 }
  1714 
  1739 
  1715 //  ------------------------------------------------------------------------------------------------
  1740 //  ------------------------------------------------------------------------------------------------
  1716 //  CMPXBufferingState::HandleLoadingStarted()
  1741 //    CMPXBufferingState::HandleLoadingStarted()
  1717 //
       
  1718 //  We transition to Buffering state after Play command is issued initially
       
  1719 //
       
  1720 //  No state transitions necessary here as we are already in Buffering state
       
  1721 //  ------------------------------------------------------------------------------------------------
  1742 //  ------------------------------------------------------------------------------------------------
  1722 void CMPXBufferingState::HandleLoadingStarted()
  1743 void CMPXBufferingState::HandleLoadingStarted()
  1723 {
  1744 {
  1724     MPX_DEBUG(_L("CMPXBufferingState::HandleLoadingStarted()"));
  1745     MPX_DEBUG(_L("CMPXBufferingState::HandleLoadingStarted()"));
  1725 
  1746 
  1726     // no need to send any events - we are already in buffering state
  1747     TInt loadingPercentage = RetrieveBufferingPercentage();
       
  1748     
       
  1749     if ( loadingPercentage < 100 )
       
  1750     {
       
  1751         MPX_TRAPD( err,
       
  1752         {
       
  1753             CMPXMessage* message = CMPXMessage::NewL();
       
  1754             CleanupStack::PushL( message );
       
  1755     
       
  1756             message->SetTObjectValueL<TMPXMessageId>( KMPXMessageGeneralId, 
       
  1757                                                       KMPXMediaIdVideoPlayback );
       
  1758             
       
  1759             message->SetTObjectValueL<TMPXVideoPlaybackCommand>( KMPXMediaVideoPlaybackCommand, 
       
  1760                                                                  EPbCmdLoadingStarted );
       
  1761     
       
  1762             iVideoPlaybackCtlr->iMPXPluginObs->HandlePlaybackMessage( message, KErrNone );
       
  1763     
       
  1764             CleanupStack::PopAndDestroy( message );
       
  1765         } );
       
  1766     }
  1727 }
  1767 }
  1728 
  1768 
  1729 //  ------------------------------------------------------------------------------------------------
  1769 //  ------------------------------------------------------------------------------------------------
  1730 //  CMPXBufferingState::HandleLoadingComplete()
  1770 //  CMPXBufferingState::HandleLoadingComplete()
  1731 //  ------------------------------------------------------------------------------------------------
  1771 //  ------------------------------------------------------------------------------------------------
  1745                                                     0,
  1785                                                     0,
  1746                                                     KErrNone );
  1786                                                     KErrNone );
  1747         }
  1787         }
  1748         else
  1788         else
  1749         {
  1789         {
  1750             //  delayed pause :
  1790             //
  1751             //  background event was received while we were in buffering state
  1791             //  Delayed pause, background event was received while we were in buffering state
       
  1792             //
  1752             iVideoPlaybackCtlr->iPlaybackMode->HandlePause();
  1793             iVideoPlaybackCtlr->iPlaybackMode->HandlePause();
  1753         }
  1794         }
  1754     }
  1795     }
  1755     else
  1796     else
  1756     {
  1797     {
  1773                                                           0,
  1814                                                           0,
  1774                                                           KErrNone );
  1815                                                           KErrNone );
  1775 }
  1816 }
  1776 
  1817 
  1777 //  ------------------------------------------------------------------------------------------------
  1818 //  ------------------------------------------------------------------------------------------------
  1778 //  CMPXBufferingState::HandleBackground()
  1819 //    CMPXBufferingState::HandleBackground()
  1779 //  ------------------------------------------------------------------------------------------------
  1820 //  ------------------------------------------------------------------------------------------------
  1780 void CMPXBufferingState::HandleBackground()
  1821 void CMPXBufferingState::HandleBackground()
  1781 {
  1822 {
  1782     MPX_DEBUG(_L("CMPXBufferingState::HandleBackground()"));
  1823     MPX_DEBUG(_L("CMPXBufferingState::HandleBackground()"));
  1783 
       
  1784     // we are in buffering state and received a background event
       
  1785     // we cannot pause now but need to pause when buffering is complete
       
  1786     iVideoPlaybackCtlr->iPlaybackMode->HandleBackground();
  1824     iVideoPlaybackCtlr->iPlaybackMode->HandleBackground();
  1787 }
  1825 }
  1788 
  1826 
  1789 //  ------------------------------------------------------------------------------------------------
  1827 //  ------------------------------------------------------------------------------------------------
  1790 //  CMPXBufferingState::HandleForeground()
  1828 //  CMPXBufferingState::HandleForeground()
  1791 //  ------------------------------------------------------------------------------------------------
  1829 //  ------------------------------------------------------------------------------------------------
  1792 void CMPXBufferingState::HandleForeground()
  1830 void CMPXBufferingState::HandleForeground()
  1793 {
  1831 {
  1794     MPX_DEBUG(_L("CMPXBufferingState::HandleForeground()"));
  1832     MPX_DEBUG(_L("CMPXBufferingState::HandleForeground()"));
  1795 
  1833 
  1796     // we are in buffering state and received a background event
  1834     //
  1797     // we cannot pause now but need to pause when buffering is complete
  1835     //  We are in buffering state and received a background and foreground event
       
  1836     //  playback will continue when buffering is complete
       
  1837     //
  1798 }
  1838 }
  1799 
  1839 
  1800 //  ------------------------------------------------------------------------------------------------
  1840 //  ------------------------------------------------------------------------------------------------
  1801 //    CMPXBufferingState::HandlePause()
  1841 //    CMPXBufferingState::HandlePause()
  1802 //  ------------------------------------------------------------------------------------------------
  1842 //  ------------------------------------------------------------------------------------------------
  1886 //  ------------------------------------------------------------------------------------------------
  1926 //  ------------------------------------------------------------------------------------------------
  1887 //    CMPXSeekingState::HandleBackground()
  1927 //    CMPXSeekingState::HandleBackground()
  1888 //  ------------------------------------------------------------------------------------------------
  1928 //  ------------------------------------------------------------------------------------------------
  1889 void CMPXSeekingState::HandleBackground()
  1929 void CMPXSeekingState::HandleBackground()
  1890 {
  1930 {
  1891     MPX_DEBUG(_L("CMPXSeekingState::HandleBackground()"));
  1931     MPX_ENTER_EXIT(_L("CMPXSeekingState::HandleBackground()"));
       
  1932 
  1892     MPX_TRAPD( err, HandleStopSeekL() );
  1933     MPX_TRAPD( err, HandleStopSeekL() );
  1893     iVideoPlaybackCtlr->iPlaybackMode->HandleBackground();
  1934     iVideoPlaybackCtlr->iPlaybackMode->HandleBackground();
  1894 }
  1935 }
  1895 
  1936 
  1896 //  ------------------------------------------------------------------------------------------------
  1937 //  ------------------------------------------------------------------------------------------------
  1897 //  CMPXSeekingState::HandlePause()
  1938 //  CMPXSeekingState::HandlePause()
  1898 //  ------------------------------------------------------------------------------------------------
  1939 //  ------------------------------------------------------------------------------------------------
  1899 void CMPXSeekingState::HandlePause()
  1940 void CMPXSeekingState::HandlePause()
  1900 {
  1941 {
  1901     MPX_DEBUG(_L("CMPXSeekingState::HandlePause()"));
  1942     MPX_ENTER_EXIT(_L("CMPXSeekingState::HandlePause()"));
       
  1943 
  1902     MPX_TRAPD( err, HandleStopSeekL() );
  1944     MPX_TRAPD( err, HandleStopSeekL() );
  1903     iVideoPlaybackCtlr->iPlaybackMode->HandlePause();
  1945     iVideoPlaybackCtlr->iPlaybackMode->HandlePause();
  1904 }
  1946 }
  1905 
  1947 
  1906 //  ------------------------------------------------------------------------------------------------
  1948 //  ------------------------------------------------------------------------------------------------