FileDocCategorySizeDatePackage
SrtParser.javaAPI Docmp4parser 1.0-RC-172127Wed Dec 19 20:10:37 GMT 2012com.googlecode.mp4parser.srt

SrtParser

public class SrtParser extends Object
Parses a .srt file and creates a Track for it.

Fields Summary
Constructors Summary
Methods Summary
public static com.googlecode.mp4parser.authoring.tracks.TextTrackImplparse(java.io.InputStream is)

        LineNumberReader r = new LineNumberReader(new InputStreamReader(is, "UTF-8"));
        TextTrackImpl track = new TextTrackImpl();
        String numberString;
        while ((numberString = r.readLine()) != null) {
            String timeString = r.readLine();
            String lineString = "";
            String s;
            while (!((s = r.readLine()) == null || s.trim().equals(""))) {
                lineString += s + "\n";
            }

            long startTime = parse(timeString.split("-->")[0]);
            long endTime = parse(timeString.split("-->")[1]);

            track.getSubs().add(new TextTrackImpl.Line(startTime, endTime, lineString));

        }
        return track;
    
private static longparse(java.lang.String in)

        long hours = Long.parseLong(in.split(":")[0].trim());
        long minutes = Long.parseLong(in.split(":")[1].trim());
        long seconds = Long.parseLong(in.split(":")[2].split(",")[0].trim());
        long millies = Long.parseLong(in.split(":")[2].split(",")[1].trim());

        return hours * 60 * 60 * 1000 + minutes * 60 * 1000 + seconds * 1000 + millies;