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
c0d2ed06
authored
2014-03-14 16:15:55 -0400
by
Gary Katsevman
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
convert segmentXHR to use xhr helper
1 parent
64547ed3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
44 deletions
src/videojs-hls.js
src/videojs-hls.js
View file @
c0d2ed0
...
...
@@ -639,68 +639,62 @@ var
}
// request the next segment
segmentXhr
=
new
window
.
XMLHttpRequest
();
segmentXhr
.
open
(
'GET'
,
segmentUri
);
segmentXhr
.
responseType
=
'arraybuffer'
;
segmentXhr
.
onreadystatechange
=
function
()
{
// wait until the request completes
if
(
this
.
readyState
!==
4
)
{
return
;
}
segmentXhr
=
xhr
({
url
:
segmentUri
,
responseType
:
'arraybuffer'
},
function
(
error
,
url
)
{
// the segment request is no longer outstanding
segmentXhr
=
null
;
// trigger an error if the request was not successful
if
(
this
.
status
>=
400
)
{
if
(
error
)
{
player
.
hls
.
error
=
{
status
:
this
.
status
,
message
:
'HLS segment request error at URL: '
+
segmentUri
,
message
:
'HLS segment request error at URL: '
+
url
,
code
:
(
this
.
status
>=
500
)
?
4
:
2
};
// try moving on to the next segment
player
.
hls
.
mediaIndex
++
;
return
;
}
// stop processing if the request was aborted
if
(
!
this
.
response
)
{
return
;
}
// calculate the download bandwidth
player
.
hls
.
segmentXhrTime
=
(
+
new
Date
())
-
startTime
;
player
.
hls
.
bandwidth
=
(
this
.
response
.
byteLength
/
player
.
hls
.
segmentXhrTime
)
*
8
*
1000
;
}
else
{
// stop processing if the request was aborted
if
(
!
this
.
response
)
{
return
;
}
// transmux the segment data from MP2T to FLV
segmentParser
.
parseSegmentBinaryData
(
new
Uint8Array
(
this
.
response
));
segmentParser
.
flushTags
();
// calculate the download bandwidth
player
.
hls
.
segmentXhrTime
=
(
+
new
Date
())
-
startTime
;
player
.
hls
.
bandwidth
=
(
this
.
response
.
byteLength
/
player
.
hls
.
segmentXhrTime
)
*
8
*
1000
;
// transmux the segment data from MP2T to FLV
segmentParser
.
parseSegmentBinaryData
(
new
Uint8Array
(
this
.
response
));
segmentParser
.
flushTags
();
// if we're refilling the buffer after a seek, scan through the muxed
// FLV tags until we find the one that is closest to the desired
// playback time
if
(
offset
!==
undefined
&&
typeof
offset
===
"number"
)
{
while
(
segmentParser
.
getTags
()[
0
].
pts
<
offset
)
{
segmentParser
.
getNextTag
();
}
}
// if we're refilling the buffer after a seek, scan through the muxed
// FLV tags until we find the one that is closest to the desired
// playback time
if
(
offset
!==
undefined
&&
typeof
offset
===
"number"
)
{
while
(
segmentParser
.
getTags
()[
0
].
pts
<
offset
)
{
segmentParser
.
getNextTag
();
while
(
segmentParser
.
tagsAvailable
())
{
// queue up the bytes to be appended to the SourceBuffer
// the queue gives control back to the browser between tags
// so that large segments don't cause a "hiccup" in playback
tags
.
push
(
segmentParser
.
getNextTag
().
bytes
);
}
}
while
(
segmentParser
.
tagsAvailable
())
{
// queue up the bytes to be appended to the SourceBuffer
// the queue gives control back to the browser between tags
// so that large segments don't cause a "hiccup" in playback
tags
.
push
(
segmentParser
.
getNextTag
().
bytes
);
}
player
.
hls
.
mediaIndex
++
;
player
.
hls
.
mediaIndex
++
;
// figure out what stream the next segment should be downloaded from
// with the updated bandwidth information
updateCurrentPlaylist
();
}
});
// figure out what stream the next segment should be downloaded from
// with the updated bandwidth information
updateCurrentPlaylist
();
};
startTime
=
+
new
Date
();
segmentXhr
.
send
(
null
);
};
// load the MediaSource into the player
...
...
Please
register
or
sign in
to post a comment