made the 'elapsed' and 'remaining' times change in sync

This commit is contained in:
fgerlits 2006-11-10 17:04:26 +00:00
parent e9ce767d07
commit f5eb8849a0
3 changed files with 56 additions and 29 deletions

View File

@ -191,7 +191,7 @@ class TimeConversion
* @param duration sleep for this duration.
*/
static void
sleep(Ptr<time_duration>::Ref duration) throw ();
sleep(Ptr<const time_duration>::Ref duration) throw ();
/**
* Convert a time_duration to a format used in SMILs.
@ -201,7 +201,7 @@ class TimeConversion
* @param duration the time duration to convert.
*/
static Ptr<std::string>::Ref
timeDurationToSmilString(Ptr<time_duration>::Ref duration)
timeDurationToSmilString(Ptr<const time_duration>::Ref duration)
throw ();
/**
@ -216,7 +216,7 @@ class TimeConversion
* @return the time duration in string format
*/
static Ptr<std::string>::Ref
timeDurationToHhMmSsString(Ptr<time_duration>::Ref duration)
timeDurationToHhMmSsString(Ptr<const time_duration>::Ref duration)
throw ();
/**
@ -232,7 +232,7 @@ class TimeConversion
* @return the time duration in string format
*/
static Ptr<std::string>::Ref
timeDurationToShortString(Ptr<time_duration>::Ref duration)
timeDurationToShortString(Ptr<const time_duration>::Ref duration)
throw ();
/**
@ -257,10 +257,21 @@ class TimeConversion
/**
* Get the number of digits used for fractional seconds
* in time durations.
* Returns the constant 6, for microsecond precision.
* @return the constant 6, for microsecond precision.
*/
static int
getNumberOfDigitsPrecision(void) throw ();
/**
* Round the time duration to the nearest second.
*
* @param duration the time to be rounded; it will not be
* modified.
* @return the rounded value.
*/
static Ptr<time_duration>::Ref
roundToNearestSecond(Ptr<const time_duration>::Ref duration)
throw ();
};

View File

@ -154,7 +154,7 @@ TimeConversion :: nowString(void)
* Sleep for the specified duration.
*----------------------------------------------------------------------------*/
void
TimeConversion :: sleep(Ptr<time_duration>::Ref duration)
TimeConversion :: sleep(Ptr<const time_duration>::Ref duration)
throw ()
{
int ret;
@ -179,7 +179,7 @@ TimeConversion :: sleep(Ptr<time_duration>::Ref duration)
*----------------------------------------------------------------------------*/
Ptr<std::string>::Ref
TimeConversion :: timeDurationToSmilString(
Ptr<time_duration>::Ref duration)
Ptr<const time_duration>::Ref duration)
throw ()
{
std::stringstream stringStream;
@ -202,38 +202,24 @@ TimeConversion :: timeDurationToSmilString(
*----------------------------------------------------------------------------*/
Ptr<std::string>::Ref
TimeConversion :: timeDurationToHhMmSsString(
Ptr<time_duration>::Ref duration)
Ptr<const time_duration>::Ref duration)
throw ()
{
int hours = duration->hours();
int minutes = duration->minutes();
int seconds = duration->seconds();
if (duration->fractional_seconds() >= 500000) {
++seconds;
}
if (seconds == 60) {
seconds = 0;
++minutes;
}
if (minutes == 60) {
minutes = 0;
++hours;
}
Ptr<time_duration>::Ref roundedDuration = roundToNearestSecond(
duration);
std::stringstream stringStream;
stringStream << std::dec
<< std::setw(2)
<< std::setfill('0')
<< hours
<< roundedDuration->hours()
<< ":"
<< std::setw(2)
<< std::setfill('0')
<< minutes
<< roundedDuration->minutes()
<< ":"
<< std::setw(2)
<< std::setfill('0')
<< seconds;
<< roundedDuration->seconds();
Ptr<std::string>::Ref result(new std::string(stringStream.str()));
return result;
@ -245,7 +231,7 @@ TimeConversion :: timeDurationToHhMmSsString(
*----------------------------------------------------------------------------*/
Ptr<std::string>::Ref
TimeConversion :: timeDurationToShortString(
Ptr<time_duration>::Ref duration)
Ptr<const time_duration>::Ref duration)
throw ()
{
std::stringstream stringStream;
@ -397,3 +383,32 @@ TimeConversion :: getNumberOfDigitsPrecision(void) throw ()
return numberOfDigitsPrecision;
}
/*------------------------------------------------------------------------------
* Round the time duration to the nearest second.
*----------------------------------------------------------------------------*/
Ptr<time_duration>::Ref
TimeConversion :: roundToNearestSecond(Ptr<const time_duration>::Ref duration)
throw ()
{
int hours = duration->hours();
int minutes = duration->minutes();
int seconds = duration->seconds();
if (duration->fractional_seconds() >= 500000) {
++seconds;
}
if (seconds == 60) {
seconds = 0;
++minutes;
}
if (minutes == 60) {
minutes = 0;
++hours;
}
Ptr<time_duration>::Ref roundedDuration(new time_duration(
hours, minutes, seconds, 0));
return roundedDuration;
}

View File

@ -184,7 +184,8 @@ NowPlaying :: setPlayable(Ptr<Playable>::Ref playable) throw ()
}
creatorLabel->set_markup(*infoString);
audioLength = playable->getPlaylength();
audioLength = TimeConversion::roundToNearestSecond(
playable->getPlaylength());
resetRemainsTimeState();
} else {