diff --git a/sjplayer/src/sjplayer/ScheduledControllerInterface.d b/sjplayer/src/sjplayer/ScheduledControllerInterface.d index aa875ad..244bd99 100644 --- a/sjplayer/src/sjplayer/ScheduledControllerInterface.d +++ b/sjplayer/src/sjplayer/ScheduledControllerInterface.d @@ -35,8 +35,9 @@ abstract class AbstractScheduledController : ScheduledControllerInterface { assert(next_operation_index_ <= operations_.length); const last_operation = &operations_[next_operation_index_-1]; - if (IsTimeInPeriod(time, last_operation.period)) { - ProcessOperation(time, *last_operation); + const period = last_operation.period; + if (IsTimeInPeriod(time, period)) { + ProcessOperation(period.ConvertToRelativeTime(time), *last_operation); return; } FinalizeOperation(*last_operation); @@ -47,7 +48,8 @@ abstract class AbstractScheduledController : ScheduledControllerInterface { const next_operation = &operations_[next_operation_index_]; if (IsTimeInPeriod(time, next_operation.period)) { PrepareOperation(*next_operation); - ProcessOperation(time, *next_operation); + ProcessOperation( + next_operation.period.ConvertToRelativeTime(time), *next_operation); ++next_operation_index_; } } diff --git a/sjplayer/src/sjplayer/util/Period.d b/sjplayer/src/sjplayer/util/Period.d index d0bfc9b..72660dc 100644 --- a/sjplayer/src/sjplayer/util/Period.d +++ b/sjplayer/src/sjplayer/util/Period.d @@ -12,3 +12,9 @@ bool IsTimeInPeriod(float time, in Period period) { bool IsPeriodIntersectedToPeriod(in Period p1, in Period p2) { return p1.start < p2.end && p2.start < p1.end; } + +/// +float ConvertToRelativeTime(in Period period, float src) + in (period.start < period.end) { + return (src - period.start) / (period.end - period.start); +}