Is there an android library which will parse/display an SMPTE Timed Text (captions) xml file?

449 Views Asked by At

I am retrieving SMPTE Timed Text xml files remotely which I need to parse and draw to a surface as captions.

The full file format is defined here:

https://www.smpte.org/sites/default/files/st2052-1-2010.pdf

The xml looks like this:

<tt xmlns="http://www.w3.org/ns/ttml">
    <head>
        ...
    </head>
    <body>
        <p begin="00:00:33:03" end="00:00:37:24" region="pop1" style="basic" tts:origin="20% 79.33%" tts:extent="60% 5.33%">It is on a little world,</p>
        <p begin="00:01:29:23" end="00:01:31:10" region="pop2" style="basic" tts:origin="30% 84.67%" tts:extent="50% 5.33%">GIVING INSTRUCTIONS)</p>
        ...
    </body>
</tt>

Basically each p tag defined a time and position and some text to draw. I haven't been able to find any native or third party libraries to help with this on android.

I'm looking for a library to read the xml file into an organized data structure of some sort. From there I can handle the drawing if need be.

Any pointers would be helpful before I start writing it myself, as taking into account all the different arguments can become quite involved.

Thankyou.

1

There are 1 best solutions below

0
On

I was able to use the simple library to marshal into the following classes. Setters and getters removed for brevity. At this point the code is just a proof of concept, but you get the idea.

Caption.java

// single caption to display (from SMPE-TT file)
@Root (name="p", strict=false)
public class Caption
{
    @Element (required = false, name = "font")
    private String caption;

    @Attribute
    private String begin;

    @Attribute
    private String end;

    @Attribute (required = false)
    private String origin;

    @Attribute (required = false)
    private String style;

    @Attribute (required = false)
    private String space;
}

TimedText.java

// class for marshalling the entire SMPE-TT file
@Root (name="tt")
public class TimedText
{
    @Attribute (required=false)
    private String lang;

    @Element (required=false)
    private String head;

    @Element (name = "body")
    private TTBody ttb;
}

class TTBody
{
    @Element (name = "div")
    private TTDiv ttd;
}

class TTDiv
{
    @ElementList (inline = true)
    private List<Caption> captionList;
}