public function sync($_startIndex, $_startTime, $_endIndex, $_endTime, $_syncLast = true)
{
//set first and last subtitles index
if (!$_startIndex) {
$_startIndex = 0;
}
if (!$_endIndex) {
$_endIndex = $this->getCuesCount() - 1;
}
if (!$_syncLast) {
$_endIndex--;
}
//check subtitles do exist
$startSubtitle = $this->getCue($_startIndex);
$endSubtitle = $this->getCue($_endIndex);
if (!$startSubtitle || !$endSubtitle || $_startTime >= $_endTime) {
return false;
}
$shift = $_startTime - $startSubtitle->getStartMS();
$factor = ($_endTime - $_startTime) / ($endSubtitle->getStartMS() - $startSubtitle->getStartMS());
/* Shift subtitles to the start point */
if ($shift) {
$this->shift($shift, $_startIndex, $_endIndex);
}
/* Sync timings with proportion */
for ($index = $_startIndex; $index <= $_endIndex; $index++) {
$cue = $this->getCue($index);
$cue->scale($_startTime, $factor);
}
return true;
}