Fix load stream in compiled mode.

* Move retrieveGroupIds to OfflineVideoSource.
* Quote properties of stored objects to avoid variable
  renaming issues.

Issue #22

Change-Id: I31ca1261411de5ff5ae4859da571d0029ed77f42
This commit is contained in:
Timothy Drews
2015-04-08 13:21:11 -07:00
committed by Gerrit Code Review
parent 176aac3bc1
commit d414d4eaa7
3 changed files with 50 additions and 30 deletions
+3 -12
View File
@@ -137,12 +137,8 @@ app.init = function() {
}
// Retrieve and verify list of offline streams
var storage = new shaka.util.ContentDatabase(null);
storage.setUpDatabase().then(
function() {
return storage.retrieveGroupIds();
}
).then(
shaka.player.OfflineVideoSource.retrieveGroupIds().then(
/** @param {!Array.<number>} groupIds */
function(groupIds) {
var groups = app.getOfflineGroups_();
for (var i in groupIds) {
@@ -154,14 +150,9 @@ app.init = function() {
app.addOfflineStream_(value, id);
}
}
).then(
function() {
storage.closeDatabaseConnection();
}
).catch(
function(e) {
storage.closeDatabaseConnection();
console.error('Error retrieving stored data', e);
console.error('Failed to retrieve group IDs', e);
}
);
+44 -15
View File
@@ -76,6 +76,34 @@ goog.inherits(shaka.player.OfflineVideoSource, shaka.player.StreamVideoSource);
shaka.player.OfflineVideoSource.ChooseTracksCallback;
/**
* Retrieves an array of all stored group IDs.
* @return {!Promise.<!Array.<number>>} The unique IDs of all of the
* stored groups.
* @export
*/
shaka.player.OfflineVideoSource.retrieveGroupIds = function() {
var contentDatabase = new shaka.util.ContentDatabase(null);
var p = contentDatabase.setUpDatabase().then(
function() {
return contentDatabase.retrieveGroupIds();
});
p.then(
function() {
contentDatabase.closeDatabaseConnection();
}
).catch(
function() {
contentDatabase.closeDatabaseConnection();
}
);
return p;
};
/**
* Stores the content described by the MPD for offline playback.
* @param {string} mpdUrl The MPD URL.
@@ -306,9 +334,10 @@ shaka.player.OfflineVideoSource.prototype.load = function(preferredLanguage) {
/** @param {shaka.util.ContentDatabase.GroupInformation} group */
function(group) {
var async = [];
this.sessionIds_ = group.session_ids;
for (var i = 0; i < group.stream_ids.length; ++i) {
async.push(contentDatabase.retrieveStreamIndex(group.stream_ids[i]));
this.sessionIds_ = group['session_ids'];
for (var i = 0; i < group['stream_ids'].length; ++i) {
var streamId = group['stream_ids'][i];
async.push(contentDatabase.retrieveStreamIndex(streamId));
}
return Promise.all(async);
})
@@ -352,15 +381,15 @@ shaka.player.OfflineVideoSource.prototype.reconstructManifestInfo_ =
var storedStreamInfo = indexes[i];
var references = [];
for (var j = 0; j < storedStreamInfo.references.length; j++) {
var info = storedStreamInfo.references[j];
for (var j = 0; j < storedStreamInfo['references'].length; j++) {
var info = storedStreamInfo['references'][j];
var reference = new shaka.media.SegmentReference(
info.index,
info.start_time,
info.end_time,
info.start_byte,
info['index'],
info['start_time'],
info['end_time'],
info['start_byte'],
null,
new goog.Uri(info.url));
new goog.Uri(info['url']));
references.push(reference);
}
@@ -368,18 +397,18 @@ shaka.player.OfflineVideoSource.prototype.reconstructManifestInfo_ =
var streamInfo = new shaka.media.StreamInfo();
var segmentIndex = new shaka.media.SegmentIndex(references);
streamInfo.segmentIndex = segmentIndex;
streamInfo.mimeType = storedStreamInfo.mime_type;
streamInfo.codecs = storedStreamInfo.codecs;
streamInfo.segmentInitializationData = storedStreamInfo.init_segment;
streamInfo.mimeType = storedStreamInfo['mime_type'];
streamInfo.codecs = storedStreamInfo['codecs'];
streamInfo.segmentInitializationData = storedStreamInfo['init_segment'];
var drmSchemeInfo = new shaka.player.DrmSchemeInfo(
storedStreamInfo.key_system, false, '', false, null, null);
storedStreamInfo['key_system'], false, '', false, null, null);
var streamSetInfo = new shaka.media.StreamSetInfo();
streamSetInfo.streamInfos.push(streamInfo);
streamSetInfo.drmSchemes.push(drmSchemeInfo);
streamSetInfo.contentType = streamInfo.mimeType.split('/')[0];
periodInfo.streamSetInfos.push(streamSetInfo);
periodInfo.duration = storedStreamInfo.duration;
periodInfo.duration = storedStreamInfo['duration'];
}
manifestInfo.periodInfos.push(periodInfo);
return manifestInfo;
+3 -3
View File
@@ -225,7 +225,7 @@ shaka.util.ContentDatabase.SegmentInformation;
* stream_id: number,
* mime_type: string,
* codecs: string,
* duration: number,
* duration: ?number,
* init_segment: ArrayBuffer,
* key_system: string,
* references: !Array.<shaka.util.ContentDatabase.SegmentInformation>
@@ -626,8 +626,8 @@ shaka.util.ContentDatabase.prototype.deleteGroup = function(groupId) {
/** @param {shaka.util.ContentDatabase.GroupInformation} result */
function(result) {
var async = [];
for (var id in result.stream_ids) {
async.push(this.deleteStream(result.stream_ids[id]));
for (var id in result['stream_ids']) {
async.push(this.deleteStream(result['stream_ids'][id]));
}
var groupStore = this.getGroupStore_();
async.push(groupStore.delete(groupId));