e95cfe5a by David LaPalomento

Fix whitespace

All files should use 2-space indenting.
1 parent eda08662
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>video.js HLS Plugin Example</title>
<meta charset="utf-8">
<title>video.js HLS Plugin Example</title>
<link href="node_modules/video.js/video-js.css" rel="stylesheet">
......@@ -52,7 +52,7 @@
videojs.options.flash.swf = 'node_modules/videojs-media-sources/video-js-with-mse.swf';
video = videojs('video',{},function(){
this.playbackController = new window.videojs.hls.HLSPlaybackController(this);
this.playbackController.loadManifest("http://localhost:7070/test/basic-playback/zencoder/gogo/manifest.m3u8",function(data){console.log(data)});
this.playbackController.loadManifest('http://localhost:7070/test/basic-playback/zencoder/gogo/manifest.m3u8',function(data){console.log(data)});
});
</script>
......
(function (window) {
window.videojs.hls.HLSPlaybackController = function (vjsPlayerReference) {
var ManifestController = window.videojs.hls.ManifestController;
var SegmentController = window.videojs.hls.SegmentController;
var MediaSource = window.videojs.MediaSource;
var SegmentParser = window.videojs.hls.SegmentParser;
var M3U8 = window.videojs.hls.M3U8;
window.videojs.hls.HLSPlaybackController = function (vjsPlayerReference) {
var ManifestController = window.videojs.hls.ManifestController;
var SegmentController = window.videojs.hls.SegmentController;
var MediaSource = window.videojs.MediaSource;
var SegmentParser = window.videojs.hls.SegmentParser;
var M3U8 = window.videojs.hls.M3U8;
var self = this;
var self = this;
self.player = vjsPlayerReference;
self.mediaSource = new MediaSource();
self.parser = new SegmentParser();
self.manifestController = null;
self.segmentController = null;
self.manifestLoaded = false;
self.currentSegment = 0;
self.currentManifest = null;
self.currentPlaylist = null;
self.currentRendition = null;
self.player = vjsPlayerReference;
self.mediaSource = new MediaSource();
self.parser = new SegmentParser();
self.manifestController = null;
self.segmentController = null;
self.manifestLoaded = false;
self.currentSegment = 0;
self.currentManifest = null;
self.currentPlaylist = null;
self.currentRendition = null;
// Register Externall Callbacks
self.manifestLoadCompleteCallback;
// Register Externall Callbacks
self.manifestLoadCompleteCallback;
self.player.on('timeupdate', function () {
console.log(self.player.currentTime());
});
self.player.on('timeupdate', function () {
console.log(self.player.currentTime());
});
self.player.on('onsrcchange', function () {
console.log('src change', self.player.currentSrc());
//if src.url.m3u8 -- loadManifest.url
});
self.player.on('onsrcchange', function () {
console.log('src change', self.player.currentSrc());
//if src.url.m3u8 -- loadManifest.url
});
self.rendition = function (rendition) {
self.currentRendition = rendition;
self.loadManifest(self.currentRendition.url, self.onM3U8LoadComplete, self.onM3U8LoadError, self.onM3U8Update);
};
self.rendition = function (rendition) {
self.currentRendition = rendition;
self.loadManifest(self.currentRendition.url, self.onM3U8LoadComplete, self.onM3U8LoadError, self.onM3U8Update);
};
self.loadManifest = function (manifestUrl, onDataCallback, onErrorCallback, onUpdateCallback) {
self.mediaSource.addEventListener('sourceopen', function (event) {
console.log('source open here');
// feed parsed bytes into the player
self.sourceBuffer = self.mediaSource.addSourceBuffer('video/flv; codecs="vp6,aac"');
self.loadManifest = function (manifestUrl, onDataCallback, onErrorCallback, onUpdateCallback) {
self.mediaSource.addEventListener('sourceopen', function (event) {
console.log('source open here');
// feed parsed bytes into the player
self.sourceBuffer = self.mediaSource.addSourceBuffer('video/flv; codecs="vp6,aac"');
self.parser = new SegmentParser();
self.parser = new SegmentParser();
self.sourceBuffer.appendBuffer(self.parser.getFlvHeader(), video);
self.sourceBuffer.appendBuffer(self.parser.getFlvHeader(), video);
if( onDataCallback )
{
self.manifestLoadCompleteCallback = onDataCallback;
}
if( onDataCallback )
{
self.manifestLoadCompleteCallback = onDataCallback;
}
self.manifestController = new ManifestController();
self.manifestController.loadManifest(manifestUrl, self.onM3U8LoadComplete, self.onM3U8LoadError, self.onM3U8Update);
self.manifestController = new ManifestController();
self.manifestController.loadManifest(manifestUrl, self.onM3U8LoadComplete, self.onM3U8LoadError, self.onM3U8Update);
}, false);
}, false);
self.player.src({
src: videojs.URL.createObjectURL(self.mediaSource),
type: "video/flv"
});
};
self.player.src({
src: videojs.URL.createObjectURL(self.mediaSource),
type: "video/flv"
});
};
self.onM3U8LoadComplete = function (m3u8) {
if (m3u8.invalidReasons.length == 0) {
if(m3u8.isPlaylist)
{
self.currentPlaylist = m3u8;
self.rendition(self.currentPlaylist.playlistItems[0]);
} else {
self.currentManifest = m3u8;
self.manifestLoaded = true;
self.onM3U8LoadComplete = function (m3u8) {
if (m3u8.invalidReasons.length == 0) {
if(m3u8.isPlaylist)
{
self.currentPlaylist = m3u8;
self.rendition(self.currentPlaylist.playlistItems[0]);
} else {
self.currentManifest = m3u8;
self.manifestLoaded = true;
self.loadSegment(self.currentManifest.mediaItems[0]);
self.loadSegment(self.currentManifest.mediaItems[0]);
if(self.manifestLoadCompleteCallback)
{
self.manifestLoadCompleteCallback(m3u8);
}
}
}
};
if(self.manifestLoadCompleteCallback)
{
self.manifestLoadCompleteCallback(m3u8);
}
}
}
};
self.onM3U8LoadError = function (error) {
self.onM3U8LoadError = function (error) {
};
};
self.onM3U8Update = function (m3u8) {
self.onM3U8Update = function (m3u8) {
};
};
self.loadSegment = function(segment) {
self.segmentController = new SegmentController();
self.segmentController.loadSegment(segment.url, self.onSegmentLoadComplete, self.onSegmentLoadError);
self.loadSegment = function(segment) {
self.segmentController = new SegmentController();
self.segmentController.loadSegment(segment.url, self.onSegmentLoadComplete, self.onSegmentLoadError);
};
};
self.onSegmentLoadComplete = function (segment) {
self.parser.parseSegmentBinaryData(segment.binaryData);
self.onSegmentLoadComplete = function (segment) {
self.parser.parseSegmentBinaryData(segment.binaryData);
while (self.parser.tagsAvailable()) {
self.sourceBuffer.appendBuffer(self.parser.getNextTag().bytes, self.player);
};
while (self.parser.tagsAvailable()) {
self.sourceBuffer.appendBuffer(self.parser.getNextTag().bytes, self.player);
};
console.log('load another',self.currentSegment,self.currentManifest.mediaItems.length);
console.log('load another',self.currentSegment,self.currentManifest.mediaItems.length);
if(self.currentSegment < self.currentManifest.mediaItems.length-1)
{
console.log('load another');
self.loadNextSegment();
}
};
if(self.currentSegment < self.currentManifest.mediaItems.length-1)
{
console.log('load another');
self.loadNextSegment();
}
};
self.loadNextSegment = function () {
self.currentSegment++;
self.loadSegment(self.currentManifest.mediaItems[self.currentSegment]);
}
self.loadNextSegment = function () {
self.currentSegment++;
self.loadSegment(self.currentManifest.mediaItems[self.currentSegment]);
}
self.onSegmentLoadError = function (error) {
self.onSegmentLoadError = function (error) {
};
};
};
})(this);
\ No newline at end of file
};
})(this);
......
(function(window) {
var M3U8 = window.videojs.hls.M3U8;
var M3U8 = window.videojs.hls.M3U8;
window.videojs.hls.M3U8Parser = function() {
var self = this;
self.directory;
var tagTypes = window.videojs.hls.m3u8TagType;
var lines = [];
var data;
self.getTagType = function( lineData ) {
for ( var s in tagTypes )
{
if (lineData.indexOf(tagTypes[s]) == 0)
{
return tagTypes[s];
}
}
}
self.getTagValue = function ( lineData ) {
for ( var s in tagTypes )
{
if (lineData.indexOf(tagTypes[s]) == 0)
{
return lineData.substr(tagTypes[s].length);
}
}
}
self.parse = function( rawDataString ) {
data = new M3U8();
if(self.directory)
{
data.directory = self.directory;
}
if( rawDataString != undefined && rawDataString.toString().length > 0 )
{
lines = rawDataString.split('\n');
lines.forEach(
function(value,index) {
switch( self.getTagType(value) )
{
case tagTypes.EXTM3U:
data.hasValidM3UTag = (index == 0);
if(!data.hasValidM3UTag)
{
data.invalidReasons.push("Invalid EXTM3U Tag");
}
break;
case tagTypes.DISCONTINUITY:
break;
case tagTypes.PLAYLIST_TYPE:
if(self.getTagValue(value) == "VOD" || self.getTagValue(value) == "EVENT")
{
data.playlistType = self.getTagValue(value);
data.isPlaylist = true;
} else {
data.invalidReasons.push("Invalid Playlist Type Value");
}
break;
case tagTypes.EXTINF:
var segment = {url: "unknown", byterange: -1, targetDuration: data.targetDuration };
if( self.getTagType(lines[index+1]) == tagTypes.BYTERANGE )
{
segment.byterange = self.getTagValue(lines[index+1]).split('@');
segment.url = lines[index+2];
} else
{
segment.url = lines[index+1];
}
if(segment.url.indexOf("http")===-1 && self.directory)
{
if(data.directory[data.directory.length-1] === segment.url[0] && segment.url[0] === "/")
{
segment.url = segment.url.substr(1);
}
segment.url = self.directory + segment.url;
}
data.mediaItems.push(segment);
break;
case tagTypes.STREAM_INF:
var rendition = {};
var attributes = value.substr(tagTypes.STREAM_INF.length).split(',');
window.videojs.hls.M3U8Parser = function() {
attributes.forEach(function(attr_value,attr_index) {
if(isNaN(attr_value.split('=')[1])){
rendition[attr_value.split('=')[0].toLowerCase()] = attr_value.split('=')[1];
var self = this;
self.directory;
if(rendition[attr_value.split('=')[0].toLowerCase()].split('x').length = 2)
{
rendition.resolution = {
width: Number(rendition[attr_value.split('=')[0].toLowerCase()].split('x')[0]),
height: Number(rendition[attr_value.split('=')[0].toLowerCase()].split('x')[1])
}
}
var tagTypes = window.videojs.hls.m3u8TagType;
var lines = [];
var data;
} else {
rendition[attr_value.split('=')[0].toLowerCase()] = Number(attr_value.split('=')[1]);
}
});
self.getTagType = function( lineData ) {
for ( var s in tagTypes )
{
if (lineData.indexOf(tagTypes[s]) == 0)
{
return tagTypes[s];
}
}
if( self.getTagType(lines[index+1]) == tagTypes.BYTERANGE )
{
rendition.byterange = self.getTagValue(lines[index+1]).split('@');
rendition.url = lines[index+2];
} else
{
rendition.url = lines[index+1];
}
self.getTagValue = function ( lineData ) {
for ( var s in tagTypes )
{
if (lineData.indexOf(tagTypes[s]) == 0)
{
return lineData.substr(tagTypes[s].length);
}
}
data.isPlaylist = true;
data.playlistItems.push(rendition);
break;
case tagTypes.TARGETDURATION:
data.targetDuration = Number(self.getTagValue(value).split(',')[0]);
break;
case tagTypes.ZEN_TOTAL_DURATION:
data.totalDuration = Number(self.getTagValue(value));
break;
case tagTypes.VERSION:
data.version = Number(self.getTagValue(value));
break;
case tagTypes.MEDIA_SEQUENCE:
data.mediaSequence = parseInt(self.getTagValue(value));
break;
case tagTypes.ALLOW_CACHE:
if(self.getTagValue(value) == "YES" || self.getTagValue(value) == "NO")
{
data.allowCache = self.getTagValue(value);
} else {
data.invalidReasons.push("Invalid ALLOW_CACHE Value");
}
break;
case tagTypes.ENDLIST:
data.hasEndTag = true;
break;
}
}
)
} else {
data.invalidReasons.push("Empty Manifest");
}
return data;
self.parse = function( rawDataString ) {
data = new M3U8();
if(self.directory)
{
data.directory = self.directory;
}
if( rawDataString != undefined && rawDataString.toString().length > 0 )
{
lines = rawDataString.split('\n');
lines.forEach(
function(value,index) {
switch( self.getTagType(value) )
{
case tagTypes.EXTM3U:
data.hasValidM3UTag = (index == 0);
if(!data.hasValidM3UTag)
{
data.invalidReasons.push("Invalid EXTM3U Tag");
}
break;
case tagTypes.DISCONTINUITY:
break;
case tagTypes.PLAYLIST_TYPE:
if(self.getTagValue(value) == "VOD" || self.getTagValue(value) == "EVENT")
{
data.playlistType = self.getTagValue(value);
data.isPlaylist = true;
} else {
data.invalidReasons.push("Invalid Playlist Type Value");
}
break;
case tagTypes.EXTINF:
var segment = {url: "unknown", byterange: -1, targetDuration: data.targetDuration };
if( self.getTagType(lines[index+1]) == tagTypes.BYTERANGE )
{
segment.byterange = self.getTagValue(lines[index+1]).split('@');
segment.url = lines[index+2];
} else
{
segment.url = lines[index+1];
}
if(segment.url.indexOf("http")===-1 && self.directory)
{
if(data.directory[data.directory.length-1] === segment.url[0] && segment.url[0] === "/")
{
segment.url = segment.url.substr(1);
}
segment.url = self.directory + segment.url;
}
data.mediaItems.push(segment);
break;
case tagTypes.STREAM_INF:
var rendition = {};
var attributes = value.substr(tagTypes.STREAM_INF.length).split(',');
attributes.forEach(function(attr_value,attr_index) {
if(isNaN(attr_value.split('=')[1])){
rendition[attr_value.split('=')[0].toLowerCase()] = attr_value.split('=')[1];
if(rendition[attr_value.split('=')[0].toLowerCase()].split('x').length = 2)
{
rendition.resolution = {
width: Number(rendition[attr_value.split('=')[0].toLowerCase()].split('x')[0]),
height: Number(rendition[attr_value.split('=')[0].toLowerCase()].split('x')[1])
}
}
} else {
rendition[attr_value.split('=')[0].toLowerCase()] = Number(attr_value.split('=')[1]);
}
});
if( self.getTagType(lines[index+1]) == tagTypes.BYTERANGE )
{
rendition.byterange = self.getTagValue(lines[index+1]).split('@');
rendition.url = lines[index+2];
} else
{
rendition.url = lines[index+1];
}
data.isPlaylist = true;
data.playlistItems.push(rendition);
break;
case tagTypes.TARGETDURATION:
data.targetDuration = Number(self.getTagValue(value).split(',')[0]);
break;
case tagTypes.ZEN_TOTAL_DURATION:
data.totalDuration = Number(self.getTagValue(value));
break;
case tagTypes.VERSION:
data.version = Number(self.getTagValue(value));
break;
case tagTypes.MEDIA_SEQUENCE:
data.mediaSequence = parseInt(self.getTagValue(value));
break;
case tagTypes.ALLOW_CACHE:
if(self.getTagValue(value) == "YES" || self.getTagValue(value) == "NO")
{
data.allowCache = self.getTagValue(value);
} else {
data.invalidReasons.push("Invalid ALLOW_CACHE Value");
}
break;
case tagTypes.ENDLIST:
data.hasEndTag = true;
break;
}
}
)
} else {
data.invalidReasons.push("Empty Manifest");
}
return data;
};
};
};
})(this);
\ No newline at end of file
})(this);
......
window.videojs.hls.m3u8TagType = {
/*
* Derived from V8: http://tools.ietf.org/html/draft-pantos-http-live-streaming-08
*/
/**
* Identifies manifest as Extended M3U - must be present on first line!
*/
EXTM3U:"#EXTM3U",
/**
* Specifies duration.
* Syntax: #EXTINF:<duration>,<title>
* Example: #EXTINF:10,
*/
EXTINF:"#EXTINF:",
/**
* Indicates that a media segment is a sub-range of the resource identified by its media URI.
* Syntax: #EXT-X-BYTERANGE:<n>[@o]
*/
BYTERANGE:"#EXT-X-BYTERANGE:",
/**
* Specifies the maximum media segment duration - applies to entire manifest.
* Syntax: #EXT-X-TARGETDURATION:<s>
* Example: #EXT-X-TARGETDURATION:10
*/
TARGETDURATION:"#EXT-X-TARGETDURATION:",
/**
* Specifies the sequence number of the first URI in a manifest.
* Syntax: #EXT-X-MEDIA-SEQUENCE:<i>
* Example: #EXT-X-MEDIA-SEQUENCE:50
*/
MEDIA_SEQUENCE:"#EXT-X-MEDIA-SEQUENCE:",
/**
* Specifies a method by which media segments can be decrypted, if encryption is present.
* Syntax: #EXT-X-KEY:<attribute-list>
* Note: This is likely irrelevant in the context of the Flash Player.
*/
KEY:"#EXT-X-KEY:",
/**
* Associates the first sample of a media segment with an absolute date and/or time. Applies only to the next media URI.
* Syntax: #EXT-X-PROGRAM-DATE-TIME:<YYYY-MM-DDThh:mm:ssZ>
* Example: #EXT-X-PROGRAM-DATE-TIME:2010-02-19T14:54:23.031+08:00
*/
PROGRAM_DATE_TIME:"#EXT-X-PROGRAM-DATE-TIME:",
/**
* Indicates whether the client MAY or MUST NOT cache downloaded media segments for later replay.
* Syntax: #EXT-X-ALLOW-CACHE:<YES|NO>
* Note: This is likely irrelevant in the context of the Flash Player.
*/
ALLOW_CACHE:"#EXT-X-ALLOW_CACHE:",
/**
* Provides mutability information about the manifest.
* Syntax: #EXT-X-PLAYLIST-TYPE:<EVENT|VOD>
*/
PLAYLIST_TYPE:"#EXT-X-PLAYLIST-TYPE:",
/**
* Indicates that no more media segments will be added to the manifest. May occur ONCE, anywhere in the mainfest file.
*/
ENDLIST:"#EXT-X-ENDLIST",
/**
* Used to relate Playlists that contain alternative renditions of the same content.
* Syntax: #EXT-X-MEDIA:<attribute-list>
*/
MEDIA:"#EXT-X-MEDIA:",
/**
* Identifies a media URI as a Playlist file containing a multimedia presentation and provides information about that presentation.
* Syntax: #EXT-X-STREAM-INF:<attribute-list>
* <URI>
*/
STREAM_INF:"#EXT-X-STREAM-INF:",
/**
* Indicates an encoding discontinuity between the media segment that follows it and the one that preceded it.
*/
DISCONTINUITY:"#EXT-X-DISCONTINUITY",
/**
* Indicates that each media segment in the manifest describes a single I-frame.
*/
I_FRAMES_ONLY:"#EXT-X-I-FRAMES-ONLY",
/**
* Identifies a manifest file containing the I-frames of a multimedia presentation. It stands alone, in that it does not apply to a particular URI in the manifest.
* Syntax: #EXT-X-I-FRAME-STREAM-INF:<attribute-list>
*/
I_FRAME_STREAM_INF:"#EXT-X-I-FRAME-STREAM-INF:",
/**
* Indicates the compatibility version of the Playlist file.
* Syntax: #EXT-X-VERSION:<n>
*/
VERSION:"#EXT-X-VERSION:",
/**
* Indicates the total duration as reported by Zencoder.
* Syntax: #ZEN-TOTAL-DURATION:<n>
*/
ZEN_TOTAL_DURATION: "#ZEN-TOTAL-DURATION:"
};
\ No newline at end of file
(function(window) {
window.videojs.hls.m3u8TagType = {
/*
* Derived from V8: http://tools.ietf.org/html/draft-pantos-http-live-streaming-08
*/
/**
* Identifies manifest as Extended M3U - must be present on first line!
*/
EXTM3U:"#EXTM3U",
/**
* Specifies duration.
* Syntax: #EXTINF:<duration>,<title>
* Example: #EXTINF:10,
*/
EXTINF:"#EXTINF:",
/**
* Indicates that a media segment is a sub-range of the resource identified by its media URI.
* Syntax: #EXT-X-BYTERANGE:<n>[@o]
*/
BYTERANGE:"#EXT-X-BYTERANGE:",
/**
* Specifies the maximum media segment duration - applies to entire manifest.
* Syntax: #EXT-X-TARGETDURATION:<s>
* Example: #EXT-X-TARGETDURATION:10
*/
TARGETDURATION:"#EXT-X-TARGETDURATION:",
/**
* Specifies the sequence number of the first URI in a manifest.
* Syntax: #EXT-X-MEDIA-SEQUENCE:<i>
* Example: #EXT-X-MEDIA-SEQUENCE:50
*/
MEDIA_SEQUENCE:"#EXT-X-MEDIA-SEQUENCE:",
/**
* Specifies a method by which media segments can be decrypted, if encryption is present.
* Syntax: #EXT-X-KEY:<attribute-list>
* Note: This is likely irrelevant in the context of the Flash Player.
*/
KEY:"#EXT-X-KEY:",
/**
* Associates the first sample of a media segment with an absolute date and/or time. Applies only to the next media URI.
* Syntax: #EXT-X-PROGRAM-DATE-TIME:<YYYY-MM-DDThh:mm:ssZ>
* Example: #EXT-X-PROGRAM-DATE-TIME:2010-02-19T14:54:23.031+08:00
*/
PROGRAM_DATE_TIME:"#EXT-X-PROGRAM-DATE-TIME:",
/**
* Indicates whether the client MAY or MUST NOT cache downloaded media segments for later replay.
* Syntax: #EXT-X-ALLOW-CACHE:<YES|NO>
* Note: This is likely irrelevant in the context of the Flash Player.
*/
ALLOW_CACHE:"#EXT-X-ALLOW_CACHE:",
/**
* Provides mutability information about the manifest.
* Syntax: #EXT-X-PLAYLIST-TYPE:<EVENT|VOD>
*/
PLAYLIST_TYPE:"#EXT-X-PLAYLIST-TYPE:",
/**
* Indicates that no more media segments will be added to the manifest. May occur ONCE, anywhere in the mainfest file.
*/
ENDLIST:"#EXT-X-ENDLIST",
/**
* Used to relate Playlists that contain alternative renditions of the same content.
* Syntax: #EXT-X-MEDIA:<attribute-list>
*/
MEDIA:"#EXT-X-MEDIA:",
/**
* Identifies a media URI as a Playlist file containing a multimedia presentation and provides information about that presentation.
* Syntax: #EXT-X-STREAM-INF:<attribute-list>
* <URI>
*/
STREAM_INF:"#EXT-X-STREAM-INF:",
/**
* Indicates an encoding discontinuity between the media segment that follows it and the one that preceded it.
*/
DISCONTINUITY:"#EXT-X-DISCONTINUITY",
/**
* Indicates that each media segment in the manifest describes a single I-frame.
*/
I_FRAMES_ONLY:"#EXT-X-I-FRAMES-ONLY",
/**
* Identifies a manifest file containing the I-frames of a multimedia presentation. It stands alone, in that it does not apply to a particular URI in the manifest.
* Syntax: #EXT-X-I-FRAME-STREAM-INF:<attribute-list>
*/
I_FRAME_STREAM_INF:"#EXT-X-I-FRAME-STREAM-INF:",
/**
* Indicates the compatibility version of the Playlist file.
* Syntax: #EXT-X-VERSION:<n>
*/
VERSION:"#EXT-X-VERSION:",
/**
* Indicates the total duration as reported by Zencoder.
* Syntax: #ZEN-TOTAL-DURATION:<n>
*/
ZEN_TOTAL_DURATION: "#ZEN-TOTAL-DURATION:"
};
})(this);
......
(function(window) {
window.videojs.hls.M3U8 = function() {
this.directory = "";
this.allowCache = "NO";
this.playlistItems = [];
this.mediaItems = [];
this.iFrameItems = [];
this.invalidReasons = [];
this.hasValidM3UTag = false;
this.hasEndTag = false;
this.targetDuration = -1;
this.totalDuration = -1;
this.isPlaylist = false;
this.playlistType = "";
this.mediaSequence = -1;
this.version = -1;
}
})(this);
\ No newline at end of file
window.videojs.hls.M3U8 = function() {
this.directory = "";
this.allowCache = "NO";
this.playlistItems = [];
this.mediaItems = [];
this.iFrameItems = [];
this.invalidReasons = [];
this.hasValidM3UTag = false;
this.hasEndTag = false;
this.targetDuration = -1;
this.totalDuration = -1;
this.isPlaylist = false;
this.playlistType = "";
this.mediaSequence = -1;
this.version = -1;
}
})(this);
......
(function (window) {
var M3U8 = window.videojs.hls.M3U8;
var M3U8Parser = window.videojs.hls.M3U8Parser;
window.videojs.hls.ManifestController = function () {
var self = this;
self.parser;
self.data;
self.url;
self.onDataCallback;
self.onErrorCallback;
self.onUpdateCallback;
self.loadManifest = function (manifestUrl, onDataCallback, onErrorCallback, onUpdateCallback) {
self.url = manifestUrl;
if (onDataCallback) {
self.onDataCallback = onDataCallback;
}
if (onErrorCallback) {
self.onErrorCallback = onErrorCallback;
}
if (onUpdateCallback) {
self.onUpdateCallback = onUpdateCallback;
}
vjs.get(manifestUrl, self.onManifestLoadComplete, self.onManifestLoadError);
};
self.parseManifest = function (dataAsString) {
self.parser = new M3U8Parser();
self.parser.directory = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/.exec(self.url).slice(1)[1];
self.data = self.parser.parse(dataAsString);
return self.data;
};
self.onManifestLoadComplete = function (response) {
var output = self.parseManifest(response);
if (self.onDataCallback != undefined) {
self.onDataCallback(output);
}
};
self.onManifestLoadError = function (err) {
if (self.onErrorCallback != undefined) {
self.onErrorCallback((err != undefined) ? err : null);
}
};
}
var M3U8 = window.videojs.hls.M3U8;
var M3U8Parser = window.videojs.hls.M3U8Parser;
window.videojs.hls.ManifestController = function () {
var self = this;
self.parser;
self.data;
self.url;
self.onDataCallback;
self.onErrorCallback;
self.onUpdateCallback;
self.loadManifest = function (manifestUrl, onDataCallback, onErrorCallback, onUpdateCallback) {
self.url = manifestUrl;
if (onDataCallback) {
self.onDataCallback = onDataCallback;
}
if (onErrorCallback) {
self.onErrorCallback = onErrorCallback;
}
if (onUpdateCallback) {
self.onUpdateCallback = onUpdateCallback;
}
vjs.get(manifestUrl, self.onManifestLoadComplete, self.onManifestLoadError);
};
self.parseManifest = function (dataAsString) {
self.parser = new M3U8Parser();
self.parser.directory = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/.exec(self.url).slice(1)[1];
self.data = self.parser.parse(dataAsString);
return self.data;
};
self.onManifestLoadComplete = function (response) {
var output = self.parseManifest(response);
if (self.onDataCallback != undefined) {
self.onDataCallback(output);
}
};
self.onManifestLoadError = function (err) {
if (self.onErrorCallback != undefined) {
self.onErrorCallback((err != undefined) ? err : null);
}
};
}
})(this);
......
(function(window) {
window.videojs.hls.SegmentController = function(){
var self = this;
self.url;
self.requestTimestamp;
self.responseTimestamp;
self.data;
self.onDataCallback;
self.onErrorCallback;
self.onUpdateCallback;
self.loadSegment = function ( segmentUrl, onDataCallback, onErrorCallback, onUpdateCallback ) {
self.url = segmentUrl;
self.onDataCallback = onDataCallback;
self.onErrorCallback = onErrorCallback;
self.onUpdateCallback = onUpdateCallback;
self.requestTimestamp = new Date().getTime();
var req = new XMLHttpRequest();
req.open('GET', segmentUrl, true);
req.responseType = 'arraybuffer';
req.onload = function(response) {
self.onSegmentLoadComplete(new Uint8Array(req.response));
};
req.send(null);
//vjs.get(segmentUrl, self.onSegmentLoadComplete, self.onSegmentLoadError);
};
self.parseSegment = function ( incomingData ) {
// Add David's code later //
console.log('got segment data', incomingData.byteLength);
self.data = {};
self.data.binaryData = incomingData;
self.data.url = self.url;
self.data.isCached = false;
self.data.requestTimestamp = self.requestTimestamp;
self.data.responseTimestamp = self.responseTimestamp;
self.data.byteLength = incomingData.byteLength;
self.data.isCached = ( parseInt(self.responseTimestamp - self.requestTimestamp) < 75 );
self.data.throughput = self.calculateThroughput(self.data.byteLength, self.requestTimestamp ,self.responseTimestamp);
return self.data;
};
self.calculateThroughput = function(dataAmount, startTime, endTime) {
return Math.round(dataAmount/(endTime-startTime)*1000)*8;
}
self.onSegmentLoadComplete = function(response) {
self.responseTimestamp = new Date().getTime();
var output = self.parseSegment(response);
if(self.onDataCallback != undefined)
{
self.onDataCallback(output);
}
};
self.onSegmentLoadError = function(err) {
if(err)
{
console.log(err.message);
}
if(self.onErrorCallback != undefined)
{
onErrorCallback((err != undefined) ? err : null);
}
};
}
window.videojs.hls.SegmentController = function(){
var self = this;
self.url;
self.requestTimestamp;
self.responseTimestamp;
self.data;
self.onDataCallback;
self.onErrorCallback;
self.onUpdateCallback;
self.loadSegment = function ( segmentUrl, onDataCallback, onErrorCallback, onUpdateCallback ) {
self.url = segmentUrl;
self.onDataCallback = onDataCallback;
self.onErrorCallback = onErrorCallback;
self.onUpdateCallback = onUpdateCallback;
self.requestTimestamp = new Date().getTime();
var req = new XMLHttpRequest();
req.open('GET', segmentUrl, true);
req.responseType = 'arraybuffer';
req.onload = function(response) {
self.onSegmentLoadComplete(new Uint8Array(req.response));
};
req.send(null);
//vjs.get(segmentUrl, self.onSegmentLoadComplete, self.onSegmentLoadError);
};
self.parseSegment = function ( incomingData ) {
// Add David's code later //
console.log('got segment data', incomingData.byteLength);
self.data = {};
self.data.binaryData = incomingData;
self.data.url = self.url;
self.data.isCached = false;
self.data.requestTimestamp = self.requestTimestamp;
self.data.responseTimestamp = self.responseTimestamp;
self.data.byteLength = incomingData.byteLength;
self.data.isCached = ( parseInt(self.responseTimestamp - self.requestTimestamp) < 75 );
self.data.throughput = self.calculateThroughput(self.data.byteLength, self.requestTimestamp ,self.responseTimestamp);
return self.data;
};
self.calculateThroughput = function(dataAmount, startTime, endTime) {
return Math.round(dataAmount/(endTime-startTime)*1000)*8;
}
self.onSegmentLoadComplete = function(response) {
self.responseTimestamp = new Date().getTime();
var output = self.parseSegment(response);
if(self.onDataCallback != undefined)
{
self.onDataCallback(output);
}
};
self.onSegmentLoadError = function(err) {
if(err)
{
console.log(err.message);
}
if(self.onErrorCallback != undefined)
{
onErrorCallback((err != undefined) ? err : null);
}
};
}
})(this);
......
window.playlistData = '#EXTM3U\n'+
'#EXT-X-TARGETDURATION:10\n' +
'#EXT-X-VERSION:4\n' +
'#EXT-X-MEDIA-SEQUENCE:0\n' +
'#EXT-X-PLAYLIST-TYPE:VOD\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:522828@0\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:587500@522828\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:713084@1110328\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:476580@1823412\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:535612@2299992\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:207176@2835604\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:455900@3042780\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:657248@3498680\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:571708@4155928\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:485040@4727636\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:709136@5212676\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:730004@5921812\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:456276@6651816\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:468684@7108092\n' +
'hls_450k_video.ts' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:444996@7576776\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:331444@8021772\n' +
'hls_450k_video.ts\n' +
'#EXTINF:1.4167,\n' +
'#EXT-X-BYTERANGE:44556@8353216\n' +
'hls_450k_video.ts\n' +
'#EXT-X-ENDLIST';
\ No newline at end of file
'#EXT-X-TARGETDURATION:10\n' +
'#EXT-X-VERSION:4\n' +
'#EXT-X-MEDIA-SEQUENCE:0\n' +
'#EXT-X-PLAYLIST-TYPE:VOD\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:522828@0\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:587500@522828\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:713084@1110328\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:476580@1823412\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:535612@2299992\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:207176@2835604\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:455900@3042780\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:657248@3498680\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:571708@4155928\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:485040@4727636\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:709136@5212676\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:730004@5921812\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:456276@6651816\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:468684@7108092\n' +
'hls_450k_video.ts' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:444996@7576776\n' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:331444@8021772\n' +
'hls_450k_video.ts\n' +
'#EXTINF:1.4167,\n' +
'#EXT-X-BYTERANGE:44556@8353216\n' +
'hls_450k_video.ts\n' +
'#EXT-X-ENDLIST';
......