videoplayback/videoplaybackcontrols/src/mpxvideoplaybackprogressbar.cpp
changeset 0 96612d01cf9f
child 6 7d91903f795f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Progress bar control
       
    15 *
       
    16 */
       
    17 
       
    18 // Version : %version: 15 %
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <eikenv.h>
       
    23 #include <gulicon.h>
       
    24 #include <AknUtils.h>
       
    25 #include <eiklabel.h>
       
    26 #include <StringLoader.h>
       
    27 #include <AknsDrawUtils.h>
       
    28 #include <aknlayoutscalable_apps.cdl.h>
       
    29 #include <aknlayoutscalable_avkon.cdl.h>
       
    30 #include <data_caging_path_literals.hrh>
       
    31 
       
    32 #include <mpxvideoplaybackcontrols.rsg>
       
    33 #include <mpxvideoplaybackcontrols.mbg>
       
    34 
       
    35 #include "mpxcommonvideoplaybackview.hrh"
       
    36 #include "mpxvideoplaybackprogressbar.h"
       
    37 #include "mpxvideoplaybackcontrolscontroller.h"
       
    38 #include "mpxvideoplaybackviewfiledetails.h"
       
    39 #include "mpxvideo_debug.h"
       
    40 
       
    41 #ifdef RD_TACTILE_FEEDBACK
       
    42 #include <touchfeedback.h>
       
    43 #endif //RD_TACTILE_FEEDBACK
       
    44 
       
    45 using namespace AknLayoutScalable_Apps;
       
    46 
       
    47 // CONSTANTS
       
    48 const TInt KMPXProgressSliderWidth = 20;
       
    49 const TInt KMPXSliderHeightOverProgresBar = 5;
       
    50 const TInt64 KMPXMicroSeconds = 1000000;
       
    51 const TInt KMPXOneHourInSeconds = 3600;
       
    52 
       
    53 // ============================ MEMBER FUNCTIONS ===================================================
       
    54 
       
    55 CMPXVideoPlaybackProgressBar::CMPXVideoPlaybackProgressBar(
       
    56     CMPXVideoPlaybackControlsController* aController )
       
    57     : iController( aController )
       
    58     , iPlaybackRatio( 0.0 )
       
    59     , iDownloadRatio( 0.0 )
       
    60     , iDragging( EFalse )
       
    61     , iPointerEventStarted( EFalse )
       
    62     , iWasPlaying ( EFalse )
       
    63     , iOldDLSize(0)
       
    64 {
       
    65 }
       
    66 
       
    67 // -------------------------------------------------------------------------------------------------
       
    68 // CMPXVideoPlaybackProgressBar::ConstructL()
       
    69 // Symbian 2nd phase constructor can leave.
       
    70 // -------------------------------------------------------------------------------------------------
       
    71 //
       
    72 void CMPXVideoPlaybackProgressBar::ConstructL( TRect aRect )
       
    73 {
       
    74     MPX_DEBUG(_L("CMPXVideoPlaybackProgressBar::ConstructL()"));
       
    75 
       
    76     SetRect( TRect(0, 0, aRect.Width(), aRect.Height()) );
       
    77 
       
    78     SetLayoutL();
       
    79     SkinChangeL();
       
    80 
       
    81     //
       
    82     //  Read time format strings from AVKON resource
       
    83     //
       
    84     iMinSecFormatString = iEikonEnv->AllocReadResourceL(R_QTN_TIME_DURAT_MIN_SEC);
       
    85     iHourMinSecFormatString = iEikonEnv->AllocReadResourceL(R_QTN_TIME_DURAT_LONG);
       
    86 
       
    87 
       
    88 #ifdef RD_TACTILE_FEEDBACK
       
    89     iFeedback = MTouchFeedback::Instance();
       
    90 #endif //RD_TACTILE_FEEDBACK
       
    91 }
       
    92 
       
    93 // -------------------------------------------------------------------------------------------------
       
    94 // CMPXVideoPlaybackProgressBar::NewL()
       
    95 // Two-phased constructor.
       
    96 // -------------------------------------------------------------------------------------------------
       
    97 //
       
    98 CMPXVideoPlaybackProgressBar* CMPXVideoPlaybackProgressBar::NewL(
       
    99     CMPXVideoPlaybackControlsController* aController,
       
   100     TRect aRect )
       
   101 {
       
   102     MPX_DEBUG(_L("CMPXVideoPlaybackProgressBar::NewL()"));
       
   103 
       
   104     CMPXVideoPlaybackProgressBar* self =
       
   105         new ( ELeave ) CMPXVideoPlaybackProgressBar( aController );
       
   106 
       
   107     CleanupStack::PushL( self );
       
   108     self->ConstructL( aRect );
       
   109     CleanupStack::Pop();
       
   110     return self;
       
   111 }
       
   112 
       
   113 // -------------------------------------------------------------------------------------------------
       
   114 // CMPXVideoPlaybackProgressBar::~CMPXVideoPlaybackProgressBar()
       
   115 // Destructor.
       
   116 // -------------------------------------------------------------------------------------------------
       
   117 //
       
   118 CMPXVideoPlaybackProgressBar::~CMPXVideoPlaybackProgressBar()
       
   119 {
       
   120     MPX_DEBUG(_L("CMPXVideoPlaybackProgressBar::~CMPXVideoPlaybackProgressBar()"));
       
   121 
       
   122     if ( iMinSecFormatString )
       
   123     {
       
   124         delete iMinSecFormatString;
       
   125         iMinSecFormatString = NULL;
       
   126     }
       
   127 
       
   128     if ( iHourMinSecFormatString )
       
   129     {
       
   130         delete iHourMinSecFormatString;
       
   131         iHourMinSecFormatString = NULL;
       
   132     }
       
   133 
       
   134     if ( iLiveStreamingString )
       
   135     {
       
   136         delete iLiveStreamingString;
       
   137         iLiveStreamingString = NULL;
       
   138     }
       
   139 
       
   140     if ( iFrameIcon )
       
   141     {
       
   142        delete iFrameIcon;
       
   143        iFrameIcon = NULL;
       
   144     }
       
   145 
       
   146     if ( iPlaybackIcon )
       
   147     {
       
   148        delete iPlaybackIcon;
       
   149        iPlaybackIcon = NULL;
       
   150     }
       
   151 
       
   152     if ( iDownloadIcon )
       
   153     {
       
   154        delete iDownloadIcon;
       
   155        iDownloadIcon = NULL;
       
   156     }
       
   157 
       
   158     if ( iSliderIcon )
       
   159     {
       
   160        delete iSliderIcon;
       
   161        iSliderIcon = NULL;
       
   162     }
       
   163 
       
   164     if ( iSelectedSliderIcon )
       
   165     {
       
   166        delete iSelectedSliderIcon;
       
   167        iSelectedSliderIcon = NULL;
       
   168     }
       
   169 
       
   170     if ( iPositionLabel )
       
   171     {
       
   172         delete iPositionLabel;
       
   173         iPositionLabel = NULL;
       
   174     }
       
   175 
       
   176     if ( iDurationLabel )
       
   177     {
       
   178         delete iDurationLabel;
       
   179         iDurationLabel = NULL;
       
   180     }
       
   181 
       
   182 #ifdef RD_TACTILE_FEEDBACK
       
   183     if (iFeedback)
       
   184     {
       
   185         iFeedback->RemoveFeedbackForControl(this);
       
   186     }
       
   187 #endif //RD_TACTILE_FEEDBACK
       
   188 
       
   189 }
       
   190 
       
   191 // -------------------------------------------------------------------------------------------------
       
   192 // CMPXVideoPlaybackProgressBar::HandleResourceChange()
       
   193 // -------------------------------------------------------------------------------------------------
       
   194 //
       
   195 void CMPXVideoPlaybackProgressBar::HandleResourceChange( TInt aType )
       
   196 {
       
   197     MPX_DEBUG(_L("CMPXVideoPlaybackProgressBar::HandleResourceChange(0x%X)"), aType);
       
   198 
       
   199     if ( aType == KAknsMessageSkinChange )
       
   200     {
       
   201         TRAP_IGNORE( SkinChangeL() );
       
   202     }
       
   203 
       
   204     CCoeControl::HandleResourceChange( aType );
       
   205 }
       
   206 
       
   207 // -------------------------------------------------------------------------------------------------
       
   208 // CMPXVideoPlaybackProgressBar::SetLayout()
       
   209 // -------------------------------------------------------------------------------------------------
       
   210 //
       
   211 void CMPXVideoPlaybackProgressBar::SetLayoutL()
       
   212 {
       
   213     MPX_DEBUG(_L("CMPXVideoPlaybackProgressBar::SetLayoutL()"));
       
   214 
       
   215     //
       
   216     // Calculate icon rects
       
   217     //
       
   218     TAknLayoutRect progressPaneRect;
       
   219     progressPaneRect.LayoutRect( iEikonEnv->EikAppUi()->ApplicationRect(),
       
   220                                  mp4_progress_pane(0).LayoutLine() );
       
   221 
       
   222     TRect progressRect = Rect();
       
   223     progressRect.iBr.iY = progressPaneRect.Rect().Height();
       
   224 
       
   225     TAknLayoutRect seekBarFrameRect;
       
   226     seekBarFrameRect.LayoutRect( progressRect, mup_progress_pane_cp04().LayoutLine() );
       
   227 
       
   228     iFrameIconRect = seekBarFrameRect.Rect();
       
   229 
       
   230     iSliderRect.iTl.iY = iFrameIconRect.iTl.iY - KMPXSliderHeightOverProgresBar;
       
   231     iSliderRect.iBr.iY = iFrameIconRect.iBr.iY + KMPXSliderHeightOverProgresBar;
       
   232 
       
   233     //
       
   234     // Create labels
       
   235     //
       
   236     if ( iPositionLabel )
       
   237     {
       
   238         delete iPositionLabel;
       
   239         iPositionLabel = NULL;
       
   240     }
       
   241 
       
   242     iPositionLabel = new (ELeave) CEikLabel;
       
   243     AknLayoutUtils::LayoutLabel( iPositionLabel,
       
   244                                  progressRect,
       
   245                                  mp4_progress_pane_t1().LayoutLine() ) ;
       
   246 
       
   247     iPositionLabel->SetContainerWindowL( *this );
       
   248     iPositionLabel->SetTextL( KNullDesC );
       
   249     iPositionLabel->MakeVisible( ETrue );
       
   250 
       
   251     if ( iDurationLabel )
       
   252     {
       
   253         delete iDurationLabel;
       
   254         iDurationLabel = NULL;
       
   255     }
       
   256 
       
   257     iDurationLabel = new (ELeave) CEikLabel;
       
   258 
       
   259     AknLayoutUtils::LayoutLabel( iDurationLabel,
       
   260                                  progressRect,
       
   261                                  mp4_progress_pane_t2().LayoutLine() );
       
   262 
       
   263     iDurationLabel->SetContainerWindowL( *this );
       
   264     iDurationLabel->SetTextL( KNullDesC );
       
   265     iDurationLabel->MakeVisible( ETrue );
       
   266 }
       
   267 
       
   268 // -------------------------------------------------------------------------------------------------
       
   269 // CMPXVideoPlaybackProgressBar::SkinChangeL()
       
   270 // -------------------------------------------------------------------------------------------------
       
   271 //
       
   272 void CMPXVideoPlaybackProgressBar::SkinChangeL()
       
   273 {
       
   274     MPX_DEBUG(_L("CMPXVideoPlaybackProgressBar::SkinChangeL()"));
       
   275 
       
   276     //
       
   277     // Create icons
       
   278     //
       
   279     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   280 
       
   281     TFileName iconsPath;
       
   282     iController->LocateBitmapFileL( iconsPath );
       
   283 
       
   284     delete iFrameIcon;
       
   285     iFrameIcon = NULL;
       
   286     iFrameIcon = AknsUtils::CreateGulIconL(
       
   287         skin,
       
   288         KAknsIIDQgnGrafMup2BarFrame,
       
   289         iconsPath,
       
   290         EMbmMpxvideoplaybackcontrolsQgn_graf_mup2_bar_frame,
       
   291         EMbmMpxvideoplaybackcontrolsQgn_graf_mup2_bar_frame_mask);
       
   292 
       
   293     if ( iFrameIcon )
       
   294     {
       
   295         AknIconUtils::SetSize( iFrameIcon->Bitmap(),
       
   296                                iFrameIconRect.Size(),
       
   297                                EAspectRatioNotPreserved );
       
   298     }
       
   299 
       
   300     delete iPlaybackIcon;
       
   301     iPlaybackIcon = NULL;
       
   302     iPlaybackIcon = AknsUtils::CreateGulIconL(
       
   303         skin,
       
   304         KAknsIIDQgnGrafMup2BarProgress2,
       
   305         iconsPath,
       
   306         EMbmMpxvideoplaybackcontrolsQgn_graf_mup2_bar_progress_2,
       
   307         EMbmMpxvideoplaybackcontrolsQgn_graf_mup2_bar_progress_2_mask);
       
   308 
       
   309     if ( iPlaybackIcon )
       
   310     {
       
   311         AknIconUtils::SetSize( iPlaybackIcon->Bitmap(),
       
   312                                iFrameIconRect.Size(),
       
   313                                EAspectRatioNotPreserved );
       
   314     }
       
   315 
       
   316     UpdateProgressBarStateL( iController->FileDetails() );
       
   317 }
       
   318 
       
   319 // -------------------------------------------------------------------------------------------------
       
   320 // CMPXVideoPlaybackProgressBar::HandlePointerEventL()
       
   321 // -------------------------------------------------------------------------------------------------
       
   322 //
       
   323 void CMPXVideoPlaybackProgressBar::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
   324 {
       
   325     MPX_DEBUG(_L("CMPXVideoPlaybackProgressBar::HandlePointerEventL()"));
       
   326 
       
   327     TMPXPlaybackState state = iController->State();
       
   328 
       
   329     //
       
   330     //  Block pointer events in the following cases:
       
   331     //  - The clip is not seekable
       
   332     //  - The state is not playing/paused
       
   333     //  - If TV-Out is connected and the clip is DRM protected
       
   334     //
       
   335     if ( iController->FileDetails()->iSeekable &&
       
   336          ( state == EPbStatePlaying || state == EPbStatePaused ) &&
       
   337          iController->IsTvOutPlaybackAllowed() )
       
   338     {
       
   339         TReal ratio = (TReal) ( aPointerEvent.iPosition.iX - iFrameIconRect.iTl.iX )/
       
   340                       (TReal)( iFrameIconRect.Width() - KMPXProgressSliderWidth );
       
   341 
       
   342         if ( ratio > 1.0 )
       
   343         {
       
   344             ratio = 1.0;
       
   345         }
       
   346         else if ( ratio < 0.0 )
       
   347         {
       
   348             ratio = 0.0;
       
   349         }
       
   350 
       
   351         if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   352         {
       
   353             HandleButtonDownEventL( ratio );
       
   354         }
       
   355         else if ( aPointerEvent.iType == TPointerEvent::EDrag )
       
   356         {
       
   357             HandleDraggingEventL( ratio );
       
   358         }
       
   359         else if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   360         {
       
   361             HandleButtonUpEventL( ratio );
       
   362         }
       
   363     }
       
   364 }
       
   365 
       
   366 // -------------------------------------------------------------------------------------------------
       
   367 //   CMPXVideoPlaybackProgressBar::HandleButtonDownEventL
       
   368 // -------------------------------------------------------------------------------------------------
       
   369 //
       
   370 void CMPXVideoPlaybackProgressBar::HandleButtonDownEventL( TReal aRatio )
       
   371 {
       
   372     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackProgressBar::HandleButtonDownEventL()"),
       
   373                    _L("ratio = %f"), aRatio );
       
   374 
       
   375     iPointerEventStarted = ETrue;
       
   376     iWasPlaying = iController->State() == EPbStatePlaying? ETrue:EFalse;
       
   377 
       
   378     if ( iWasPlaying )
       
   379     {
       
   380         iController->HandleCommandL( EMPXPbvCmdCustomPause );
       
   381     }
       
   382 
       
   383 #ifdef RD_TACTILE_FEEDBACK
       
   384     if ( iFeedback )
       
   385     {
       
   386 #ifdef SYMBIAN_BUILD_GCE
       
   387         iFeedback->InstantFeedback( ETouchFeedbackSlider );
       
   388 #else
       
   389         iFeedback->InstantFeedback( ETouchFeedbackBasic );
       
   390 #endif //SYMBIAN_BUILD_GCE        
       
   391     }
       
   392 #endif //RD_TACTILE_FEEDBACK
       
   393 
       
   394     iDragging = EFalse;
       
   395 
       
   396     //
       
   397     //  Check for PDL using the download icon
       
   398     //
       
   399     if ( iDownloadIcon && ( aRatio > iDownloadRatio ) )
       
   400     {
       
   401         aRatio = iDownloadRatio;
       
   402     }
       
   403 
       
   404     PositionChangedL( aRatio * iDuration, ETrue );
       
   405 }
       
   406 
       
   407 // -------------------------------------------------------------------------------------------------
       
   408 //   CMPXVideoPlaybackProgressBar::HandleDraggingEventL
       
   409 // -------------------------------------------------------------------------------------------------
       
   410 //
       
   411 void CMPXVideoPlaybackProgressBar::HandleDraggingEventL( TReal aRatio )
       
   412 {
       
   413     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackProgressBar::HandleDraggingEventL()"),
       
   414                    _L("ratio = %f"), aRatio );
       
   415 
       
   416 #ifdef RD_TACTILE_FEEDBACK
       
   417     if ( iFeedback )
       
   418     {
       
   419 #ifdef SYMBIAN_BUILD_GCE
       
   420         iFeedback->InstantFeedback( ETouchFeedbackSlider );
       
   421 #else
       
   422         iFeedback->InstantFeedback( ETouchFeedbackSensitive );
       
   423 #endif //SYMBIAN_BUILD_GCE        
       
   424     }
       
   425 #endif //RD_TACTILE_FEEDBACK
       
   426 
       
   427     iDragging = ETrue;
       
   428 
       
   429     if ( iDownloadIcon && ( aRatio > iDownloadRatio ) )
       
   430     {
       
   431         aRatio = iDownloadRatio;
       
   432     }
       
   433 
       
   434     PositionChangedL( aRatio * iDuration, ETrue );
       
   435 }
       
   436 
       
   437 // -------------------------------------------------------------------------------------------------
       
   438 //   CMPXVideoPlaybackProgressBar::HandleButtonUpEventL
       
   439 // -------------------------------------------------------------------------------------------------
       
   440 //
       
   441 void CMPXVideoPlaybackProgressBar::HandleButtonUpEventL( TReal aRatio )
       
   442 {
       
   443     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackProgressBar::HandleButtonUpEventL()"),
       
   444                    _L("ratio = %f"), aRatio );
       
   445 
       
   446     iDragging = EFalse;
       
   447 
       
   448     if ( ( ! iDownloadIcon && aRatio == 1.0 ) ||
       
   449          ( iDownloadIcon && aRatio == 1.0 && iDownloadRatio == 1.0 ) )
       
   450     {
       
   451         iController->HandleCommandL( EMPXPbvCmdEndOfClip );
       
   452     }
       
   453     else
       
   454     {
       
   455         if ( iDownloadIcon && ( aRatio >= iDownloadRatio ) )
       
   456         {
       
   457             aRatio = iDownloadRatio;
       
   458         }
       
   459 
       
   460         TInt position = (TInt)( aRatio * iDuration );
       
   461 
       
   462         PositionChangedL( position, ETrue );
       
   463 
       
   464         iController->HandleCommandL( EMPXPbvCmdSetPosition, position );
       
   465 
       
   466         if ( iWasPlaying )
       
   467         {
       
   468             iWasPlaying = EFalse;
       
   469             iController->HandleCommandL( EMPXPbvCmdCustomPlay );
       
   470         }
       
   471     }
       
   472 
       
   473     iPointerEventStarted = EFalse;
       
   474 }
       
   475 
       
   476 // -------------------------------------------------------------------------------------------------
       
   477 //   CMPXVideoPlaybackProgressBar::Draw()
       
   478 // -------------------------------------------------------------------------------------------------
       
   479 //
       
   480 void CMPXVideoPlaybackProgressBar::Draw( const TRect& aRect ) const
       
   481 {
       
   482     MPX_DEBUG(_L("CMPXVideoPlaybackProgressBar::Draw()"));
       
   483 
       
   484     CWindowGc& gc = SystemGc();
       
   485     gc.SetClippingRect( aRect );
       
   486 
       
   487     if ( Window().DisplayMode() == EColor16MAP )
       
   488     {
       
   489         gc.SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha );
       
   490         gc.SetBrushColor( TRgb::Color16MAP( 255 ) );
       
   491         gc.Clear( aRect );
       
   492     }
       
   493     else if ( Window().DisplayMode() == EColor16MA )
       
   494     {
       
   495         gc.SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha );
       
   496         gc.SetBrushColor( TRgb::Color16MA( 0 ) );
       
   497         gc.Clear( aRect );
       
   498     }
       
   499     else
       
   500     {
       
   501         // draw a solid background so that the entire progress
       
   502         // bar is shown not just the area representing the
       
   503         // portion that has been played.
       
   504         gc.SetBrushColor( KRgbBlack );
       
   505         gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   506         gc.DrawRect( aRect );
       
   507         gc.SetBrushStyle(CGraphicsContext::ENullBrush);
       
   508     }
       
   509 
       
   510     //
       
   511     // If it is live streaming, don't need to draw the progress bar
       
   512     //
       
   513     if ( ! iLiveStreamingString )
       
   514     {
       
   515         if ( iFrameIcon )
       
   516         {
       
   517             gc.BitBltMasked( iFrameIconRect.iTl,
       
   518                              iFrameIcon->Bitmap(),
       
   519                              TRect( iFrameIconRect.Size() ),
       
   520                              iFrameIcon->Mask(),
       
   521                              ETrue );
       
   522         }
       
   523 
       
   524         if ( iDownloadIcon && iDownloadRatio )
       
   525         {
       
   526             gc.BitBltMasked( iDownloadRect.iTl,
       
   527                              iDownloadIcon->Bitmap(),
       
   528                              TRect( iDownloadRect.Size() ),
       
   529                              iDownloadIcon->Mask(),
       
   530                              ETrue );
       
   531         }
       
   532 
       
   533         if ( iPlaybackIcon && iPlaybackRatio )
       
   534         {
       
   535             gc.BitBltMasked( iPlaybackRect.iTl,
       
   536                              iPlaybackIcon->Bitmap(),
       
   537                              TRect( iPlaybackRect.Size() ),
       
   538                              iPlaybackIcon->Mask(),
       
   539                              ETrue );
       
   540         }
       
   541 
       
   542         if ( iSliderIcon && iSelectedSliderIcon && iController->State() != EPbStateStopped )
       
   543         {
       
   544             if ( iDragging )
       
   545             {
       
   546                 gc.BitBltMasked( iSliderRect.iTl,
       
   547                                  iSelectedSliderIcon->Bitmap(),
       
   548                                  TRect( iSliderRect.Size() ),
       
   549                                  iSelectedSliderIcon->Mask(),
       
   550                                  ETrue );
       
   551             }
       
   552             else
       
   553             {
       
   554                 gc.BitBltMasked( iSliderRect.iTl,
       
   555                                  iSliderIcon->Bitmap(),
       
   556                                  TRect( iSliderRect.Size() ),
       
   557                                  iSliderIcon->Mask(),
       
   558                                  ETrue );
       
   559             }
       
   560         }
       
   561     }
       
   562 }
       
   563 
       
   564 // -------------------------------------------------------------------------------------------------
       
   565 // CMPXVideoPlaybackProgressBar::CountComponentControls()
       
   566 // -------------------------------------------------------------------------------------------------
       
   567 //
       
   568 TInt CMPXVideoPlaybackProgressBar::CountComponentControls() const
       
   569 {
       
   570     return 2;
       
   571 }
       
   572 
       
   573 // -------------------------------------------------------------------------------------------------
       
   574 // CMPXVideoPlaybackProgressBar::ComponentControl()
       
   575 // -------------------------------------------------------------------------------------------------
       
   576 //
       
   577 CCoeControl* CMPXVideoPlaybackProgressBar::ComponentControl( TInt aIndex ) const
       
   578 {
       
   579     CCoeControl* control = NULL;
       
   580 
       
   581     switch ( aIndex )
       
   582     {
       
   583         case 0:
       
   584             control = iPositionLabel;
       
   585             break;
       
   586         case 1:
       
   587             control = iDurationLabel;
       
   588             break;
       
   589         default:
       
   590             break;
       
   591     }
       
   592 
       
   593     return control;
       
   594 }
       
   595 
       
   596 // -------------------------------------------------------------------------------------------------
       
   597 // CMPXVideoPlaybackProgressBar::DurationChangedL()
       
   598 // -------------------------------------------------------------------------------------------------
       
   599 //
       
   600 void CMPXVideoPlaybackProgressBar::DurationChangedL( TInt aDuration )
       
   601 {
       
   602     MPX_DEBUG(_L("CMPXVideoPlaybackProgressBar::DurationChangedL() [%d]"), aDuration);
       
   603 
       
   604     iDuration = aDuration;
       
   605 
       
   606     //
       
   607     //  In live streaming case,
       
   608     //  Will show "live streaming" text instead of remaining time
       
   609     //
       
   610     if ( iLiveStreamingString )
       
   611     {
       
   612         iDurationLabel->SetTextL( iLiveStreamingString->Des() );
       
   613     }
       
   614     else
       
   615     {
       
   616         if ( iDuration > 0 )
       
   617         {
       
   618             SetTextLWithReadableTimeL( iDuration, iDurationLabel );
       
   619         }
       
   620     }
       
   621 }
       
   622 
       
   623 // -------------------------------------------------------------------------------------------------
       
   624 // CMPXVideoPlaybackProgressBar::PositionChangedL()
       
   625 // -------------------------------------------------------------------------------------------------
       
   626 //
       
   627 void CMPXVideoPlaybackProgressBar::PositionChangedL( TInt aPosition, TBool aUserChanged )
       
   628 {
       
   629     MPX_DEBUG(_L("CMPXVideoPlaybackProgressBar::PositionChangedL() [%d]"), aPosition );
       
   630 
       
   631     //
       
   632     //  We will ignore position information which engine sent
       
   633     //  after we issue SetPosition()
       
   634     //
       
   635     if ( aPosition == 0 ||
       
   636          aUserChanged   ||
       
   637          (! iPointerEventStarted && iController->State() != EPbStatePaused ) )
       
   638     {
       
   639         TReal position = aPosition;
       
   640 
       
   641         if ( iDuration > 0 && position > iDuration )
       
   642         {
       
   643             position = iDuration;
       
   644         }
       
   645 
       
   646         SetTextLWithReadableTimeL( (TInt)position, iPositionLabel );
       
   647 
       
   648         if ( ! iLiveStreamingString )
       
   649         {
       
   650             iPlaybackRatio = position / iDuration;
       
   651             iPlaybackRect = iFrameIconRect;
       
   652 
       
   653             if ( iSliderIcon )
       
   654             {
       
   655                 iPlaybackRect.iBr.iX =
       
   656                     KMPXProgressSliderWidth / 2 + iPlaybackRatio *
       
   657                     ( iFrameIconRect.Width() - KMPXProgressSliderWidth );
       
   658 
       
   659                 iSliderRect.iTl.iX =
       
   660                     iPlaybackRect.iBr.iX - KMPXProgressSliderWidth/2;
       
   661                 iSliderRect.iBr.iX =
       
   662                     iPlaybackRect.iBr.iX + KMPXProgressSliderWidth/2;
       
   663             }
       
   664             else
       
   665             {
       
   666                 iPlaybackRect.iBr.iX = iPlaybackRatio * iFrameIconRect.Width();
       
   667             }
       
   668         }
       
   669 
       
   670         if ( IsVisible() )
       
   671         {
       
   672             DrawNow();
       
   673         }
       
   674     }
       
   675 }
       
   676 
       
   677 // -------------------------------------------------------------------------------------------------
       
   678 //   CMPXVideoPlaybackProgressBar::SetDownloadSize()
       
   679 // -------------------------------------------------------------------------------------------------
       
   680 //
       
   681 void CMPXVideoPlaybackProgressBar::SetDownloadSize( TInt aSize )
       
   682 {
       
   683     MPX_DEBUG(_L("CMPXVideoPlaybackProgressBar::SetDownloadSize() [%d]"), aSize );
       
   684 
       
   685     iDownloadSize = aSize;
       
   686 }
       
   687 
       
   688 // -------------------------------------------------------------------------------------------------
       
   689 //   CMPXVideoPlaybackProgressBar::UpdateDownloadPosition()
       
   690 // -------------------------------------------------------------------------------------------------
       
   691 //
       
   692 void CMPXVideoPlaybackProgressBar::UpdateDownloadPosition( TInt aSize )
       
   693 {
       
   694     MPX_DEBUG(_L("CMPXVideoPlaybackProgressBar::UpdateDownloadPosition() [%d]"), aSize );
       
   695 
       
   696     if ( iDownloadSize  && ( aSize > iOldDLSize ) )
       
   697     {
       
   698         iOldDLSize = aSize;
       
   699         iDownloadRatio = (TReal)aSize/(TReal)iDownloadSize;
       
   700 
       
   701         iDownloadRect= iFrameIconRect;
       
   702 
       
   703         if ( iDownloadIcon && iDownloadRatio > 0.0 )
       
   704         {
       
   705             iDownloadRect.iBr.iX = iDownloadRatio * iFrameIconRect.Width();
       
   706         }
       
   707 
       
   708         if ( IsVisible() )
       
   709         {
       
   710             DrawNow();
       
   711         }
       
   712     }
       
   713 }
       
   714 
       
   715 // -------------------------------------------------------------------------------------------------
       
   716 //   CMPXVideoPlaybackProgressBar::SetTextLWithReadableTimeL()
       
   717 // -------------------------------------------------------------------------------------------------
       
   718 //
       
   719 void CMPXVideoPlaybackProgressBar::SetTextLWithReadableTimeL( TInt aTime, CEikLabel* aLabel )
       
   720 {
       
   721     MPX_DEBUG(_L("CMPXVideoPlaybackProgressBar::SetTextLWithReadableTimeL() [%d]"), aTime);
       
   722 
       
   723     TBuf<16> text;
       
   724 
       
   725     TTime time = TTime( (TInt64)aTime * KMPXMicroSeconds );
       
   726 
       
   727     if ( iDuration > 0 && iDuration < KMPXOneHourInSeconds )
       
   728     {
       
   729         // Format time to user readable format. (min:sec)
       
   730         time.FormatL( text, *iMinSecFormatString );
       
   731     }
       
   732     else
       
   733     {
       
   734         // Format time to user readable format. (hour:min:sec)
       
   735         time.FormatL( text, *iHourMinSecFormatString );
       
   736     }
       
   737 
       
   738     if ( AknTextUtils::DigitModeQuery( AknTextUtils::EDigitModeShownToUser ) )
       
   739     {
       
   740         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( text );
       
   741     }
       
   742 
       
   743     aLabel->SetTextL( text );
       
   744 }
       
   745 
       
   746 // -------------------------------------------------------------------------------------------------
       
   747 //   CMPXVideoPlaybackProgressBar::UpdateProgressBarStateL()
       
   748 // -------------------------------------------------------------------------------------------------
       
   749 //
       
   750 void CMPXVideoPlaybackProgressBar::UpdateProgressBarStateL( CMPXVideoPlaybackViewFileDetails* aDetails )
       
   751 {
       
   752     MPX_DEBUG(_L("CMPXVideoPlaybackProgressBar::UpdateProgressBarStateL()"));
       
   753 
       
   754     //
       
   755     //  Update the duration in case it has not been initialized yet
       
   756     //
       
   757     DurationChangedL( (TReal)aDetails->iDuration / (TReal)KPbMilliMultiplier );
       
   758 
       
   759     TFileName iconsPath;
       
   760     iController->LocateBitmapFileL( iconsPath );
       
   761     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   762 
       
   763     if ( aDetails->iPlaybackMode == EMPXVideoProgressiveDownload )
       
   764     {
       
   765         delete iDownloadIcon;
       
   766         iDownloadIcon = NULL;
       
   767         iDownloadIcon = AknsUtils::CreateGulIconL(
       
   768             skin,
       
   769             KAknsIIDQgnGrafMup2BarProgress,
       
   770             iconsPath,
       
   771             EMbmMpxvideoplaybackcontrolsQgn_graf_mup2_bar_progress,
       
   772             EMbmMpxvideoplaybackcontrolsQgn_graf_mup2_bar_progress_mask );
       
   773 
       
   774         if ( iDownloadIcon )
       
   775         {
       
   776             AknIconUtils::SetSize( iDownloadIcon->Bitmap(),
       
   777                                    iFrameIconRect.Size(),
       
   778                                    EAspectRatioNotPreserved );
       
   779         }
       
   780     }
       
   781     else if ( aDetails->iPlaybackMode == EMPXVideoLiveStreaming )
       
   782     {
       
   783         iLiveStreamingString = iEikonEnv->AllocReadResourceL( R_MPX_LIVE_STREAMING );
       
   784 
       
   785         //
       
   786         //  update labels to show live streaming text
       
   787         //
       
   788         iDurationLabel->SetTextL( iLiveStreamingString->Des() );
       
   789     }
       
   790 
       
   791     if ( AknLayoutUtils::PenEnabled() && aDetails->iSeekable )
       
   792     {
       
   793         delete iSliderIcon;
       
   794         iSliderIcon = NULL;
       
   795         iSliderIcon = AknsUtils::CreateGulIconL(
       
   796             skin,
       
   797             KAknsIIDQgnGrafNsliderMarker,
       
   798             iconsPath,
       
   799             EMbmMpxvideoplaybackcontrolsQgn_graf_nslider_marker,
       
   800             EMbmMpxvideoplaybackcontrolsQgn_graf_nslider_marker_mask );
       
   801 
       
   802         delete iSelectedSliderIcon;
       
   803         iSelectedSliderIcon = NULL;
       
   804         iSelectedSliderIcon = AknsUtils::CreateGulIconL(
       
   805             skin,
       
   806             KAknsIIDQgnGrafNsliderMarkerSelected,
       
   807             iconsPath,
       
   808             EMbmMpxvideoplaybackcontrolsQgn_graf_nslider_marker_selected,
       
   809             EMbmMpxvideoplaybackcontrolsQgn_graf_nslider_marker_selected_mask );
       
   810 
       
   811         if ( iSliderIcon )
       
   812         {
       
   813             AknIconUtils::SetSize(
       
   814                 iSliderIcon->Bitmap(),
       
   815                 TSize( KMPXProgressSliderWidth,
       
   816                        iFrameIconRect.Height() + KMPXSliderHeightOverProgresBar*2 ),
       
   817                 EAspectRatioNotPreserved );
       
   818         }
       
   819 
       
   820         if ( iSelectedSliderIcon )
       
   821         {
       
   822             AknIconUtils::SetSize(
       
   823                 iSelectedSliderIcon->Bitmap(),
       
   824                 TSize( KMPXProgressSliderWidth,
       
   825                        iFrameIconRect.Height() + KMPXSliderHeightOverProgresBar*2 ),
       
   826                 EAspectRatioNotPreserved );
       
   827         }
       
   828     }
       
   829     else
       
   830     {
       
   831         //
       
   832         // for non-seekable media, disable iSliderIcon and iSelectedSliderIcon
       
   833         //
       
   834 
       
   835         if ( iSliderIcon )
       
   836         {
       
   837             delete iSliderIcon;
       
   838             iSliderIcon = NULL;
       
   839         }
       
   840 
       
   841         if ( iSelectedSliderIcon )
       
   842         {
       
   843             delete iSelectedSliderIcon;
       
   844             iSelectedSliderIcon = NULL;
       
   845         }
       
   846     }
       
   847 }
       
   848 
       
   849 // -------------------------------------------------------------------------------------------------
       
   850 // CMPXVideoPlaybackProgressBar::Reset
       
   851 // -------------------------------------------------------------------------------------------------
       
   852 //
       
   853 void CMPXVideoPlaybackProgressBar::Reset()
       
   854 {
       
   855     if ( iPointerEventStarted || iDragging )
       
   856     {
       
   857         TPointerEvent event;
       
   858         event.iType = TPointerEvent::EButton1Up;
       
   859         HandlePointerEventL(event);
       
   860     }
       
   861 }
       
   862 
       
   863 //  End of File