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
b0431885
authored
2014-05-27 23:41:10 -0400
by
David LaPalomento
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge remote-tracking branch 'origin/master' into feature/switching
2 parents
65d53488
2318f8d7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
29 deletions
package.json
src/videojs-hls.js
test/videojs-hls_test.js
package.json
View file @
b043188
...
...
@@ -34,12 +34,9 @@
"karma-safari-launcher"
:
"~0.1.1"
,
"karma-sauce-launcher"
:
"~0.1.8"
,
"sinon"
:
"^1.9.1"
,
"video.js"
:
"^4.5"
},
"peerDependencies"
:
{
"video.js"
:
"^4.5"
"video.js"
:
"git+https://github.com/dmlap/video-js.git#0.6.1-alpha"
},
"dependencies"
:
{
"videojs-contrib-media-sources"
:
"
^0.2
"
"videojs-contrib-media-sources"
:
"
git+https://github.com/videojs/videojs-contrib-media-sources.git#c1b0f3bd83ec975442b0a53864f6793a56751fb8
"
}
}
...
...
src/videojs-hls.js
View file @
b043188
...
...
@@ -183,20 +183,36 @@ var
initSource
=
function
(
player
,
mediaSource
,
srcUrl
)
{
var
segmentParser
=
new
videojs
.
Hls
.
SegmentParser
(),
settings
=
videojs
.
util
.
mergeOptions
({},
player
.
options
().
hls
),
lastSeekedTime
,
segmentXhr
,
settings
=
videojs
.
util
.
mergeOptions
({},
player
.
options
().
hls
),
fillBuffer
,
updateDuration
;
player
.
on
(
'seeking'
,
function
()
{
var
currentTime
=
player
.
currentTime
();
player
.
hls
.
mediaIndex
=
getMediaIndexByTime
(
player
.
hls
.
playlists
.
media
(),
currentTime
);
player
.
hls
.
currentTime
=
function
()
{
if
(
lastSeekedTime
)
{
return
lastSeekedTime
;
}
return
this
.
el
().
vjs_getProperty
(
'currentTime'
);
};
player
.
hls
.
setCurrentTime
=
function
(
currentTime
)
{
if
(
!
(
this
.
playlists
&&
this
.
playlists
.
media
()))
{
// return immediately if the metadata is not ready yet
return
0
;
}
// save the seek target so currentTime can report it correctly
// while the seek is pending
lastSeekedTime
=
currentTime
;
// determine the requested segment
this
.
mediaIndex
=
getMediaIndexByTime
(
this
.
playlists
.
media
(),
currentTime
);
// abort any segments still being decoded
player
.
hl
s
.
sourceBuffer
.
abort
();
thi
s
.
sourceBuffer
.
abort
();
// cancel outstanding requests and buffer appends
if
(
segmentXhr
)
{
...
...
@@ -205,7 +221,7 @@ var
// begin filling the buffer at the new position
fillBuffer
(
currentTime
*
1000
);
}
)
;
};
/**
* Update the player duration
...
...
@@ -324,8 +340,9 @@ var
bufferedTime
=
player
.
buffered
().
end
(
0
)
-
player
.
currentTime
();
}
// if there is plenty of content in the buffer, relax for awhile
if
(
bufferedTime
>=
goalBufferLength
)
{
// if there is plenty of content in the buffer and we're not
// seeking, relax for awhile
if
(
typeof
offset
!==
'number'
&&
bufferedTime
>=
goalBufferLength
)
{
return
;
}
...
...
@@ -376,11 +393,19 @@ var
// 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
(
typeof
offset
===
'number'
)
{
(
function
()
{
var
tag
=
segmentParser
.
getTags
()[
0
];
for
(;
tag
.
pts
<
offset
;
tag
=
segmentParser
.
getTags
()[
0
])
{
segmentParser
.
getNextTag
();
}
// tell the SWF where we will be seeking to
player
.
hls
.
el
().
vjs_setProperty
(
'currentTime'
,
tag
.
pts
*
0.001
);
lastSeekedTime
=
null
;
})();
}
}
while
(
segmentParser
.
tagsAvailable
())
{
// queue up the bytes to be appended to the SourceBuffer
...
...
@@ -467,6 +492,7 @@ videojs.Hls = videojs.Flash.extend({
videojs
.
Hls
.
prototype
.
src
=
function
(
src
)
{
var
player
=
this
.
player
(),
self
=
this
,
mediaSource
,
source
;
...
...
@@ -478,8 +504,8 @@ videojs.Hls.prototype.src = function(src) {
};
this
.
mediaSource
=
mediaSource
;
initSource
(
player
,
mediaSource
,
src
);
this
.
ready
(
function
()
{
this
.
el
().
vjs_src
(
source
.
src
);
this
.
player
().
ready
(
function
()
{
self
.
el
().
vjs_src
(
source
.
src
);
});
}
};
...
...
test/videojs-hls_test.js
View file @
b043188
...
...
@@ -49,6 +49,7 @@ var
tech
=
player
.
el
().
querySelector
(
'.vjs-tech'
);
tech
.
vjs_getProperty
=
function
()
{};
tech
.
vjs_setProperty
=
function
()
{};
tech
.
vjs_src
=
function
()
{};
videojs
.
Flash
.
onReady
(
tech
.
id
);
...
...
@@ -754,7 +755,7 @@ test('cancels outstanding XHRs when seeking', function() {
// trigger a segment download request
player
.
trigger
(
'timeupdate'
);
// attempt to seek while the download is in progress
player
.
trigger
(
'seeking'
);
player
.
currentTime
(
7
);
ok
(
requests
[
1
].
aborted
,
'XHR aborted'
);
strictEqual
(
requests
.
length
,
3
,
'opened new XHR'
);
...
...
@@ -830,10 +831,7 @@ test('drops tags before the target timestamp when seeking', function() {
bytes
:
i
});
}
player
.
currentTime
=
function
()
{
return
7
;
};
player
.
trigger
(
'seeking'
);
player
.
currentTime
(
7
);
standardXHRResponse
(
requests
[
2
]);
while
(
callbacks
.
length
)
{
...
...
@@ -879,10 +877,7 @@ test('clears pending buffer updates when seeking', function() {
// seek to 7s
tags
.
push
({
pts
:
7000
,
bytes
:
7
});
player
.
currentTime
=
function
()
{
return
7
;
};
player
.
trigger
(
'seeking'
);
player
.
currentTime
(
7
);
standardXHRResponse
(
requests
[
2
]);
while
(
callbacks
.
length
)
{
...
...
Please
register
or
sign in
to post a comment