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
10a996a2
authored
2014-01-20 10:56:18 -0800
by
Tom Johnson
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Include HLS seeking tests for PTS detection routine
1 parent
f914eaeb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
15 deletions
src/videojs-hls.js
test/videojs-hls_test.js
src/videojs-hls.js
View file @
10a996a
...
...
@@ -59,19 +59,6 @@ var
return
-
1
;
},
getPtsByTime
=
function
(
segmentParser
,
time
)
{
var
index
=
0
;
for
(
index
;
index
<
segmentParser
.
getTags
().
length
;
index
++
)
{
if
(
index
===
segmentParser
.
getTags
().
length
-
1
)
{
return
segmentParser
.
getTags
()[
index
].
pts
;
}
else
{
if
(
segmentParser
.
getTags
()[
index
].
pts
<=
time
&&
segmentParser
.
getTags
()[
index
+
1
].
pts
>
time
)
{
return
segmentParser
.
getTags
()[
index
].
pts
;
}
}
}
},
/**
* Calculate the total duration for a playlist based on segment metadata.
...
...
@@ -167,6 +154,20 @@ var
return
1
;
// HAVE_METADATA
};
player
.
hls
.
getPtsByTime
=
function
(
segmentParser
,
time
)
{
var
index
=
0
;
for
(
index
;
index
<
segmentParser
.
getTags
().
length
;
index
++
)
{
if
(
index
===
segmentParser
.
getTags
().
length
-
1
)
{
return
segmentParser
.
getTags
()[
index
].
pts
;
}
else
{
if
(
segmentParser
.
getTags
()[
index
].
pts
<=
time
&&
segmentParser
.
getTags
()[
index
+
1
].
pts
>
time
)
{
return
segmentParser
.
getTags
()[
index
].
pts
;
}
}
}
};
player
.
on
(
'seeking'
,
function
()
{
var
currentTime
=
player
.
currentTime
();
player
.
hls
.
mediaIndex
=
getMediaIndexByTime
(
player
.
hls
.
media
,
currentTime
);
...
...
@@ -365,7 +366,7 @@ var
// handle intra-segment seeking, if requested //
if
(
offset
!==
undefined
&&
typeof
offset
===
"number"
)
{
player
.
el
().
querySelector
(
'.vjs-tech'
).
vjs_setProperty
(
'lastSeekedTime'
,
getPtsByTime
(
segmentParser
,
offset
)
/
1000
);
player
.
el
().
querySelector
(
'.vjs-tech'
).
vjs_setProperty
(
'lastSeekedTime'
,
player
.
hls
.
getPtsByTime
(
segmentParser
,
offset
)
/
1000
);
for
(
tagIndex
=
0
;
tagIndex
<
segmentParser
.
getTags
().
length
;
tagIndex
++
)
{
if
(
segmentParser
.
getTags
()[
tagIndex
].
pts
>
offset
)
{
break
;
...
...
test/videojs-hls_test.js
View file @
10a996a
...
...
@@ -514,11 +514,43 @@ test('cancels outstanding XHRs when seeking', function() {
strictEqual
(
1
,
opened
,
'opened new XHR'
);
});
test
(
'gets the correct PTS on seek'
,
function
()
{
var
ptsByTime
=
-
1
,
seekTime
=
5.123
,
segmentParser
=
new
window
.
videojs
.
hls
.
SegmentParser
();
segmentParser
.
getTags
=
function
()
{
return
[
{
pts
:
1
},
{
pts
:
2
},
{
pts
:
3
},
{
pts
:
4
},
{
pts
:
5
},
{
pts
:
6
}
];
};
player
.
hls
(
'manifest/media.m3u8'
);
videojs
.
mediaSources
[
player
.
currentSrc
()].
trigger
({
type
:
'sourceopen'
});
player
.
on
(
'seeked'
,
function
()
{
ptsByTime
=
player
.
hls
.
getPtsByTime
(
segmentParser
,
seekTime
);
});
player
.
trigger
(
'seeked'
);
notEqual
(
ptsByTime
,
-
1
,
'PTS Should be set on seek'
);
strictEqual
(
ptsByTime
,
5
,
'PTS should be closest'
);
ok
(
ptsByTime
<=
seekTime
,
'PTS should be less than or equal to seek time'
);
});
module
(
'segment controller'
,
{
setup
:
function
()
{
segmentController
=
new
window
.
videojs
.
hls
.
SegmentController
();
},
teardown
:
function
()
{
window
.
videojs
.
get
=
this
.
vjsget
;
...
...
Please
register
or
sign in
to post a comment