kenji123 / as3captionslib

An AS3 library for various subtitle formats.
http://www.kenshisoft.com/projects-resos/as3captionslib/
GNU General Public License v3.0
5 stars 1 forks source link

bug in asstimeline.as #2

Open ludicch opened 11 years ago

ludicch commented 11 years ago

hi, while searching for a error when displaying multiple captions at once i found a bug in the timeline function:

            for (var i:int=0; i < _captionsBuffer.length; i++)
            {
                if ((_currentTime >= _captionsBuffer[i].event.startSeconds) && (_currentTime < _captionsBuffer[i].event.endSeconds))
                {
                    caption = _captionsBuffer.splice(i, 1)[0];

                    renderer.add(caption, Vector.<ICaption>(_captionsOnDisplay), _container);

                    _captionsOnDisplay.push(caption);

                    captionDisplaySignal.dispatch(caption);

                    // quick fix i am trying right now
                    i--;
                }
            }
            Debug.GetInstance().Log(Debug.INFO, "ASSTimeLine.timeLine: loop end: "+i+" of "+_captionsBuffer.length);

the error occurs because at the same time _captionsBuffer is spliced and i is increased. so every subtitle displayed, makes the loop skip the next entry in the _captionsBuffer.

ludicch commented 11 years ago

the above works for me as a fix for the problem.

another issue i am unsure if this it's the way it's meant to be. in the buffer function in ASSTimeline.as

            for (var i:int = _lastBufferIndex; i < captions.events.length; i++)
            {
                if ((captions.events[i].startSeconds - _currentTime) < BUFFER_LENGTH)
                {
                    _captionsBuffer.push(renderer.render(captions, captions.events[i], _videoRect, _container, captions.events[i].startSeconds, animated));

                    _lastBufferIndex++;

                    // shoudnt this be        32 < (get....
                    // if you want to break after a too long loading loop the > is wrong
                    if (32 > (getTimer() - start)) break;
                }
                else
                {
                    break;
                }
            }

this works better for me, i can increase the timer (32) and everything gets loaded, in the other case during runtime it only loads 1 subtitle per function-call.

kenji123 commented 11 years ago

You're correct in both cases.