Commit 7eafe6e7 authored by Xiaowu Zhang's avatar Xiaowu Zhang

add artist&album&cover support

parent 737caf7a
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
upload: { upload: {
"0": "../audioplayer_upload/index.html", "0": "../audioplayer_upload/index.html",
"1": "../audioplayer_playlist_local/index.html", "1": "../audioplayer_playlist_local/index.html",
"2": "../audioplayer_playlist_online/index.html" "2": "../audioplayer_upload/index.html"
}, },
playlist: { playlist: {
"0": "../audioplayer_playlist_offline/index.html", "0": "../audioplayer_playlist_offline/index.html",
...@@ -56,11 +56,11 @@ ...@@ -56,11 +56,11 @@
} }
}).allowPublicAcquisition("plDisablePage", function() { }).allowPublicAcquisition("plDisablePage", function() {
disablePage(this); disablePage(this);
}).allowPublicAcquisition("plCreateHttpStorage", function(list) { }).allowPublicAcquisition("plCreateDavStorage", function(list) {
return this.getDeclaredGadget("online").push(function(gadget) { return this.getDeclaredGadget("online").push(function(gadget) {
return gadget.createJio({ return gadget.createJio({
type: "http", type: "dav",
database: list[0] url: list[0]
}); });
}); });
}).allowPublicAcquisition("displayThisPage", function(param_list) { }).allowPublicAcquisition("displayThisPage", function(param_list) {
...@@ -71,14 +71,14 @@ ...@@ -71,14 +71,14 @@
var key = Object.keys(param_list[0]); var key = Object.keys(param_list[0]);
this.save[key[0]] = param_list[0][key[0]]; this.save[key[0]] = param_list[0][key[0]];
}).allowPublicAcquisition("plGiveStorageType", function() { }).allowPublicAcquisition("plGiveStorageType", function() {
return storageType(this.storageType); return this.storageType;
}).allowPublicAcquisition("plGive", function(param_list) { }).allowPublicAcquisition("plGive", function(param_list) {
if (this.save === undefined) { if (this.save === undefined) {
return this.save; return this.save;
} }
return this.save[param_list[0]]; return this.save[param_list[0]];
}).allowPublicAcquisition("allDocs", function(param_list) { }).allowPublicAcquisition("allDocs", function(param_list) {
if (this.storageType !== 0) { if (this.storageType === 1) {
param_list[0].save = true; param_list[0].save = true;
} else { } else {
param_list[0].save = false; param_list[0].save = false;
...@@ -88,8 +88,8 @@ ...@@ -88,8 +88,8 @@
}); });
}).allowPublicAcquisition("jio_post", function(param_list) { }).allowPublicAcquisition("jio_post", function(param_list) {
var type; var type;
if (param_list[1] === 0) { if (param_list[1] === 0 || param_list[1] === 1) {
type = 0; type = param_list[1];
} else { } else {
type = this.storageType; type = this.storageType;
} }
...@@ -98,8 +98,8 @@ ...@@ -98,8 +98,8 @@
}); });
}).allowPublicAcquisition("jio_putAttachment", function(param_list) { }).allowPublicAcquisition("jio_putAttachment", function(param_list) {
var type; var type;
if (param_list[1] === 0) { if (param_list[1] === 0 || param_list[1] === 1) {
type = 0; type = param_list[1];
} else { } else {
type = this.storageType; type = this.storageType;
} }
...@@ -115,17 +115,13 @@ ...@@ -115,17 +115,13 @@
return jio_gadget.get.apply(jio_gadget, param_list); return jio_gadget.get.apply(jio_gadget, param_list);
}); });
}).allowPublicAcquisition("jio_remove", function(param_list) { }).allowPublicAcquisition("jio_remove", function(param_list) {
if (this.storageType === 0) {
return this.getDeclaredGadget(storageType(this.storageType)).push(function(jio_gadget) { return this.getDeclaredGadget(storageType(this.storageType)).push(function(jio_gadget) {
return jio_gadget.remove.apply(jio_gadget, param_list); return jio_gadget.remove.apply(jio_gadget, param_list);
}); });
}
}).allowPublicAcquisition("jio_removeAttachment", function(param_list) { }).allowPublicAcquisition("jio_removeAttachment", function(param_list) {
if (this.storageType === 0) {
return this.getDeclaredGadget(storageType(this.storageType)).push(function(jio_gadget) { return this.getDeclaredGadget(storageType(this.storageType)).push(function(jio_gadget) {
return jio_gadget.removeAttachment.apply(jio_gadget, param_list); return jio_gadget.removeAttachment.apply(jio_gadget, param_list);
}); });
}
}).allowPublicAcquisition("displayThisTitle", function(param_list) { }).allowPublicAcquisition("displayThisTitle", function(param_list) {
var header = this.__element.getElementsByTagName("h1")[0]; var header = this.__element.getElementsByTagName("h1")[0];
header.innerHTML = param_list[0]; header.innerHTML = param_list[0];
...@@ -171,7 +167,7 @@ ...@@ -171,7 +167,7 @@
gadget.__element.getElementsByClassName("addMusic")[0].style.display = "none"; gadget.__element.getElementsByClassName("addMusic")[0].style.display = "none";
} else if (options.id === "online") { } else if (options.id === "online") {
gadget.storageType = 2; gadget.storageType = 2;
gadget.__element.getElementsByClassName("addMusic")[0].style.display = "none"; gadget.__element.getElementsByClassName("addMusic")[0].style.display = "";
} }
} }
return gadget.declareGadget(gadget_list[options.page][gadget.storageType]).push(function(g) { return gadget.declareGadget(gadget_list[options.page][gadget.storageType]).push(function(g) {
......
...@@ -15,11 +15,17 @@ ...@@ -15,11 +15,17 @@
<li> <li>
{{#compare this.doc.type}} {{#compare this.doc.type}}
<a href=#page=control&id={{this.id}}&action=offline> <a href=#page=control&id={{this.id}}&action=offline>
{{this.doc.title}} <img src={{this.doc.picture}}>
<h3> {{this.doc.title}} </h3>
<P> {{this.doc.artist}} </p>
<P> {{this.doc.album}} </p>
</a> </a>
{{else}} {{else}}
<a href=#page=video_control&id={{this.id}}&action=offline> <a href=#page=video_control&id={{this.id}}&action=offline>
{{this.doc.title}} <img src={{this.doc.picture}}>
<h3> {{this.doc.title}} </h3>
<P> {{this.doc.artist}} </p>
<P> {{this.doc.album}} </p>
</a> </a>
{{/compare}} {{/compare}}
<a href=#page=playlist&id={{this.id}}&action=delete> <a href=#page=playlist&id={{this.id}}&action=delete>
......
...@@ -15,13 +15,23 @@ ...@@ -15,13 +15,23 @@
<li> <li>
{{#compare this.doc.type}} {{#compare this.doc.type}}
<a href=#page=control&id={{this.id}}&action=offline> <a href=#page=control&id={{this.id}}&action=offline>
{{this.doc.title}} <img src={{this.doc.picture}}>
<h3> {{this.doc.title}} </h3>
<P> {{this.doc.artist}} </p>
<P> {{this.doc.album}} </p>
</a> </a>
{{else}} {{else}}
<a href=#page=video_control&id={{this.id}}&action=offline> <a href=#page=video_control&id={{this.id}}&action=offline>
{{this.doc.title}} <img src={{this.doc.picture}}>
<h3> {{this.doc.title}} </h3>
<P> {{this.doc.artist}} </p>
<P> {{this.doc.album}} </p>
</a> </a>
{{/compare}} {{/compare}}
<a href=#page=playlist&id={{this.id}}&action=delete>
data-rel=popup
data-position-to=window
</a>
</li> </li>
{{/each}} {{/each}}
</script> </script>
......
...@@ -18,9 +18,10 @@ ...@@ -18,9 +18,10 @@
return re.test(ip); return re.test(ip);
} }
function check(value) { function check(value) {
var g = this, info = g.__element.getElementsByClassName("info")[0], http, port, portEnd, ipValue = value; var g = this, info = g.__element.getElementsByClassName("info")[0], http, port, portEnd, tmp, ipValue = value;
g.__element.getElementsByTagName("ul")[0].innerHTML = " "; g.__element.getElementsByTagName("ul")[0].innerHTML = " ";
http = ipValue.indexOf("http"); http = ipValue.indexOf("http");
tmp = ipValue.charAt(0);
if (ipValue.indexOf("www.") !== -1) { if (ipValue.indexOf("www.") !== -1) {
if (http === -1) { if (http === -1) {
info.innerHTML = "please start with http:// or https://"; info.innerHTML = "please start with http:// or https://";
...@@ -32,6 +33,8 @@ ...@@ -32,6 +33,8 @@
} }
} else { } else {
ipValue = ipValue.substring(ipValue.indexOf("//") + 2); ipValue = ipValue.substring(ipValue.indexOf("//") + 2);
tmp = ipValue.charAt(0);
if (tmp >= "0" || tmp <= "9") {
port = ipValue.indexOf(":"); port = ipValue.indexOf(":");
portEnd = ipValue.indexOf(":/"); portEnd = ipValue.indexOf(":/");
if (port !== -1) { if (port !== -1) {
...@@ -54,6 +57,7 @@ ...@@ -54,6 +57,7 @@
return; return;
} }
} }
}
return new RSVP.Queue().push(function() { return new RSVP.Queue().push(function() {
return g.plSave({ return g.plSave({
ip: value ip: value
...@@ -67,7 +71,7 @@ ...@@ -67,7 +71,7 @@
window.location = url; window.location = url;
}); });
} }
gk.declareAcquiredMethod("allDocs", "allDocs").declareAcquiredMethod("plSave", "plSave").declareAcquiredMethod("plGive", "plGive").declareAcquiredMethod("displayThisPage", "displayThisPage").declareAcquiredMethod("displayThisTitle", "displayThisTitle").declareAcquiredMethod("plCreateHttpStorage", "plCreateHttpStorage").declareAcquiredMethod("plEnablePage", "plEnablePage").declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash").declareMethod("render", function(options) { gk.declareAcquiredMethod("allDocs", "allDocs").declareAcquiredMethod("plSave", "plSave").declareAcquiredMethod("plGive", "plGive").declareAcquiredMethod("displayThisPage", "displayThisPage").declareAcquiredMethod("displayThisTitle", "displayThisTitle").declareAcquiredMethod("plCreateDavStorage", "plCreateDavStorage").declareAcquiredMethod("plEnablePage", "plEnablePage").declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash").declareMethod("render", function(options) {
var gadget = this, ipValue, ip_context = gadget.__element.getElementsByClassName("inputIp")[0], list = gadget.__element.getElementsByTagName("ul")[0]; var gadget = this, ipValue, ip_context = gadget.__element.getElementsByClassName("inputIp")[0], list = gadget.__element.getElementsByTagName("ul")[0];
return new RSVP.Queue().push(function() { return new RSVP.Queue().push(function() {
return RSVP.all([ gadget.displayThisPage({ return RSVP.all([ gadget.displayThisPage({
...@@ -90,7 +94,7 @@ ...@@ -90,7 +94,7 @@
ipValue = value; ipValue = value;
ip_context.value = value; ip_context.value = value;
if (options.action) { if (options.action) {
return gadget.plCreateHttpStorage(value); return gadget.plCreateDavStorage(value);
} }
} }
}).push(function() { }).push(function() {
......
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<head> <head>
<title>audioplayer io</title> <title>audioplayer io</title>
<!-- renderjs --> <!-- renderjs -->
...@@ -11,6 +12,7 @@ ...@@ -11,6 +12,7 @@
<script src="../lib/uritemplate.min.js" type="text/javascript"></script> <script src="../lib/uritemplate.min.js" type="text/javascript"></script>
<script src="../lib/jio.js" type="text/javascript"></script> <script src="../lib/jio.js" type="text/javascript"></script>
<script src="../mixin_promise/mixin_promise.js" type="text/javascript"></script> <script src="../mixin_promise/mixin_promise.js" type="text/javascript"></script>
<script src="../lib/id3-minimized.js" type="text/javascript"></script>
<!-- custom script --> <!-- custom script -->
<script src="./upload.js" type="text/javascript"></script> <script src="./upload.js" type="text/javascript"></script>
......
/*global window, rJS, RSVP, jIO, JSON, promiseEventListener, console, /*global window, rJS, RSVP, jIO, JSON, promiseEventListener, console,
Math */ Math, ID3, FileAPIReader, dataReader, String, decodeURIComponent, escape */
/*jslint nomen: true*/ /*jslint nomen: true*/
(function(window, jIO, rJS) { (function(window, jIO, rJS) {
"use strict"; "use strict";
var gk = rJS(window); var gk = rJS(window);
function promiseId3(file) {
var resolver;
resolver = function(resolve) {
ID3.loadTags(file.name, function() {
var tags = ID3.getAllTags(file.name);
resolve(tags);
}, {
tags: [ "artist", "title", "album", "year", "comment", "track", "genre", "lyrics", "picture" ],
dataReader: new FileAPIReader(file)
});
};
return new RSVP.Promise(resolver);
}
function unknown(str) {
var ch = str.charAt(0), patrn = /[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/gi;
if (!patrn.exec(str)) {
if (ch < "a" || ch > "z" || ch < "A" || ch > "Z") {
return true;
}
if (ch < "0" || ch > "9") {
return true;
}
}
return false;
}
function exit(g) { function exit(g) {
return RSVP.Queue().push(function() { return RSVP.Queue().push(function() {
return g.plEnablePage(); return g.plEnablePage();
...@@ -15,30 +40,52 @@ ...@@ -15,30 +40,52 @@
window.location = url; window.location = url;
}); });
} }
gk.declareAcquiredMethod("jio_post", "jio_post").declareAcquiredMethod("jio_putAttachment", "jio_putAttachment").declareAcquiredMethod("jio_remove", "jio_remove").declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash").declareAcquiredMethod("displayThisPage", "displayThisPage").declareAcquiredMethod("displayThisTitle", "displayThisTitle").declareAcquiredMethod("plEnablePage", "plEnablePage").declareAcquiredMethod("plDisablePage", "plDisablePage").declareMethod("render", function() { gk.declareAcquiredMethod("jio_post", "jio_post").declareAcquiredMethod("jio_putAttachment", "jio_putAttachment").declareAcquiredMethod("jio_remove", "jio_remove").declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash").declareAcquiredMethod("displayThisPage", "displayThisPage").declareAcquiredMethod("displayThisTitle", "displayThisTitle").declareAcquiredMethod("plEnablePage", "plEnablePage").declareAcquiredMethod("plDisablePage", "plDisablePage").declareAcquiredMethod("plGiveStorageType", "plGiveStorageType").declareMethod("render", function() {
return this.displayThisTitle("upload"); return this.displayThisTitle("upload");
}).declareMethod("startService", function() { }).declareMethod("startService", function() {
var g = this, input_context = g.__element.getElementsByTagName("input")[0], info_context = g.__element.getElementsByClassName("info")[0], queue, uploaded = 0, post, length; var g = this, input_context = g.__element.getElementsByTagName("input")[0], info_context = g.__element.getElementsByClassName("info")[0], queue, uploaded = 0, post, type = 0, length;
info_context.innerHTML = "<ul>"; info_context.innerHTML = "<ul>";
post = function() { post = function() {
var now = new Date(), id; var now = new Date(), id, file;
if (uploaded === length) { if (uploaded === length) {
return; return;
} }
file = input_context.files[uploaded];
return promiseId3(file).then(function(tags) {
var title = tags.title, artist = tags.artist, album = tags.album, year = tags.year, i, image, picture = "./unknown.jpg", base64String;
if (tags.picture) {
image = tags.picture;
base64String = "";
for (i = 0; i < image.data.length; i += 1) {
base64String += String.fromCharCode(image.data[i]);
}
picture = "data:" + image.format + ";base64," + window.btoa(base64String);
}
if (title === undefined || unknown(title)) {
title = file.name;
artist = "unknown";
album = "unknown";
year = "unknown";
}
return g.jio_post({ return g.jio_post({
title: input_context.files[uploaded].name, title: title,
type: input_context.files[uploaded].type, type: file.type,
format: input_context.files[uploaded].type, format: file.type,
size: input_context.files[uploaded].size, size: file.size,
artist: artist,
album: album,
year: year,
picture: picture,
modified: now.toUTCString(), modified: now.toUTCString(),
date: now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate() date: now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate()
}, 0).then(function(res) { }, type);
}).then(function(res) {
id = res.id; id = res.id;
return g.jio_putAttachment({ return g.jio_putAttachment({
_id: res.id, _id: res.id,
_attachment: "enclosure", _attachment: "enclosure",
_blob: input_context.files[uploaded] _blob: input_context.files[uploaded]
}, 0); }, type);
}).then(function() { }).then(function() {
uploaded += 1; uploaded += 1;
info_context.innerHTML += "<li>" + input_context.files[uploaded - 1].name + " " + uploaded + "/" + length + "</li>"; info_context.innerHTML += "<li>" + input_context.files[uploaded - 1].name + " " + uploaded + "/" + length + "</li>";
...@@ -62,6 +109,9 @@ ...@@ -62,6 +109,9 @@
queue.push(function() { queue.push(function() {
return g.plEnablePage(); return g.plEnablePage();
}).push(function() { }).push(function() {
return g.plGiveStorageType();
}).push(function(param) {
type = param;
return promiseEventListener(input_context, "change", false); return promiseEventListener(input_context, "change", false);
}).push(function() { }).push(function() {
return g.plDisablePage(); return g.plDisablePage();
......
...@@ -92,10 +92,42 @@ ...@@ -92,10 +92,42 @@
} }
return RSVP.any([ loopEventListener(g.video, "ended", false, function() { return RSVP.any([ loopEventListener(g.video, "ended", false, function() {
window.location = g.__element.getElementsByClassName("next")[0].href; window.location = g.__element.getElementsByClassName("next")[0].href;
}), loopEventListener(g.video, "seeking", false, function(e) {
g.seeking = true;
console.log(e.target.currentTime);
if (g.mediaSource.readyState === "open") {
g.mediaSource.sourceBuffers[0].abort();
}
if (g.mediaSource.readyState === "closed") {
return;
}
if (g.mediaSource.sourceBuffers[0].updating) {
return;
}
g.index = 35e5;
return g.jio_getAttachment({
_id: g.id,
_attachment: "enclosure",
_start: g.index,
_end: g.index + 35e5
}).then(function(blob) {
g.index += 35e5;
return jIO.util.readBlobAsArrayBuffer(blob);
}).then(function(e) {
g.sourceBuffer.appendBuffer(new Uint8Array(e.target.result));
g.video.play();
g.seeking = false;
});
}), loopEventListener(g.sourceBuffer, "updateend", false, function() { }), loopEventListener(g.sourceBuffer, "updateend", false, function() {
if (!g.fin) { if (!g.fin) {
return; return;
} }
if (g.seeking) {
return;
}
if (g.mediaSource.sourceBuffers[0].updating) {
return;
}
g.fin = false; g.fin = false;
if (g.index >= g.size) { if (g.index >= g.size) {
g.mediaSource.endOfStream(); g.mediaSource.endOfStream();
...@@ -107,11 +139,15 @@ ...@@ -107,11 +139,15 @@
_start: g.index, _start: g.index,
_end: g.index + 35e5 _end: g.index + 35e5
}).then(function(blob) { }).then(function(blob) {
if (g.seeking === false) {
g.index += 35e5; g.index += 35e5;
return jIO.util.readBlobAsArrayBuffer(blob); return jIO.util.readBlobAsArrayBuffer(blob);
}
}).then(function(e) { }).then(function(e) {
g.fin = true; g.fin = true;
if (g.seeking === false) {
return g.sourceBuffer.appendBuffer(new Uint8Array(e.target.result)); return g.sourceBuffer.appendBuffer(new Uint8Array(e.target.result));
}
}); });
}) ]); }) ]);
}).push(function(error) { }).push(function(error) {
...@@ -126,6 +162,7 @@ ...@@ -126,6 +162,7 @@
info.innerHTML = "<ul>\n<li>for a better performence, pleasa enable MediaSource</li>\n<li>1.Type about:config into the web browser's address bar and hit enter.\nConfirm that you will be careful if a warning message is displayed.</li>\n<li>2.search for media.mediasource.enabled and double-click the name.</li>\n</ul>"; info.innerHTML = "<ul>\n<li>for a better performence, pleasa enable MediaSource</li>\n<li>1.Type about:config into the web browser's address bar and hit enter.\nConfirm that you will be careful if a warning message is displayed.</li>\n<li>2.search for media.mediasource.enabled and double-click the name.</li>\n</ul>";
return; return;
} }
g.seeking = false;
g.mediaSource = new MediaSource(); g.mediaSource = new MediaSource();
g.video.src = URL.createObjectURL(g.mediaSource); g.video.src = URL.createObjectURL(g.mediaSource);
}); });
......
This diff is collapsed.
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
var gadget_list = { var gadget_list = {
"upload" : {"0" : "../audioplayer_upload/index.html", "upload" : {"0" : "../audioplayer_upload/index.html",
"1" : "../audioplayer_playlist_local/index.html", "1" : "../audioplayer_playlist_local/index.html",
"2" : "../audioplayer_playlist_online/index.html"}, "2" : "../audioplayer_upload/index.html"},
"playlist" : {"0" : "../audioplayer_playlist_offline/index.html", "playlist" : {"0" : "../audioplayer_playlist_offline/index.html",
"1" : "../audioplayer_playlist_local/index.html", "1" : "../audioplayer_playlist_local/index.html",
"2" : "../audioplayer_playlist_online/index.html"}, "2" : "../audioplayer_playlist_online/index.html"},
...@@ -58,12 +58,12 @@ ...@@ -58,12 +58,12 @@
.allowPublicAcquisition("plDisablePage", function () { .allowPublicAcquisition("plDisablePage", function () {
disablePage(this); disablePage(this);
}) })
.allowPublicAcquisition("plCreateHttpStorage", function (list) { .allowPublicAcquisition("plCreateDavStorage", function (list) {
return this.getDeclaredGadget("online") return this.getDeclaredGadget("online")
.push(function (gadget) { .push(function (gadget) {
return gadget.createJio( return gadget.createJio(
{ "type" : "http", { "type" : "dav",
"database" : list[0]} "url" : list[0]}
); );
}); });
}) })
...@@ -77,7 +77,7 @@ ...@@ -77,7 +77,7 @@
this.save[key[0]] = param_list[0][key[0]]; this.save[key[0]] = param_list[0][key[0]];
}) })
.allowPublicAcquisition("plGiveStorageType", function () { .allowPublicAcquisition("plGiveStorageType", function () {
return storageType(this.storageType); return this.storageType;
}) })
.allowPublicAcquisition("plGive", function (param_list) { .allowPublicAcquisition("plGive", function (param_list) {
if (this.save === undefined) { if (this.save === undefined) {
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
return this.save[param_list[0]]; return this.save[param_list[0]];
}) })
.allowPublicAcquisition("allDocs", function (param_list) { .allowPublicAcquisition("allDocs", function (param_list) {
if (this.storageType !== 0) { if (this.storageType === 1) {
param_list[0].save = true; param_list[0].save = true;
} else { } else {
param_list[0].save = false; param_list[0].save = false;
...@@ -98,8 +98,8 @@ ...@@ -98,8 +98,8 @@
}) })
.allowPublicAcquisition("jio_post", function (param_list) { .allowPublicAcquisition("jio_post", function (param_list) {
var type; var type;
if (param_list[1] === 0) { if (param_list[1] === 0 || param_list[1] === 1) {
type = 0; type = param_list[1];
} else { } else {
type = this.storageType; type = this.storageType;
} }
...@@ -110,8 +110,8 @@ ...@@ -110,8 +110,8 @@
}) })
.allowPublicAcquisition("jio_putAttachment", function (param_list) { .allowPublicAcquisition("jio_putAttachment", function (param_list) {
var type; var type;
if (param_list[1] === 0) { if (param_list[1] === 0 || param_list[1] === 1) {
type = 0; type = param_list[1];
} else { } else {
type = this.storageType; type = this.storageType;
} }
...@@ -133,20 +133,16 @@ ...@@ -133,20 +133,16 @@
}); });
}) })
.allowPublicAcquisition("jio_remove", function (param_list) { .allowPublicAcquisition("jio_remove", function (param_list) {
if (this.storageType === 0) {
return this.getDeclaredGadget(storageType(this.storageType)) return this.getDeclaredGadget(storageType(this.storageType))
.push(function (jio_gadget) { .push(function (jio_gadget) {
return jio_gadget.remove.apply(jio_gadget, param_list); return jio_gadget.remove.apply(jio_gadget, param_list);
}); });
}
}) })
.allowPublicAcquisition("jio_removeAttachment", function (param_list) { .allowPublicAcquisition("jio_removeAttachment", function (param_list) {
if (this.storageType === 0) {
return this.getDeclaredGadget(storageType(this.storageType)) return this.getDeclaredGadget(storageType(this.storageType))
.push(function (jio_gadget) { .push(function (jio_gadget) {
return jio_gadget.removeAttachment.apply(jio_gadget, param_list); return jio_gadget.removeAttachment.apply(jio_gadget, param_list);
}); });
}
}) })
.allowPublicAcquisition("displayThisTitle", function (param_list) { .allowPublicAcquisition("displayThisTitle", function (param_list) {
var header = this.__element.getElementsByTagName("h1")[0]; var header = this.__element.getElementsByTagName("h1")[0];
...@@ -206,7 +202,7 @@ ...@@ -206,7 +202,7 @@
} else if (options.id === "online") { } else if (options.id === "online") {
gadget.storageType = 2; gadget.storageType = 2;
gadget.__element.getElementsByClassName('addMusic')[0]. gadget.__element.getElementsByClassName('addMusic')[0].
style.display = "none"; style.display = "";
} }
} }
return gadget.declareGadget( return gadget.declareGadget(
......
...@@ -15,11 +15,17 @@ ...@@ -15,11 +15,17 @@
<li> <li>
{{#compare this.doc.type}} {{#compare this.doc.type}}
<a href=#page=control&id={{this.id}}&action=offline> <a href=#page=control&id={{this.id}}&action=offline>
{{this.doc.title}} <img src={{this.doc.picture}}>
<h3> {{this.doc.title}} </h3>
<P> {{this.doc.artist}} </p>
<P> {{this.doc.album}} </p>
</a> </a>
{{else}} {{else}}
<a href=#page=video_control&id={{this.id}}&action=offline> <a href=#page=video_control&id={{this.id}}&action=offline>
{{this.doc.title}} <img src={{this.doc.picture}}>
<h3> {{this.doc.title}} </h3>
<P> {{this.doc.artist}} </p>
<P> {{this.doc.album}} </p>
</a> </a>
{{/compare}} {{/compare}}
<a href=#page=playlist&id={{this.id}}&action=delete> <a href=#page=playlist&id={{this.id}}&action=delete>
......
...@@ -15,13 +15,23 @@ ...@@ -15,13 +15,23 @@
<li> <li>
{{#compare this.doc.type}} {{#compare this.doc.type}}
<a href=#page=control&id={{this.id}}&action=offline> <a href=#page=control&id={{this.id}}&action=offline>
{{this.doc.title}} <img src={{this.doc.picture}}>
<h3> {{this.doc.title}} </h3>
<P> {{this.doc.artist}} </p>
<P> {{this.doc.album}} </p>
</a> </a>
{{else}} {{else}}
<a href=#page=video_control&id={{this.id}}&action=offline> <a href=#page=video_control&id={{this.id}}&action=offline>
{{this.doc.title}} <img src={{this.doc.picture}}>
<h3> {{this.doc.title}} </h3>
<P> {{this.doc.artist}} </p>
<P> {{this.doc.album}} </p>
</a> </a>
{{/compare}} {{/compare}}
<a href=#page=playlist&id={{this.id}}&action=delete>
data-rel=popup
data-position-to=window
</a>
</li> </li>
{{/each}} {{/each}}
</script> </script>
......
...@@ -33,9 +33,11 @@ ...@@ -33,9 +33,11 @@
http, http,
port, port,
portEnd, portEnd,
tmp,
ipValue = value; ipValue = value;
g.__element.getElementsByTagName('ul')[0].innerHTML = " "; g.__element.getElementsByTagName('ul')[0].innerHTML = " ";
http = ipValue.indexOf("http"); http = ipValue.indexOf("http");
tmp = ipValue.charAt(0);
if (ipValue.indexOf("www.") !== -1) { if (ipValue.indexOf("www.") !== -1) {
if (http === -1) { if (http === -1) {
info.innerHTML = "please start with http:// or https://"; info.innerHTML = "please start with http:// or https://";
...@@ -47,6 +49,8 @@ ...@@ -47,6 +49,8 @@
} }
} else { } else {
ipValue = ipValue.substring(ipValue.indexOf("//") + 2); ipValue = ipValue.substring(ipValue.indexOf("//") + 2);
tmp = ipValue.charAt(0);
if (tmp >= '0' || tmp <= '9') {
port = ipValue.indexOf(":"); port = ipValue.indexOf(":");
portEnd = ipValue.indexOf(":/"); portEnd = ipValue.indexOf(":/");
if (port !== -1) { if (port !== -1) {
...@@ -70,6 +74,7 @@ ...@@ -70,6 +74,7 @@
return; return;
} }
} }
}
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return g.plSave({"ip": value}); return g.plSave({"ip": value});
...@@ -88,7 +93,7 @@ ...@@ -88,7 +93,7 @@
.declareAcquiredMethod("plGive", "plGive") .declareAcquiredMethod("plGive", "plGive")
.declareAcquiredMethod("displayThisPage", "displayThisPage") .declareAcquiredMethod("displayThisPage", "displayThisPage")
.declareAcquiredMethod("displayThisTitle", "displayThisTitle") .declareAcquiredMethod("displayThisTitle", "displayThisTitle")
.declareAcquiredMethod("plCreateHttpStorage", "plCreateHttpStorage") .declareAcquiredMethod("plCreateDavStorage", "plCreateDavStorage")
.declareAcquiredMethod("plEnablePage", "plEnablePage") .declareAcquiredMethod("plEnablePage", "plEnablePage")
.declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash") .declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash")
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
...@@ -123,7 +128,7 @@ ...@@ -123,7 +128,7 @@
ipValue = value; ipValue = value;
ip_context.value = value; ip_context.value = value;
if (options.action) { if (options.action) {
return gadget.plCreateHttpStorage(value); return gadget.plCreateDavStorage(value);
} }
} }
}) })
......
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<head> <head>
<title>audioplayer io</title> <title>audioplayer io</title>
<!-- renderjs --> <!-- renderjs -->
...@@ -11,6 +12,7 @@ ...@@ -11,6 +12,7 @@
<script src="../<%= copy.uritemplate.relative_dest %>" type="text/javascript"></script> <script src="../<%= copy.uritemplate.relative_dest %>" type="text/javascript"></script>
<script src="../<%= concat.jio.relative_dest %>" type="text/javascript"></script> <script src="../<%= concat.jio.relative_dest %>" type="text/javascript"></script>
<script src="../mixin_promise/mixin_promise.js" type="text/javascript"></script> <script src="../mixin_promise/mixin_promise.js" type="text/javascript"></script>
<script src="../<%= copy.id3.relative_dest %>" type="text/javascript"></script>
<!-- custom script --> <!-- custom script -->
<script src="./upload.js" type="text/javascript"></script> <script src="./upload.js" type="text/javascript"></script>
......
/*global window, rJS, RSVP, jIO, JSON, promiseEventListener, console, /*global window, rJS, RSVP, jIO, JSON, promiseEventListener, console,
Math */ Math, ID3, FileAPIReader, dataReader, String, decodeURIComponent, escape */
/*jslint nomen: true*/ /*jslint nomen: true*/
(function (window, jIO, rJS) { (function (window, jIO, rJS) {
"use strict"; "use strict";
var gk = rJS(window); var gk = rJS(window);
function promiseId3(file) {
var resolver;
resolver = function (resolve) {
ID3.loadTags(file.name, function () {
var tags = ID3.getAllTags(file.name);
resolve(tags);
}, {
tags: ["artist", "title", "album", "year", "comment",
"track", "genre", "lyrics", "picture"],
dataReader: new FileAPIReader(file)
});
};
return new RSVP.Promise(resolver);
}
function unknown(str) {
var ch = str.charAt(0),
patrn = /[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/gi;
if (!patrn.exec(str)) {
if ((ch < 'a' || ch > 'z' || ch < 'A' || ch > 'Z')) {
return true;
}
if (ch < '0' || ch > '9') {
return true;
}
}
return false;
}
function exit(g) { function exit(g) {
return RSVP.Queue() return RSVP.Queue()
.push(function () { .push(function () {
...@@ -25,6 +53,7 @@ ...@@ -25,6 +53,7 @@
.declareAcquiredMethod("displayThisTitle", "displayThisTitle") .declareAcquiredMethod("displayThisTitle", "displayThisTitle")
.declareAcquiredMethod("plEnablePage", "plEnablePage") .declareAcquiredMethod("plEnablePage", "plEnablePage")
.declareAcquiredMethod("plDisablePage", "plDisablePage") .declareAcquiredMethod("plDisablePage", "plDisablePage")
.declareAcquiredMethod("plGiveStorageType", "plGiveStorageType")
.declareMethod("render", function () { .declareMethod("render", function () {
return this.displayThisTitle("upload"); return this.displayThisTitle("upload");
}) })
...@@ -37,29 +66,62 @@ ...@@ -37,29 +66,62 @@
queue, queue,
uploaded = 0, uploaded = 0,
post, post,
type = 0,
length; length;
info_context.innerHTML = "<ul>"; info_context.innerHTML = "<ul>";
post = function () { post = function () {
var now = new Date(), var now = new Date(),
id; id,
file;
if (uploaded === length) { if (uploaded === length) {
return; return;
} }
return g.jio_post({ "title" : input_context.files[uploaded].name, file = input_context.files[uploaded];
"type" : input_context.files[uploaded].type, return promiseId3(file)
"format" : input_context.files[uploaded].type, .then(function (tags) {
"size" : input_context.files[uploaded].size, var title = tags.title,
artist = tags.artist,
album = tags.album,
year = tags.year,
i,
image,
picture = "./unknown.jpg",
base64String;
if (tags.picture) {
image = tags.picture;
base64String = "";
for (i = 0; i < image.data.length; i += 1) {
base64String += String.fromCharCode(image.data[i]);
}
picture = "data:" + image.format +
";base64," + window.btoa(base64String);
}
if (title === undefined || unknown(title)) {
title = file.name;
artist = "unknown";
album = "unknown";
year = "unknown";
}
return g.jio_post({ "title" : title,
"type" : file.type,
"format" : file.type,
"size" : file.size,
"artist" : artist,
"album" : album,
"year" : year,
"picture" : picture,
"modified" : now.toUTCString(), "modified" : now.toUTCString(),
"date" : now.getFullYear() + "-" + "date" : now.getFullYear() + "-" +
(now.getMonth() + 1) + "-" + now.getDate() (now.getMonth() + 1) + "-" + now.getDate()
}, 0) }, type);
})
.then(function (res) { .then(function (res) {
id = res.id; id = res.id;
return g.jio_putAttachment({ return g.jio_putAttachment({
"_id" : res.id, "_id" : res.id,
"_attachment" : "enclosure", "_attachment" : "enclosure",
"_blob": input_context.files[uploaded] "_blob": input_context.files[uploaded]
}, 0); }, type);
}) })
.then(function () { .then(function () {
uploaded += 1; uploaded += 1;
...@@ -84,12 +146,15 @@ ...@@ -84,12 +146,15 @@
JSON.stringify(error); JSON.stringify(error);
}); });
}; };
queue = new RSVP.Queue(); queue = new RSVP.Queue();
queue.push(function () { queue.push(function () {
return g.plEnablePage(); return g.plEnablePage();
}) })
.push(function () { .push(function () {
return g.plGiveStorageType();
})
.push(function (param) {
type = param;
return promiseEventListener(input_context, "change", false); return promiseEventListener(input_context, "change", false);
}) })
.push(function () { .push(function () {
......
...@@ -130,10 +130,43 @@ ...@@ -130,10 +130,43 @@
.getElementsByClassName("next")[0].href; .getElementsByClassName("next")[0].href;
}), }),
loopEventListener(g.video, "seeking", false, function (e) {
g.seeking = true;
console.log(e.target.currentTime);
if (g.mediaSource.readyState === "open") {
g.mediaSource.sourceBuffers[0].abort();
}
if (g.mediaSource.readyState === "closed") {
return;
}
if (g.mediaSource.sourceBuffers[0].updating) {
return;
}
g.index = 3500000;
return g.jio_getAttachment({"_id" : g.id,
"_attachment" : "enclosure",
"_start": g.index,
"_end": g.index + 3500000})
.then(function (blob) {
g.index += 3500000;
return jIO.util.readBlobAsArrayBuffer(blob);
})
.then(function (e) {
g.sourceBuffer.appendBuffer(new Uint8Array(e.target.result));
g.video.play();
g.seeking = false;
});
}),
loopEventListener(g.sourceBuffer, "updateend", false, function () { loopEventListener(g.sourceBuffer, "updateend", false, function () {
if (!g.fin) { if (!g.fin) {
return; return;
} }
if (g.seeking) {
return;
}
if (g.mediaSource.sourceBuffers[0].updating) {
return;
}
g.fin = false; g.fin = false;
if (g.index >= g.size) { if (g.index >= g.size) {
g.mediaSource.endOfStream(); g.mediaSource.endOfStream();
...@@ -144,12 +177,16 @@ ...@@ -144,12 +177,16 @@
"_start": g.index, "_start": g.index,
"_end": g.index + 3500000}) "_end": g.index + 3500000})
.then(function (blob) { .then(function (blob) {
if (g.seeking === false) {
g.index += 3500000; g.index += 3500000;
return jIO.util.readBlobAsArrayBuffer(blob); return jIO.util.readBlobAsArrayBuffer(blob);
}
}) })
.then(function (e) { .then(function (e) {
g.fin = true; g.fin = true;
if (g.seeking === false) {
return g.sourceBuffer.appendBuffer(new Uint8Array(e.target.result)); return g.sourceBuffer.appendBuffer(new Uint8Array(e.target.result));
}
}); });
}) })
]); ]);
...@@ -171,6 +208,7 @@ Confirm that you will be careful if a warning message is displayed.</li> ...@@ -171,6 +208,7 @@ Confirm that you will be careful if a warning message is displayed.</li>
</ul>"; </ul>";
return; return;
} }
g.seeking = false;
g.mediaSource = new MediaSource(); g.mediaSource = new MediaSource();
g.video.src = URL.createObjectURL(g.mediaSource); g.video.src = URL.createObjectURL(g.mediaSource);
}); });
......
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