1 /* vi: set et sw=4 ts=4 si: */
3 var library = function() {
5 this.initialized = false;
11 this.initialize = function() {
15 if (win.tizen === undefined) {
16 throw Error("You need the Tizen web API to run Hoofbeats.");
19 this.audioTypeFilter = new tizen.AttributeFilter(
20 "type", "EXACTLY", "AUDIO");
21 this.videoTypeFilter = new tizen.AttributeFilter(
22 "type", "EXACTLY", "VIDEO");
23 this.typeFilter = new tizen.CompositeFilter(
24 "UNION", [this.audioTypeFilter, this.videoTypeFilter]);
27 this.scan = function() {
28 this.deferred = new $.Deferred();
35 this.findCB.bind(this),
36 this.errorCB.bind(this),
43 return this.deferred.promise();
46 this.errorCB = function(error) {
47 console.log("Error: " + error.name);
48 this.deferred.reject();
49 throw new Error(error.name);
52 this.findCB = function(items) {
55 items.forEach(function(item, index, items) {
56 self.mediaItems.push(item);
57 win.MusicBrainz.getArtist(item.artists[0]).done(function(data) {
62 if (items.length == this.fetchCount) {
63 // There *might* be more items.
64 this.fetchOffset += this.fetchCount;
66 this.findCB.bind(this),
67 this.errorCB.bind(this),
74 self.deferred.resolve();
80 set initialized(value) {this._initialized = value; },
81 get initialized() { return this._initialized; }
84 win.HoofbeatsLibrary = library;