source: trunk/as3/com/jeroenwijering/parsers/TTParser.as @ 88

Revision 88, 1.1 KB checked in by jeroen, 5 years ago (diff)

merged 4.2 player to trunk

  • Property svn:executable set to *
Line 
1/**
2* Parse a TimedText XML and return an array of captions.
3**/
4package com.jeroenwijering.parsers {
5
6
7import com.jeroenwijering.utils.Strings;
8
9
10public class TTParser {
11
12
13        /**
14        * Parse the captions XML.
15        *
16        * @param dat    The loaded XML, which must be in W3C TimedText format.
17        * @return               An array with captions.
18        *                               Each caption is an object with 'begin', 'end' and 'text' parameters.
19        **/
20        public static function parseCaptions(dat:XML):Array {
21                var arr:Array = new Array();
22                for each (var i:XML in dat.children()) {
23                        if(i.localName() == "body") {
24                                for each (var j:XML in i.children()) {
25                                        for each (var k:XML in j.children()) {
26                                                if(k.localName() == 'p') {
27                                                        arr.push(TTParser.parseCaption(k));
28                                                }
29                                        }
30                                }
31                        }
32                }
33                return arr;
34        };
35
36
37        /** Parse a single captions entry. **/
38        private static function parseCaption(dat:XML):Object {
39                var obj:Object = {
40                        begin:Strings.seconds(dat.@begin),
41                        dur:Strings.seconds(dat.@dur),
42                        end:Strings.seconds(dat.@end),
43                        text:Strings.replace(dat.children().toString(),"\n","")
44                };
45                if(obj['dur']) {
46                        obj['end'] = obj['begin'] + obj['dur'];
47                        delete obj['dur'];
48                }
49                return obj;
50        };
51
52
53}
54
55
56}
Note: See TracBrowser for help on using the repository browser.