Commit c198f439 authored by Xiaowu Zhang's avatar Xiaowu Zhang

add initialize mechanism in audio control gadget

parent 3f7d21fa
...@@ -128,7 +128,17 @@ ...@@ -128,7 +128,17 @@
g.io = e; g.io = e;
g.io.createIO({ "type" : "indexeddb", g.io.createIO({ "type" : "indexeddb",
"database": "test"}, "database": "test"},
"m"); "m")
.then(function () {
g.io.showAllIO().then(function (result) {
var array = Object.keys(result),
i;
for (i = 0; i < array.length; i += 1) {
g.playlist.push(array[i]);
}
g.sendTotalId(g.playlist.length);
});
});
}); });
g.audio = new window.Audio(); g.audio = new window.Audio();
g.source = g.audioCtx.createMediaElementSource(g.audio); g.source = g.audioCtx.createMediaElementSource(g.audio);
...@@ -137,8 +147,9 @@ ...@@ -137,8 +147,9 @@
g.decoded = true; g.decoded = true;
g.audio.onended = function () { g.audio.onended = function () {
g.nextToPlay().then(function (id) { g.nextToPlay().then(function (id) {
g.setSong(id); g.setSong(id).then(function () {
g.playSong(id); g.playSong(id);
});
}); });
}; };
input_context.onchange = function () { input_context.onchange = function () {
......
/*global window, rJS, RSVP, jIO, JSON, console, indexedDB */ /*global window, rJS, RSVP, jIO, JSON, console, indexedDB */
/*jslint nomen: true*/
(function (window, jIO, rJS) { (function (window, jIO, rJS) {
"use strict"; "use strict";
var gk = rJS(window); var gk = rJS(window);
gk.declareMethod('createIO', function (description, key) { gk.declareMethod('createIO', function (description, key) {
indexedDB.deleteDatabase("jio:test"); // indexedDB.deleteDatabase("jio:test");
this.jio = jIO.createJIO(description); this.jio = jIO.createJIO(description);
this.key = key; this.key = key;
this.jio.put({ return this.jio.put({
"_id" : key "_id" : key
}).then(function () { }).then(function () {
description = JSON.stringify(description, null, " "); description = JSON.stringify(description, null, " ");
console.log("JIO created: " + description + "\nwith key: " + key); console.log("JIO created: " + description + "\nwith key: " + key);
}).catch(function (e) { return;
}).fail(function (e) {
console.log("jio created error: " + e.target.result); console.log("jio created error: " + e.target.result);
return;
}); });
}) })
.declareMethod('getIO', function (attachment) { .declareMethod('getIO', function (attachment) {
...@@ -31,18 +33,24 @@ ...@@ -31,18 +33,24 @@
}) })
.declareMethod('setIO', function (attachment, file) { .declareMethod('setIO', function (attachment, file) {
var gadget = this; var gadget = this;
gadget.jio.putAttachment({ return gadget.jio.putAttachment({
"_id": gadget.key, "_id": gadget.key,
"_attachment": attachment, "_attachment": attachment,
"_blob": file "_blob": file
}).then(function (e) { }).then(function (e) {
console.log(e); return e;
}).fail(function (error) {
return "ERROR : " + error;
}); });
}) })
.declareMethod('showAllIO', function () { .declareMethod('showAllIO', function () {
var gadget = this; var gadget = this;
return gadget.jio.allDoc({ return gadget.jio.allDocs({
"include_docs": "m" "include_docs": "m"
}).then(function (result) {
return result.data.rows[0].doc._attachment;
}).fail(function (error) {
return "ERROR : " + error;
}); });
}); });
}(window, jIO, rJS)); }(window, jIO, rJS));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment