it('Test constructor with single item', function() { var p; p = Playlist(mp4.starscape); assert.isOk(isValidPlaylistItem(p[0]), 'Initialize single item'); p = Playlist(undefined); assert.isOk(isValidPlaylistItem(p[0]), 'Initialize with undefined item'); // TODO: this doesn't actually work, shouldn't pass p = Playlist(mp4.starscape.file); assert.isOk(isValidPlaylistItem(p[0]), 'Initialize with just file name'); });
it('Test constructor with array of items', function() { var p; var arr = [mp4.starscape, mp4.starscape, mp4.starscape]; p = Playlist(arr); assert.equal(p.length, arr.length, 'Same number of items initialized'); p = Playlist([mp4.starscape]); assert.isOk(isValidPlaylistItem(p[0]), 'Initialize single item array'); // TODO: inconsistent, this is the only case where it returns an empty array p = Playlist([]); assert.isOk(_.isArray(p) && p.length === 0, 'Initialize with an empty array as argument'); });
function _updatePlaylist(data, feedData) { const playlist = Playlist(data); try { setPlaylist(_model, playlist, feedData); } catch (error) { _model.set('item', 0); _model.set('playlistItem', null); return Promise.reject(error); } return _setItem(0); }
function _load(item, feedData) { const instream = _this._instreamAdapter; if (instream) { instream.noResume = true; } _this.trigger('destroyPlugin', {}); _stop(true); checkAutoStartCancelable.cancel(); checkAutoStartCancelable = cancelable(_checkAutoStart); updatePlaylistCancelable.cancel(); if (inInteraction()) { mediaPool.prime(); } let loadPromise; switch (typeof item) { case 'string': { _model.attributes.item = 0; _model.attributes.itemReady = false; updatePlaylistCancelable = cancelable((data) => { if (data) { return _this.updatePlaylist(Playlist(data.playlist), data); } }); loadPromise = _loadPlaylist(item).then(updatePlaylistCancelable.async); break; } case 'object': _model.attributes.item = 0; loadPromise = _this.updatePlaylist(Playlist(item), feedData || {}); break; case 'number': loadPromise = _this.setItemIndex(item); break; default: return; } // Catch playlist exceptions. Item exceptions are caught first from setActiveItem. loadPromise.catch(error => { _this.triggerError(composePlayerError(error, ERROR_LOADING_PLAYLIST)); }); loadPromise.then(checkAutoStartCancelable.async).catch(noop); }
function setPlaylistAttributes(model, playlist, feedData) { const attributes = model.attributes; attributes.playlist = Playlist(playlist); attributes.feedData = feedData; }
updatePlaylistCancelable = cancelable((data) => { if (data) { return _this.updatePlaylist(Playlist(data.playlist), data); } });