Parsers parse Popcorn data into events. Data can be stored in various types. JSON and XML can store any kind of Popcorn event, while supported subtitle formats ( SBV, SRT, SSA, TTML, TTXT and VTT ) can be parsed into subtitle events.
parseJSON( fileName, callback )”
Purpose
The JSON parser will parse valid JSON into Popcorn events.
The user can also specify the source of their json file using a data-timeline-sources attribute on the media tag.
When Popcorn is instantiated, it will search each media element for a data-timeline-sources attribute and try and parse the specified file. NOTE: this requires the use of the data-timeline-sources module
Options
fileName [String] - A path to the JSON file.
callBack [Function] - An optional function to be executed when the JSON data has completed parsing.
Use Case
Parse a JSON file containing popcorn data
Example
Parses a JSON file:
1<html> 2<head> 3<script src="popcorn-complete.js"></script> 4<script type="text/javascript"> 5 6document.addEventListener('DOMContentLoaded',function(){ 7 8varp=Popcorn("#video"); 910p.parseJSON("data/data.json",function(){11alert("JSON Parsed Successfully");12});1314},false);1516</script>17</head>18<body>19<videoid="video"20controls21width='250px'22poster="../../test/poster.png">2324<sourceid='mp4'25src="../../test/trailer.mp4"type='video/mp4; codecs="avc1, mp4a"'>2627<sourceid='ogv'28src="../../test/trailer.ogv"29type='video/ogg; codecs="theora, vorbis"'>3031<p>Your user agent does not support the HTML5 Video element.</p>3233</video>34<divid="footnote-container"></div>35<divid="map-container"></div>36<divid="iframe-container"></div>37</body>38</html>
SBV parser
Purpose
The SBV parser allows the user to parse SBV subtitle data in order to populate a subtitle track event.
The user specifies the source of their SBV file in a data-timeline-sources attribute on the video object. When Popcorn is instantiated it will search each video element for a data-timeline-sources attribute and try and parse the specified file.
data-timeline-sources [String] - a media element attribute that specifies the source of the file to be parsed
Use Case
Parse a SBV file of subtitle data
Example
Parses a popcorn SBV subtitle file to populate a subtitle track
1<html> 2<head> 3<script src="popcorn-complete.js"></script> 4</head> 5<body> 6<videoid="video"data-timeline-sources="data/data.sbv" 7controls 8width='250px' 9poster="../../test/poster.png">1011<sourceid='mp4'12src="../../test/trailer.mp4"13type='video/mp4; codecs="avc1, mp4a"'>1415<sourceid='ogv'16src="../../test/trailer.ogv"17type='video/ogg; codecs="theora, vorbis"'>1819<p>Your user agent does not support the HTML5 Video element.</p>2021</video>22<divid="footnote-container"></div>23<divid="map-container"></div>24<divid="iframe-container"></div>25</body>26</html>
SRT parser
Purpose
The SRT parser allows the user to parse SRT subtitle data in order to populate a subtitle track event.
The user specifies the source of their SRT file in a data-timeline-sources attribute on the video object. When Popcorn is instantiated it will search each video element for a data-timeline-sources attribute and try and parse the specified file.
Options
data-timeline-sources [String] - a media element attribute that specifies the source of the file to be parsed
Use Case
Parse a SRT file of subtitle data
Example
Parses a popcorn SRT subtitle file to populate a subtitle track
1<html> 2<head> 3<script src="popcorn-complete.js"></script> 4</head> 5<body> 6<videoid="video"data-timeline-sources="data/data.srt" 7controls 8width='250px' 9poster="../../test/poster.png">1011<sourceid='mp4'12src="../../test/trailer.mp4"13type='video/mp4; codecs="avc1, mp4a"'>1415<sourceid='ogv'16src="../../test/trailer.ogv"17type='video/ogg; codecs="theora, vorbis"'>1819<p>Your user agent does not support the HTML5 Video element.</p>2021</video>22<divid="footnote-container"></div>23<divid="map-container"></div>24<divid="iframe-container"></div>25</body>26</html>
SSA parser
Purpose
The SSA parser allows the user to parse SSA subtitle data in order to populate a subtitle track event.
The user specifies the source of their SSA file in a data-timeline-sources attribute on the video object. When Popcorn is instantiated it will search each video element for a data-timeline-sources attribute and try and parse the specified file.
Options
data-timeline-sources [String] - a media element attribute that specifies the source of the file to be parsed
Use Case
Parse a SSA file of subtitle data
Example
Parses a popcorn SSA subtitle file to populate a subtitle track
1<html> 2<head> 3<script src="popcorn-complete.js"></script> 4</head> 5<body> 6<videoid="video"data-timeline-sources="data/data.ssa" 7controls 8width='250px' 9poster="../../test/poster.png">1011<sourceid='mp4'12src="../../test/trailer.mp4"13type='video/mp4; codecs="avc1, mp4a"'>1415<sourceid='ogv'16src="../../test/trailer.ogv"17type='video/ogg; codecs="theora, vorbis"'>1819<p>Your user agent does not support the HTML5 Video element.</p>2021</video>22<divid="footnote-container"></div>23<divid="map-container"></div>24<divid="iframe-container"></div>25</body>26</html>
TTML parser
Purpose
The TTML parser allows the user to parse TTML subtitle data in order to populate a subtitle track event.
The user specifies the source of their TTML file in a data-timeline-sources attribute on the video object. When Popcorn is instantiated it will search each video element for a data-timeline-sources attribute and try and parse the specified file.
Options
data-timeline-sources [String] - a media element attribute that specifies the source of the file to be parsed
Use Case
Parse a TTML file of subtitle data
Example
Parses a popcorn TTML subtitle file to populate a subtitle track
1<html> 2<head> 3<script src="popcorn-complete.js"></script> 4</head> 5<body> 6<videoid="video"data-timeline-sources="data/data.ttml" 7controls 8width='250px' 9poster="../../test/poster.png">1011<sourceid='mp4'12src="../../test/trailer.mp4"13type='video/mp4; codecs="avc1, mp4a"'>1415<sourceid='ogv'16src="../../test/trailer.ogv"17type='video/ogg; codecs="theora, vorbis"'>1819<p>Your user agent does not support the HTML5 Video element.</p>2021</video>22<divid="footnote-container"></div>23<divid="map-container"></div>24<divid="iframe-container"></div>25</body>26</html>
TTXT parser
Purpose
The TTXT parser allows the user to parse TTXT subtitle data in order to populate a subtitle track event.
The user specifies the source of their TTXT file in a data-timeline-sources attribute on the video object. When Popcorn is instantiated it will search each video element for a data-timeline-sources attribute and try and parse the specified file.
Options
data-timeline-sources [String] - a media element attribute that specifies the source of the file to be parsed
Use Case
Parse a TTXT file of subtitle data
Example
Parses a popcorn TTXT subtitle file to populate a subtitle track
1<html> 2<head> 3<script src="popcorn-complete.js"></script> 4</head> 5<body> 6<videoid="video"data-timeline-sources="data/data.ttxt" 7controls 8width='250px' 9poster="../../test/poster.png">1011<sourceid='mp4'12src="../../test/trailer.mp4"13type='video/mp4; codecs="avc1, mp4a"'>1415<sourceid='ogv'16src="../../test/trailer.ogv"17type='video/ogg; codecs="theora, vorbis"'>1819<p>Your user agent does not support the HTML5 Video element.</p>2021</video>22<divid="footnote-container"></div>23<divid="map-container"></div>24<divid="iframe-container"></div>25</body>26</html>
VTT parser
Purpose
The VTT parser allows the user to parse VTT subtitle data in order to populate a subtitle track event.
The user specifies the source of their VTT file in a data-timeline-sources attribute on the video object. When Popcorn is instantiated it will search each video element for a data-timeline-sources attribute and try and parse the specified file.
Options
data-timeline-sources [String] - a media element attribute that specifies the source of the file to be parsed
Use Case
Parse a VTT file of subtitle data
Example
Parses a popcorn VTT subtitle file to populate a subtitle track
1<html> 2<head> 3<script src="popcorn-complete.js"></script> 4</head> 5<body> 6<videoid="video"data-timeline-sources="data/data.vtt" 7controls 8width='250px' 9poster="../../test/poster.png">1011<sourceid='mp4'12src="../../test/trailer.mp4"13type='video/mp4; codecs="avc1, mp4a"'>1415<sourceid='ogv'16src="../../test/trailer.ogv"17type='video/ogg; codecs="theora, vorbis"'>1819<p>Your user agent does not support the HTML5 Video element.</p>2021</video>22<divid="footnote-container"></div>23<divid="map-container"></div>24<divid="iframe-container"></div>25</body>26</html>
XML parser
Purpose
The XML parser allows the user to parse XML data that contains popcorn data in order to populate a popcorn instance.
The user specifies the source of their XML file in a data-timeline-sources attribute on the video object. When Popcorn is instantiated it will search each video element for a data-timeline-sources attribute and try and parse the specified file.
Options
data-timeline-sources [String] - a media element attribute that specifies the source of the file to be parsed
Use Case
Parse a XML file of popcorn data
Example
Parses a popcorn XML file ( this example is assuming your XML file is called data.xml ) and that you are using data-timeline-sources
1<html> 2<head> 3<script src="popcorn-complete.js"></script> 4</head> 5<body> 6<videoid="video"data-timeline-sources="data/data.xml" 7controls 8width='250px' 9poster="../../test/poster.png">1011<sourceid='mp4'12src="../../test/trailer.mp4"13type='video/mp4; codecs="avc1, mp4a"'>1415<sourceid='ogv'16src="../../test/trailer.ogv"17type='video/ogg; codecs="theora, vorbis"'>1819<p>Your user agent does not support the HTML5 Video element.</p>2021</video>22<divid="footnote-container"></div>23<divid="map-container"></div>24<divid="iframe-container"></div>25</body>26</html>