as3-lib-subtitle is a library to load subtitle using some common formats. The lib has built-in support for the .srt and .sub formats, allowing developer to load those subtitle files and parse them. After the parsing is complete, it’s possible to retrieve the subtitle text by line or by time. The lib also has a display package with a subtitle viewer, a class that abstracts and encapsulate the process of displaying subtitles on the screen.
Two events are available to monitor the lib work. One is fired when a new subtitle is loaded, the other one is fired when it’s time to display a new line. Every text/line in the subtitle is handled as an item containing several information, such as its index, start/end time, duration and text.
Sample
var srt:SRTResource; srt = new SRTResource(); srt.parse("1\n00:00:15,431 --> 00:00:16,898\nHere goes the subtitle lines..."); var strTime:String = "00:00:15,431"; SRTResource.getTimeStamp(strTime); // Returns 15431 var findedsubitem:SubTitleItem = srt.getByTime(9999999); trace(findedsubitem.index); trace(findedsubitem.duration); trace(findedsubitem.startTime); trace(findedsubitem.endTime); // Load external subtitle file var subtitle:SRTResource = new SRTResource(); subtitle.load("fixtures/bigbang.srt"); subtitle.addEventListener(SubtitleEvent.LOADED_SUBTITLE, function(e:Event):void{ trace(subtitle.length); trace(subtitle.lines[0].duration); });
RT @as3gamegears: New: as3-lib-subtitle (lib to load subtitles using some common formats) http://t.co/LxZWOUoS2q #as3 #flash #gamedev