Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
videojs-contrib-hls
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
dd4862c9
authored
2013-10-24 19:28:40 -0400
by
Tom Johnson
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
toms intro to jshint
1 parent
0b06638f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
38 deletions
src/hls-playback-controller.js
src/m3u8/m3u8-parser.js
src/m3u8/m3u8.js
src/manifest-controller.js
src/segment-controller.js
test/video-js-hls_test.js
src/hls-playback-controller.js
View file @
dd4862c
...
...
@@ -3,8 +3,8 @@
ManifestController
=
window
.
videojs
.
hls
.
ManifestController
,
SegmentController
=
window
.
videojs
.
hls
.
SegmentController
,
MediaSource
=
window
.
videojs
.
MediaSource
,
SegmentParser
=
window
.
videojs
.
hls
.
SegmentParser
,
M3U8
=
window
.
videojs
.
hls
.
M3U8
;
SegmentParser
=
window
.
videojs
.
hls
.
SegmentParser
;
window
.
videojs
.
hls
.
HLSPlaybackController
=
function
(
player
)
{
...
...
@@ -23,14 +23,14 @@
self
.
loadManifest
(
self
.
currentRendition
.
url
,
self
.
onM3U8LoadComplete
,
self
.
onM3U8LoadError
,
self
.
onM3U8Update
);
};
self
.
loadManifest
=
function
(
manifestUrl
,
onDataCallback
,
onErrorCallback
,
onUpdateCallback
)
{
self
.
mediaSource
.
addEventListener
(
'sourceopen'
,
function
(
event
)
{
self
.
loadManifest
=
function
(
manifestUrl
,
onDataCallback
)
{
self
.
mediaSource
.
addEventListener
(
'sourceopen'
,
function
()
{
// feed parsed bytes into the player
self
.
sourceBuffer
=
self
.
mediaSource
.
addSourceBuffer
(
'video/flv; codecs="vp6,aac"'
);
self
.
parser
=
new
SegmentParser
();
self
.
sourceBuffer
.
appendBuffer
(
self
.
parser
.
getFlvHeader
(),
video
);
self
.
sourceBuffer
.
appendBuffer
(
self
.
parser
.
getFlvHeader
(),
self
.
player
);
if
(
onDataCallback
)
{
self
.
manifestLoadCompleteCallback
=
onDataCallback
;
...
...
@@ -42,7 +42,7 @@
},
false
);
self
.
player
.
src
({
src
:
videojs
.
URL
.
createObjectURL
(
self
.
mediaSource
),
src
:
window
.
videojs
.
URL
.
createObjectURL
(
self
.
mediaSource
),
type
:
"video/flv"
});
};
...
...
@@ -65,8 +65,18 @@
}
};
self
.
onM3U8LoadError
=
function
(
error
)
{};
self
.
onM3U8Update
=
function
(
m3u8
)
{};
self
.
onM3U8LoadError
=
function
(
error
)
{
if
(
error
)
{
console
.
log
(
error
);
}
};
self
.
onM3U8Update
=
function
(
m3u8
)
{
if
(
m3u8
)
{
console
.
log
(
m3u8
);
}
};
self
.
loadSegment
=
function
(
segment
)
{
self
.
segmentController
=
new
SegmentController
();
...
...
@@ -88,9 +98,14 @@
self
.
loadNextSegment
=
function
()
{
self
.
currentSegment
++
;
self
.
loadSegment
(
self
.
currentManifest
.
mediaItems
[
self
.
currentSegment
]);
}
}
;
self
.
onSegmentLoadError
=
function
(
error
)
{};
self
.
onSegmentLoadError
=
function
(
error
)
{
if
(
error
)
{
console
.
log
(
error
);
}
};
};
})(
this
);
...
...
src/m3u8/m3u8-parser.js
View file @
dd4862c
...
...
@@ -38,11 +38,11 @@
lines
=
rawDataString
.
split
(
'\n'
);
lines
.
forEach
(
function
(
value
,
index
)
{
var
segment
,
rendition
,
attribute
;
var
segment
,
rendition
,
attribute
s
;
switch
(
self
.
getTagType
(
value
))
{
case
tagTypes
.
EXTM3U
:
data
.
hasValidM3UTag
=
(
index
==
0
);
data
.
hasValidM3UTag
=
(
index
==
=
0
);
if
(
!
data
.
hasValidM3UTag
)
{
data
.
invalidReasons
.
push
(
"Invalid EXTM3U Tag"
);
}
...
...
@@ -95,12 +95,12 @@
if
(
rendition
[
attrValue
.
split
(
'='
)[
0
].
toLowerCase
()].
split
(
'x'
).
length
===
2
)
{
rendition
.
resolution
=
{
width
:
parseInt
(
rendition
[
attrValue
.
split
(
'='
)[
0
].
toLowerCase
()].
split
(
'x'
)[
0
]),
height
:
parseInt
(
rendition
[
attrValue
.
split
(
'='
)[
0
].
toLowerCase
()].
split
(
'x'
)[
1
])
}
width
:
parseInt
(
rendition
[
attrValue
.
split
(
'='
)[
0
].
toLowerCase
()].
split
(
'x'
)[
0
]
,
10
),
height
:
parseInt
(
rendition
[
attrValue
.
split
(
'='
)[
0
].
toLowerCase
()].
split
(
'x'
)[
1
]
,
10
)
}
;
}
}
else
{
rendition
[
attrValue
.
split
(
'='
)[
0
].
toLowerCase
()]
=
parseInt
(
attrValue
.
split
(
'='
)[
1
]);
rendition
[
attrValue
.
split
(
'='
)[
0
].
toLowerCase
()]
=
parseInt
(
attrValue
.
split
(
'='
)[
1
]
,
10
);
}
});
...
...
@@ -128,7 +128,7 @@
break
;
case
tagTypes
.
MEDIA_SEQUENCE
:
data
.
mediaSequence
=
parseInt
(
self
.
getTagValue
(
value
));
data
.
mediaSequence
=
parseInt
(
self
.
getTagValue
(
value
)
,
10
);
break
;
case
tagTypes
.
ALLOW_CACHE
:
...
...
src/m3u8/m3u8.js
View file @
dd4862c
(
function
(
window
)
{
window
.
videojs
.
hls
.
M3U8
=
function
()
{
(
function
(
window
)
{
window
.
videojs
.
hls
.
M3U8
=
function
()
{
this
.
directory
=
""
;
this
.
allowCache
=
"NO"
;
this
.
playlistItems
=
[];
...
...
src/manifest-controller.js
View file @
dd4862c
(
function
(
window
)
{
var
M3U8
=
window
.
videojs
.
hls
.
M3U8
,
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
;
...
...
@@ -28,7 +19,7 @@
self
.
onUpdateCallback
=
onUpdateCallback
;
}
vjs
.
get
(
manifestUrl
,
self
.
onManifestLoadComplete
,
self
.
onManifestLoadError
);
window
.
vjs
.
get
(
manifestUrl
,
self
.
onManifestLoadComplete
,
self
.
onManifestLoadError
);
};
self
.
parseManifest
=
function
(
dataAsString
)
{
...
...
@@ -42,15 +33,15 @@
self
.
onManifestLoadComplete
=
function
(
response
)
{
var
output
=
self
.
parseManifest
(
response
);
if
(
self
.
onDataCallback
!=
undefined
)
{
if
(
self
.
onDataCallback
!=
=
undefined
)
{
self
.
onDataCallback
(
output
);
}
};
self
.
onManifestLoadError
=
function
(
err
)
{
if
(
self
.
onErrorCallback
!=
undefined
)
{
self
.
onErrorCallback
((
err
!=
undefined
)
?
err
:
null
);
if
(
self
.
onErrorCallback
!=
=
undefined
)
{
self
.
onErrorCallback
((
err
!=
=
undefined
)
?
err
:
null
);
}
};
}
}
;
})(
this
);
...
...
src/segment-controller.js
View file @
dd4862c
...
...
@@ -14,7 +14,7 @@
request
.
open
(
'GET'
,
segmentUrl
,
true
);
request
.
responseType
=
'arraybuffer'
;
request
.
onload
=
function
(
response
)
{
request
.
onload
=
function
()
{
self
.
onSegmentLoadComplete
(
new
Uint8Array
(
request
.
response
));
};
...
...
@@ -29,7 +29,7 @@
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
.
isCached
=
parseInt
(
self
.
responseTimestamp
-
self
.
requestTimestamp
,
10
)
<
75
;
self
.
data
.
throughput
=
self
.
calculateThroughput
(
self
.
data
.
byteLength
,
self
.
requestTimestamp
,
self
.
responseTimestamp
);
return
self
.
data
;
...
...
@@ -37,7 +37,7 @@
self
.
calculateThroughput
=
function
(
dataAmount
,
startTime
,
endTime
)
{
return
Math
.
round
(
dataAmount
/
(
endTime
-
startTime
)
*
1000
)
*
8
;
}
}
;
self
.
onSegmentLoadComplete
=
function
(
response
)
{
var
output
;
...
...
@@ -57,8 +57,8 @@
}
if
(
self
.
onErrorCallback
!==
undefined
)
{
onErrorCallback
(
error
);
self
.
onErrorCallback
(
error
);
}
};
}
}
;
})(
this
);
...
...
test/video-js-hls_test.js
View file @
dd4862c
This diff is collapsed.
Click to expand it.
Please
register
or
sign in
to post a comment