From d414d4eaa711194034a4f2c0e8f4e2bb5d2fc37a Mon Sep 17 00:00:00 2001 From: Timothy Drews Date: Wed, 8 Apr 2015 13:21:11 -0700 Subject: [PATCH] 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 --- app.js | 15 ++------ lib/player/offline_video_source.js | 59 ++++++++++++++++++++++-------- lib/util/content_database.js | 6 +-- 3 files changed, 50 insertions(+), 30 deletions(-) diff --git a/app.js b/app.js index 54fefed57..8f8562393 100644 --- a/app.js +++ b/app.js @@ -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.} 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); } ); diff --git a/lib/player/offline_video_source.js b/lib/player/offline_video_source.js index 957041efe..a60020ba9 100644 --- a/lib/player/offline_video_source.js +++ b/lib/player/offline_video_source.js @@ -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.>} 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; diff --git a/lib/util/content_database.js b/lib/util/content_database.js index ecbb524e5..64834f7d3 100644 --- a/lib/util/content_database.js +++ b/lib/util/content_database.js @@ -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. @@ -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));