videoplayback/hbvideoplaybackview/controlsrc/mpxvideoplaybackprogressbar.cpp
changeset 36 8aed59de29f9
parent 35 3738fe97f027
child 37 4eb2df7f7cbe
equal deleted inserted replaced
35:3738fe97f027 36:8aed59de29f9
    13 *
    13 *
    14 * Description:  Implementation of QMPXVideoPlaybackProgressBar
    14 * Description:  Implementation of QMPXVideoPlaybackProgressBar
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 // Version : %version: da1mmcf#14 %
    18 // Version : %version: da1mmcf#18 %
    19 
    19 
    20 
    20 
    21 
    21 
    22 
    22 
    23 #include <QTime>
    23 #include <QTime>
       
    24 #include <QTimer>
    24 #include <QGraphicsSceneMouseEvent>
    25 #include <QGraphicsSceneMouseEvent>
    25 
    26 
    26 #include <hblabel.h>
    27 #include <hblabel.h>
    27 #include <hbprogressbar.h>
    28 #include <hbprogressslider.h>
       
    29 #include <hbextendedlocale.h>
    28 
    30 
    29 #include "mpxvideo_debug.h"
    31 #include "mpxvideo_debug.h"
    30 #include "mpxvideoplaybackprogressbar.h"
    32 #include "mpxvideoplaybackprogressbar.h"
    31 #include "mpxvideoplaybackdocumentloader.h"
    33 #include "mpxvideoplaybackdocumentloader.h"
    32 #include "mpxvideoplaybackcontrolscontroller.h"
    34 #include "mpxvideoplaybackcontrolscontroller.h"
    33 
    35 
       
    36 const int KSeekingTimeOut = 250;
       
    37 
    34 // -------------------------------------------------------------------------------------------------
    38 // -------------------------------------------------------------------------------------------------
    35 // QMPXVideoPlaybackProgressBar::QMPXVideoPlaybackProgressBar
    39 // QMPXVideoPlaybackProgressBar::QMPXVideoPlaybackProgressBar
    36 // -------------------------------------------------------------------------------------------------
    40 // -------------------------------------------------------------------------------------------------
    37 //
    41 //
    38 QMPXVideoPlaybackProgressBar::QMPXVideoPlaybackProgressBar( 
    42 QMPXVideoPlaybackProgressBar::QMPXVideoPlaybackProgressBar( 
    39         QMPXVideoPlaybackControlsController* controller )
    43         QMPXVideoPlaybackControlsController* controller )
    40     : mController( controller )
    44     : mController( controller )
    41     , mDuration( -1 )
    45     , mDuration( -1 )
       
    46     , mDraggingPosition( 0 )
       
    47     , mSetPosition( -1 )
    42     , mNeedToResumeAfterSetPosition( false )
    48     , mNeedToResumeAfterSetPosition( false )
    43     , mInitialized( false )
    49     , mInitialized( false )
    44     , mDragging( false )
    50     , mSliderDragging( false )
       
    51     , mLongTimeFormat( false )
       
    52     , mLiveStreaming( false )
    45 {
    53 {
    46     MPX_ENTER_EXIT(_L("QMPXVideoPlaybackProgressBar::QMPXVideoPlaybackProgressBar()"));
    54     MPX_ENTER_EXIT(_L("QMPXVideoPlaybackProgressBar::QMPXVideoPlaybackProgressBar()"));
    47 }
    55 }
    48 
    56 
    49 // -------------------------------------------------------------------------------------------------
    57 // -------------------------------------------------------------------------------------------------
    51 // -------------------------------------------------------------------------------------------------
    59 // -------------------------------------------------------------------------------------------------
    52 //
    60 //
    53 QMPXVideoPlaybackProgressBar::~QMPXVideoPlaybackProgressBar()
    61 QMPXVideoPlaybackProgressBar::~QMPXVideoPlaybackProgressBar()
    54 {
    62 {
    55     MPX_ENTER_EXIT(_L("QMPXVideoPlaybackProgressBar::~QMPXVideoPlaybackProgressBar()"));
    63     MPX_ENTER_EXIT(_L("QMPXVideoPlaybackProgressBar::~QMPXVideoPlaybackProgressBar()"));
       
    64 
       
    65     disconnect( mSeekingTimer, SIGNAL( timeout() ), this, SLOT( handleSeekingTimeout() ) );
       
    66 
       
    67     if ( mSeekingTimer )
       
    68     {
       
    69         if ( mSeekingTimer->isActive() )
       
    70         {
       
    71             mSeekingTimer->stop();
       
    72         }
       
    73 
       
    74         delete mSeekingTimer;
       
    75         mSeekingTimer = NULL;
       
    76     }
    56 }
    77 }
    57 
    78 
    58 // -------------------------------------------------------------------------------------------------
    79 // -------------------------------------------------------------------------------------------------
    59 // QMPXVideoPlaybackProgressBar::initialize
    80 // QMPXVideoPlaybackProgressBar::initialize
    60 // -------------------------------------------------------------------------------------------------
    81 // -------------------------------------------------------------------------------------------------
    69     // Don't need to initialize buttons once it gets initialized
    90     // Don't need to initialize buttons once it gets initialized
    70     //
    91     //
    71     if ( loader && ! mInitialized )
    92     if ( loader && ! mInitialized )
    72     {
    93     {
    73         mInitialized = true;
    94         mInitialized = true;
       
    95         mLiveStreaming = 
       
    96                 ( mController->fileDetails()->mPlaybackMode == EMPXVideoLiveStreaming )? true:false;
       
    97 
       
    98         //
       
    99         // Create a timer for seeking. 
       
   100         // We will issue SetPosition every KSeekingTimeOut msec to show the current frame to user
       
   101         //
       
   102         mSeekingTimer = new QTimer();
       
   103         mSeekingTimer->setSingleShot( false );
       
   104         mSeekingTimer->setInterval( KSeekingTimeOut );
       
   105         connect( mSeekingTimer, SIGNAL( timeout() ), this, SLOT( handleSeekingTimeout() ) );
    74 
   106 
    75         //
   107         //
    76         // progress slider
   108         // progress slider
    77         //
   109         //
    78         QGraphicsWidget *widget = loader->findWidget( QString( "progressSlider" ) );
   110         QGraphicsWidget *widget = loader->findWidget( QString( "progressSlider" ) );
    79         mProgressSlider = qobject_cast<HbProgressBar*>( widget );
   111         mProgressSlider = qobject_cast<HbProgressSlider*>( widget );
    80 
   112 
    81         //
   113         connect( mProgressSlider, SIGNAL( sliderPressed() ), this, SLOT( handleSliderPressed() ) );
    82         // position label
   114         connect( mProgressSlider, SIGNAL( sliderReleased() ), this, SLOT( handleSliderReleased() ) );
    83         //
   115         connect( mProgressSlider, SIGNAL( sliderMoved( int ) ), this, SLOT( handleSliderMoved( int ) ) );
    84         widget = loader->findWidget( QString( "positionLabel" ) );
       
    85         mPositionLabel= qobject_cast<HbLabel*>( widget );
       
    86 
       
    87         //
       
    88         // duration label
       
    89         //
       
    90         widget = loader->findWidget( QString( "durationLabel" ) );
       
    91         mDurationLabel= qobject_cast<HbLabel*>( widget );
       
    92 
   116 
    93         //
   117         //
    94         // If we init the progress bar after pp sends the duration informatin
   118         // If we init the progress bar after pp sends the duration informatin
    95         // we need to set the duration manually 
   119         // we need to set the duration manually 
    96         //
   120         //
    97         durationChanged( (qreal)mController->fileDetails()->mDuration / (qreal)KPbMilliMultiplier );
   121         durationChanged( (qreal)mController->fileDetails()->mDuration / (qreal)KPbMilliMultiplier );
       
   122 
       
   123         //
       
   124         // Set the position to 0 until we get position information
       
   125         //
       
   126         positionChanged( 0 );
    98     }
   127     }
    99 }
   128 }
   100 
   129 
   101 // -------------------------------------------------------------------------------------------------
   130 // -------------------------------------------------------------------------------------------------
   102 // QMPXVideoPlaybackProgressBar::durationChanged
   131 // QMPXVideoPlaybackProgressBar::durationChanged
   104 //
   133 //
   105 void QMPXVideoPlaybackProgressBar::durationChanged( int duration )
   134 void QMPXVideoPlaybackProgressBar::durationChanged( int duration )
   106 {
   135 {
   107     MPX_DEBUG(_L("QMPXVideoPlaybackControlsController::durationChanged duration = %d"), duration );
   136     MPX_DEBUG(_L("QMPXVideoPlaybackControlsController::durationChanged duration = %d"), duration );
   108 
   137 
   109     mDuration = duration;
   138     if ( mLiveStreaming )
   110 
   139     {
   111     mDurationLabel->setPlainText( valueToReadableFormat( mDuration ) );
   140         mProgressSlider->setMaxText( "Live" );
       
   141     }
       
   142     else
       
   143     {
       
   144         mDuration = duration;
       
   145 
       
   146         if ( ( mDuration / 3600 ) > 0 )
       
   147         {
       
   148             mLongTimeFormat = true;
       
   149         }
       
   150         else
       
   151         {
       
   152             mLongTimeFormat = false;
       
   153         }
       
   154 
       
   155         mProgressSlider->setMaxText( valueToReadableFormat( mDuration ) );
       
   156     }
       
   157 
   112     mProgressSlider->setRange( 0, mDuration );
   158     mProgressSlider->setRange( 0, mDuration );
   113 }
   159 }
   114 
   160 
   115 // -------------------------------------------------------------------------------------------------
   161 // -------------------------------------------------------------------------------------------------
   116 // QMPXVideoPlaybackProgressBar::positionChanged
   162 // QMPXVideoPlaybackProgressBar::positionChanged
   121     MPX_DEBUG(_L("QMPXVideoPlaybackControlsController::positionChanged position = %d"), position );
   167     MPX_DEBUG(_L("QMPXVideoPlaybackControlsController::positionChanged position = %d"), position );
   122 
   168 
   123     //
   169     //
   124     // While dragging event, don't update old position information from mpx framework
   170     // While dragging event, don't update old position information from mpx framework
   125     //
   171     //
   126     if ( ! mDragging )
   172     if ( ! mSliderDragging )
   127     {
   173     {
   128         updatePostion( position );
   174         updatePostion( position );
   129     }
   175     }
   130 }
   176 }
   131 
   177 
   137 {
   183 {
   138     if ( position < 0 )
   184     if ( position < 0 )
   139     {
   185     {
   140         position = 0;
   186         position = 0;
   141     }
   187     }
   142     else if ( position > mDuration )
   188     else if ( position > mDuration && ! mLiveStreaming )
   143     {
   189     {
   144         position = mDuration;
   190         position = mDuration;
   145     }
   191     }
   146 
   192 
   147     MPX_DEBUG(_L("QMPXVideoPlaybackControlsController::updatePostion position = %d"), position );
   193     MPX_DEBUG(_L("QMPXVideoPlaybackProgressBar::updatePostion position = %d"), position );
   148 
   194 
   149     mPositionLabel->setPlainText( valueToReadableFormat( position ) );
   195     mProgressSlider->setMinText( valueToReadableFormat( position ) );
   150     mProgressSlider->setProgressValue( position );
   196 
       
   197     //
       
   198     // Don't need to set the slider for live streaming
       
   199     //
       
   200     if ( ! mLiveStreaming )
       
   201     {
       
   202         mProgressSlider->setSliderValue( position );
       
   203         mProgressSlider->setProgressValue( position );
       
   204     }
   151 }
   205 }
   152 
   206 
   153 // -------------------------------------------------------------------------------------------------
   207 // -------------------------------------------------------------------------------------------------
   154 // QMPXVideoPlaybackProgressBar::valueToReadableFormat
   208 // QMPXVideoPlaybackProgressBar::valueToReadableFormat
   155 // -------------------------------------------------------------------------------------------------
   209 // -------------------------------------------------------------------------------------------------
   165     int second = value;
   219     int second = value;
   166 
   220 
   167     QTime time( hour ,minutes ,second );
   221     QTime time( hour ,minutes ,second );
   168     QString str;
   222     QString str;
   169 
   223 
   170     if ( hour == 0 )
   224     HbExtendedLocale locale = HbExtendedLocale::system();
   171     {
   225 
   172         str = time.toString("mm:ss");
   226     if ( mLongTimeFormat )
       
   227     {
       
   228         str = locale.format( time, r_qtn_time_durat_long );
   173     }
   229     }
   174     else
   230     else
   175     {
   231     {
   176         str = time.toString("hh:mm:ss");
   232         str = locale.format( time, r_qtn_time_durat_min_sec );
   177     }
   233     }
   178 
   234 
   179     return str;
   235     return str;
   180 }
   236 }
   181 
   237 
   182 // -------------------------------------------------------------------------------------------------
   238 // -------------------------------------------------------------------------------------------------
   183 // QMPXVideoPlaybackProgressBar::mousePressEvent
   239 // QMPXVideoPlaybackProgressBar::handleSliderPressed
   184 // -------------------------------------------------------------------------------------------------
   240 // -------------------------------------------------------------------------------------------------
   185 //
   241 //
   186 void QMPXVideoPlaybackProgressBar::mousePressEvent( QGraphicsSceneMouseEvent *event ) 
   242 void QMPXVideoPlaybackProgressBar::handleSliderPressed() 
   187 {
   243 {
   188     MPX_DEBUG(_L("QMPXVideoPlaybackProgressBar::mousePressEvent()"));
   244     MPX_ENTER_EXIT(_L("QMPXVideoPlaybackProgressBar::handleSliderPressed()"));
   189 
   245 
   190     mDragging = true;
   246     mSliderDragging = true;
   191 
   247 
   192     mController->resetDisappearingTimers( EMPXTimerCancel );
   248     mController->resetDisappearingTimers( EMPXTimerCancel );
   193 
   249 
   194     //
   250     //
   195     // Pause the playback if it's playing
   251     // Pause the playback if it's playing
   197     if( mController->state() == EPbStatePlaying )
   253     if( mController->state() == EPbStatePlaying )
   198     {
   254     {
   199         mNeedToResumeAfterSetPosition = true;
   255         mNeedToResumeAfterSetPosition = true;
   200         mController->handleCommand( EMPXPbvCmdCustomPause );   
   256         mController->handleCommand( EMPXPbvCmdCustomPause );   
   201     }
   257     }
   202 
   258 }
   203     event->accept();
   259 
   204 }
   260 // -------------------------------------------------------------------------------------------------
   205 
   261 // QMPXVideoPlaybackProgressBar::handleSliderMoved
   206 // -------------------------------------------------------------------------------------------------
   262 // -------------------------------------------------------------------------------------------------
   207 // QMPXVideoPlaybackProgressBar::mouseReleaseEvent
   263 //
   208 // -------------------------------------------------------------------------------------------------
   264 void QMPXVideoPlaybackProgressBar::handleSliderMoved( int value ) 
   209 //
   265 {
   210 void QMPXVideoPlaybackProgressBar::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
   266     MPX_DEBUG(_L("QMPXVideoPlaybackProgressBar::handleSliderMoved() position = %d"), value);
   211 {
   267 
   212     MPX_DEBUG(_L("QMPXVideoPlaybackProgressBar::mouseReleaseEvent()"));
   268     updatePostion( value );
   213 
   269 
   214     mDragging = false;
   270     //
   215 
   271     // If the slider is dragging, start the timer and seek every KSeekingTimeOut msec
       
   272     //
       
   273     if ( mSliderDragging )
       
   274     {
       
   275         mDraggingPosition = value;
       
   276         MPX_DEBUG(_L("QMPXVideoPlaybackProgressBar::handleSliderMoved() mDraggingPosition = %d"), mDraggingPosition);
       
   277 
       
   278         if ( mSeekingTimer && ! mSeekingTimer->isActive() )
       
   279         {
       
   280             mSeekingTimer->start();
       
   281         }
       
   282     }
       
   283     else
       
   284     {
       
   285         if ( value >= mDuration )
       
   286         {
       
   287             MPX_DEBUG(_L("QMPXVideoPlaybackProgressBar::setPosition() reached end of the clip"));
       
   288 
       
   289             mController->handleCommand( EMPXPbvCmdEndOfClip );
       
   290         }
       
   291         else
       
   292         {
       
   293             value = mProgressSlider->sliderValue();
       
   294 
       
   295             MPX_DEBUG(_L("QMPXVideoPlaybackProgressBar::setPosition() position = %d"), value);
       
   296             mController->handleCommand( EMPXPbvCmdSetPosition, value );
       
   297         }
       
   298     }
       
   299 }
       
   300 
       
   301 // -------------------------------------------------------------------------------------------------
       
   302 // QMPXVideoPlaybackProgressBar::handleSliderReleased
       
   303 // -------------------------------------------------------------------------------------------------
       
   304 //
       
   305 void QMPXVideoPlaybackProgressBar::handleSliderReleased()
       
   306 {
       
   307     MPX_ENTER_EXIT(_L("QMPXVideoPlaybackProgressBar::handleSliderReleased()"));
       
   308 
       
   309     mSliderDragging = false;
       
   310 
       
   311     if ( mSeekingTimer && mSeekingTimer->isActive() )
       
   312     {
       
   313         mSeekingTimer->stop();
       
   314     }
       
   315     
   216     mController->resetDisappearingTimers( EMPXTimerReset );
   316     mController->resetDisappearingTimers( EMPXTimerReset );
   217 
   317     int value = mProgressSlider->sliderValue();
   218     int position = 
   318 
   219         (int)( ( event->scenePos().x() - mProgressSlider->geometry().x() ) / 
   319     if ( value >= mDuration )
   220         mProgressSlider->geometry().width() * (qreal)mDuration );
   320     {
   221 
   321         MPX_DEBUG(_L("QMPXVideoPlaybackProgressBar::setPosition() reached end of the clip"));
   222     if ( position > mDuration )
       
   223     {
       
   224         mController->handleCommand( EMPXPbvCmdEndOfClip );
   322         mController->handleCommand( EMPXPbvCmdEndOfClip );
   225     }
   323     }
   226     else
   324     else
   227     {
   325     {
   228         if ( position < 0 )
   326         if ( value < 0 )
   229         {
   327         {
   230             position = 0;
   328             value = 0;
   231         }
   329         }
   232 
   330 
   233         mController->handleCommand( EMPXPbvCmdSetPosition, position );
   331         MPX_DEBUG(_L("QMPXVideoPlaybackProgressBar::setPosition() position = %d"), value);
       
   332         mController->handleCommand( EMPXPbvCmdSetPosition, value );
   234 
   333 
   235         //
   334         //
   236         // Resume if it was playing
   335         // Resume if it was playing
   237         //
   336         //
   238         if( mNeedToResumeAfterSetPosition )
   337         if( mNeedToResumeAfterSetPosition )
   239         {
   338         {
   240             mNeedToResumeAfterSetPosition = false;
   339             mNeedToResumeAfterSetPosition = false;
   241             mController->handleCommand( EMPXPbvCmdCustomPlay );
   340             mController->handleCommand( EMPXPbvCmdCustomPlay );
   242         }
   341         }
   243     }
   342     }
   244 
       
   245     event->accept();
       
   246 }
       
   247 
       
   248 // -------------------------------------------------------------------------------------------------
       
   249 // QMPXVideoPlaybackProgressBar::mouseMoveEvent
       
   250 // -------------------------------------------------------------------------------------------------
       
   251 //
       
   252 void QMPXVideoPlaybackProgressBar::mouseMoveEvent( QGraphicsSceneMouseEvent *event )
       
   253 {
       
   254     qreal result = 
       
   255         ( event->scenePos().x() - mProgressSlider->geometry().x() ) / 
       
   256         mProgressSlider->geometry().width() * (qreal)mDuration;
       
   257 
       
   258     updatePostion( result );
       
   259 
       
   260     event->accept();
       
   261 }
   343 }
   262 
   344 
   263 // -------------------------------------------------------------------------------------------------
   345 // -------------------------------------------------------------------------------------------------
   264 // QMPXVideoPlaybackProgressBar::updateWithFileDetails()
   346 // QMPXVideoPlaybackProgressBar::updateWithFileDetails()
   265 // -------------------------------------------------------------------------------------------------
   347 // -------------------------------------------------------------------------------------------------
   269 {
   351 {
   270     MPX_DEBUG(_L("QMPXVideoPlaybackProgressBar::updateControlsWithFileDetails()"));
   352     MPX_DEBUG(_L("QMPXVideoPlaybackProgressBar::updateControlsWithFileDetails()"));
   271 
   353 
   272     if ( details->mPlaybackMode == EMPXVideoLiveStreaming )
   354     if ( details->mPlaybackMode == EMPXVideoLiveStreaming )
   273     {
   355     {
   274         setEnabled( false );
   356         mProgressSlider->setEnabled( false );
   275         mDurationLabel->setPlainText( "Live" );
       
   276     }
   357     }
   277     else if ( details->mTvOutConnected && ! details->mTvOutPlayAllowed )
   358     else if ( details->mTvOutConnected && ! details->mTvOutPlayAllowed )
   278     {
   359     {
   279         setEnabled( false );
   360         mProgressSlider->setEnabled( false );
   280     }
   361     }
   281     else
   362     else if ( ! mProgressSlider->isEnabled() )
   282     {
   363     {
   283         setEnabled( true );
   364         mProgressSlider->setEnabled( true );
   284     }
   365     }
   285 }
   366 }
   286 
   367 
   287 // -------------------------------------------------------------------------------------------------
   368 // -------------------------------------------------------------------------------------------------
   288 // QMPXVideoPlaybackProgressBar::updateState()
   369 // QMPXVideoPlaybackProgressBar::updateState()
   290 //
   371 //
   291 void QMPXVideoPlaybackProgressBar::updateState( TMPXPlaybackState state )
   372 void QMPXVideoPlaybackProgressBar::updateState( TMPXPlaybackState state )
   292 {
   373 {
   293     MPX_DEBUG(_L("QMPXVideoPlaybackProgressBar::updateState() state = %d"), state );
   374     MPX_DEBUG(_L("QMPXVideoPlaybackProgressBar::updateState() state = %d"), state );
   294 
   375 
   295     if ( mController->viewMode() == EAudioOnlyView )
   376     switch ( state )
   296     {
   377     {
   297         switch ( state )
   378         case EPbStatePlaying:
   298         {
   379         case EPbStatePaused:
   299             case EPbStatePlaying:
   380         {
   300             case EPbStatePaused:
   381             if ( ! isEnabled() )
   301             {
   382             {
   302                 updateWithFileDetails( mController->fileDetails() );
   383                 setEnabled( true );
   303                 break;
       
   304             }
   384             }
   305             case EPbStateNotInitialised:
   385 
   306             case EPbStateInitialising:
   386             break;
   307             case EPbStateBuffering:
   387         }
       
   388         default:
       
   389         {
       
   390             if ( isEnabled() )
   308             {
   391             {
   309                 setEnabled( false );
   392                 setEnabled( false );
   310                 break;
       
   311             }
   393             }
   312         }
   394             break;
       
   395         }
       
   396     }
       
   397 }
       
   398 
       
   399 // -------------------------------------------------------------------------------------------------
       
   400 // QMPXVideoPlaybackProgressBar::handleSeekingTimeout()
       
   401 // -------------------------------------------------------------------------------------------------
       
   402 //
       
   403 void QMPXVideoPlaybackProgressBar::handleSeekingTimeout()
       
   404 {
       
   405     if ( mDraggingPosition >= mDuration )
       
   406     {
       
   407         mDraggingPosition = mDuration;
       
   408     }
       
   409     else if( mDraggingPosition < 0 )
       
   410     {
       
   411         mDraggingPosition = 0;
       
   412     }
       
   413 
       
   414     MPX_DEBUG(_L("QMPXVideoPlaybackProgressBar::handleSeekingTimeout() Dragging pos = %d, Set pos = %d")
       
   415             , mDraggingPosition, mSetPosition );
       
   416 
       
   417     if ( mSetPosition != mDraggingPosition )
       
   418     {
       
   419         mSetPosition = mDraggingPosition;
       
   420         mController->handleCommand( EMPXPbvCmdSetPosition, mSetPosition );
   313     }
   421     }
   314 }
   422 }
   315 
   423 
   316 //End of file
   424 //End of file