+/* vi: set et sw=4 ts=4 si: */
$(function() {
var library = function() {
// For readability:
this.initialized = false;
+
this.fetchCount = 100;
this.fetchOffset = 0;
this.mediaItems = [];
"type", "EXACTLY", "VIDEO");
this.typeFilter = new tizen.CompositeFilter(
"UNION", [this.audioTypeFilter, this.videoTypeFilter]);
-
- this.sortMode = new tizen.SortMode("trackNumber", "ASC");
- this.mediaSource = tizen.mediacontent.getLocalMediaSource();
};
this.scan = function() {
+ this.deferred = new $.Deferred();
this.initialize()
this.mediaItems = [];
this.fetchOffset = 0;
- this.mediaSource.findItems(
- this.findItemsCB.bind(this),
+ tizen.content.find(
+ this.findCB.bind(this),
this.errorCB.bind(this),
null,
this.typeFilter,
- this.sortMode,
+ null,
this.fetchCount,
this.fetchOffset);
+
+ return this.deferred.promise();
};
this.errorCB = function(error) {
console.log("Error: " + error.name);
+ this.deferred.reject();
throw new Error(error.name);
};
- this.findItemsCB = function(items) {
+ this.findCB = function(items) {
var self = this;
items.forEach(function(item, index, items) {
self.mediaItems.push(item);
- console.log("Item added to the library: " + item.title);
+ window.MusicBrainz.getArtist(item.name).done(function(data) {
+ console.log(data);
+ });
});
if (items.length == this.fetchCount) {
// There *might* be more items.
this.fetchOffset += this.fetchCount;
- this.mediaSource.findItems(
- this.findItemsCB.bind(this),
+ tizen.content.find(
+ this.findCB.bind(this),
this.errorCB.bind(this),
null,
this.typeFilter,
- this.sortMode,
+ null,
this.fetchCount,
this.fetchOffset);
+ } else {
+ self.deferred.resolve();
}
};
};