Add support for Media Source v0.5.
- Updated dash_player.js to work with Media Source v0.3 and 0.5.
- Changed text on error message for Chrome versions lower than 17.
Change-Id: I92ba714fc142afb80f351911933e21469755da6b
diff --git a/adaptive/dash-player.html b/adaptive/dash-player.html
index fb5cb6f..d7d4bfe 100644
--- a/adaptive/dash-player.html
+++ b/adaptive/dash-player.html
@@ -90,10 +90,10 @@
if (!videoTag.webkitMediaSourceURL) {
var str = 'Video tag does not have Media Source API support!';
log(str);
- alert(str + '\n' +
- 'Make sure you are using Chrome version 17+.\n' +
- 'Then go to "chrome://flags" and turn on\n' +
- '"Enable Media Source API on <video> elements"');
+ alert(str + '\n\n' +
+ 'To run the demo you must have Chrome or Chromium version 17+' +
+ ' and enable the following feature in chrome://flags\n\n' +
+ 'Enable Media Source API on <video> elements\n');
return;
}
diff --git a/adaptive/dash_player.js b/adaptive/dash_player.js
index 16de830..e2f07a9 100644
--- a/adaptive/dash_player.js
+++ b/adaptive/dash_player.js
@@ -538,6 +538,13 @@
this.webMFilesMap_ = {};
this.eventCallbacks_ = {};
+ this.mediaSourceVersion_ = 0.3;
+ if (this.videoElement.webkitSourceAddId)
+ this.mediaSourceVersion_ = 0.5;
+
+ this.log('Created DashPlayer. this.mediaSourceVersion_:' +
+ this.mediaSourceVersion_);
+
var t = this;
this.videoElement.addEventListener('webkitsourceopen', function() {
t.doOpen(function() {
@@ -602,7 +609,7 @@
* @return {string} version.
*/
DashPlayer.version = function() {
- return '0.1.0.1';
+ return '0.2.0.0';
};
/**
@@ -773,6 +780,20 @@
DashPlayer.prototype.webMFilesMap_ = null;
/**
+ * The source ID string for Media Source API.
+ * @private
+ * @type {string}
+ */
+DashPlayer.prototype.mediaSourceIDString_ = 'source1';
+
+/**
+ * Media Source API version.
+ * @private
+ * @type {number}
+ */
+DashPlayer.prototype.mediaSourceVersion_ = 0.3;
+
+/**
* Logging function to be set by the application.
* @param {string} str The input string to be logged.
*/
@@ -817,6 +838,11 @@
return new ErrorStatus(errorStr);
}
+ if (this.mediaSourceVersion_ == 0.5) {
+ this.videoElement.webkitSourceAddId(this.mediaSourceIDString_,
+ 'video/webm; codecs="vp8, vorbis"');
+ }
+
if (this.dashParser == null) {
var res = this.parseManifest(function() {
setupStreamsFunction();
@@ -858,7 +884,7 @@
this.seekSequenceNum += 1;
this.seekTime = this.videoElement.currentTime;
- this.log('doSeeking ' + this.seekTime);
+ this.log('doSeeking ' + this.seekTime + ' newSeqNum:' + this.seekSequenceNum);
if (this.state == DashPlayer.SEEKING) {
this.log('Already seeking...');
@@ -867,6 +893,9 @@
this.changeState(DashPlayer.SEEKING);
+ if (this.mediaSourceVersion_ == 0.5)
+ this.videoElement.webkitSourceAbort(this.mediaSourceIDString_);
+
var vid = this.adaptiveStreams_['video'];
if (vid.fetchingClusters_) {
// We have to wait until we finish fetching clusters
@@ -972,8 +1001,13 @@
this.log('Error appendData() state != LOADING state:' + this.state +
' data.length:' + data.length);
- if (this.state == DashPlayer.LOADING)
- this.videoElement.webkitSourceAppend(data);
+ if (this.state == DashPlayer.LOADING) {
+ if (this.mediaSourceVersion_ == 0.5) {
+ this.videoElement.webkitSourceAppend(this.mediaSourceIDString_, data);
+ } else {
+ this.videoElement.webkitSourceAppend(data);
+ }
+ }
};
/**
@@ -2364,7 +2398,7 @@
//Check to see if a seek happened while we were getting the cluster.
if (seqNum != this.seekSequenceNum) {
- this.logCue('onPartialCluster() != this.seekSequenceNum' +
+ this.logCue('onPartialCluster() != this.seekSequenceNum:' +
this.seekSequenceNum, stream.source.representation.id, seqNum,
stream.cueDesc, buf.length, stream.cueBytesDownloaded_,
nextCueDesc);