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

add artist&album&cover support

parent 737caf7a
......@@ -10,7 +10,7 @@
upload: {
"0": "../audioplayer_upload/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",
......@@ -56,11 +56,11 @@
}
}).allowPublicAcquisition("plDisablePage", function() {
disablePage(this);
}).allowPublicAcquisition("plCreateHttpStorage", function(list) {
}).allowPublicAcquisition("plCreateDavStorage", function(list) {
return this.getDeclaredGadget("online").push(function(gadget) {
return gadget.createJio({
type: "http",
database: list[0]
type: "dav",
url: list[0]
});
});
}).allowPublicAcquisition("displayThisPage", function(param_list) {
......@@ -71,14 +71,14 @@
var key = Object.keys(param_list[0]);
this.save[key[0]] = param_list[0][key[0]];
}).allowPublicAcquisition("plGiveStorageType", function() {
return storageType(this.storageType);
return this.storageType;
}).allowPublicAcquisition("plGive", function(param_list) {
if (this.save === undefined) {
return this.save;
}
return this.save[param_list[0]];
}).allowPublicAcquisition("allDocs", function(param_list) {
if (this.storageType !== 0) {
if (this.storageType === 1) {
param_list[0].save = true;
} else {
param_list[0].save = false;
......@@ -88,8 +88,8 @@
});
}).allowPublicAcquisition("jio_post", function(param_list) {
var type;
if (param_list[1] === 0) {
type = 0;
if (param_list[1] === 0 || param_list[1] === 1) {
type = param_list[1];
} else {
type = this.storageType;
}
......@@ -98,8 +98,8 @@
});
}).allowPublicAcquisition("jio_putAttachment", function(param_list) {
var type;
if (param_list[1] === 0) {
type = 0;
if (param_list[1] === 0 || param_list[1] === 1) {
type = param_list[1];
} else {
type = this.storageType;
}
......@@ -115,17 +115,13 @@
return jio_gadget.get.apply(jio_gadget, param_list);
});
}).allowPublicAcquisition("jio_remove", function(param_list) {
if (this.storageType === 0) {
return this.getDeclaredGadget(storageType(this.storageType)).push(function(jio_gadget) {
return jio_gadget.remove.apply(jio_gadget, param_list);
});
}
return this.getDeclaredGadget(storageType(this.storageType)).push(function(jio_gadget) {
return jio_gadget.remove.apply(jio_gadget, param_list);
});
}).allowPublicAcquisition("jio_removeAttachment", function(param_list) {
if (this.storageType === 0) {
return this.getDeclaredGadget(storageType(this.storageType)).push(function(jio_gadget) {
return jio_gadget.removeAttachment.apply(jio_gadget, param_list);
});
}
return this.getDeclaredGadget(storageType(this.storageType)).push(function(jio_gadget) {
return jio_gadget.removeAttachment.apply(jio_gadget, param_list);
});
}).allowPublicAcquisition("displayThisTitle", function(param_list) {
var header = this.__element.getElementsByTagName("h1")[0];
header.innerHTML = param_list[0];
......@@ -171,7 +167,7 @@
gadget.__element.getElementsByClassName("addMusic")[0].style.display = "none";
} else if (options.id === "online") {
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) {
......
......@@ -15,11 +15,17 @@
<li>
{{#compare this.doc.type}}
<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>
{{else}}
<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>
{{/compare}}
<a href=#page=playlist&id={{this.id}}&action=delete>
......
......@@ -15,13 +15,23 @@
<li>
{{#compare this.doc.type}}
<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>
{{else}}
<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>
{{/compare}}
<a href=#page=playlist&id={{this.id}}&action=delete>
data-rel=popup
data-position-to=window
</a>
</li>
{{/each}}
</script>
......
......@@ -18,9 +18,10 @@
return re.test(ip);
}
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 = " ";
http = ipValue.indexOf("http");
tmp = ipValue.charAt(0);
if (ipValue.indexOf("www.") !== -1) {
if (http === -1) {
info.innerHTML = "please start with http:// or https://";
......@@ -32,26 +33,29 @@
}
} else {
ipValue = ipValue.substring(ipValue.indexOf("//") + 2);
port = ipValue.indexOf(":");
portEnd = ipValue.indexOf(":/");
if (port !== -1) {
ipValue = ipValue.substring(0, port);
}
if (http === -1) {
info.innerHTML = "please start ip with http:// or https://";
return;
}
if (port === -1 || portEnd !== -1) {
info.innerHTML = "input port number";
return;
}
if (checkIp(ipValue) === false) {
info.innerHTML = "invalide ip: ip should like xxx.xxx.xxx.xxx(xxx is between 0 ~ 255)";
return;
}
if (!endWith(value, "/")) {
info.innerHTML = "not end with /";
return;
tmp = ipValue.charAt(0);
if (tmp >= "0" || tmp <= "9") {
port = ipValue.indexOf(":");
portEnd = ipValue.indexOf(":/");
if (port !== -1) {
ipValue = ipValue.substring(0, port);
}
if (http === -1) {
info.innerHTML = "please start ip with http:// or https://";
return;
}
if (port === -1 || portEnd !== -1) {
info.innerHTML = "input port number";
return;
}
if (checkIp(ipValue) === false) {
info.innerHTML = "invalide ip: ip should like xxx.xxx.xxx.xxx(xxx is between 0 ~ 255)";
return;
}
if (!endWith(value, "/")) {
info.innerHTML = "not end with /";
return;
}
}
}
return new RSVP.Queue().push(function() {
......@@ -67,7 +71,7 @@
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];
return new RSVP.Queue().push(function() {
return RSVP.all([ gadget.displayThisPage({
......@@ -90,7 +94,7 @@
ipValue = value;
ip_context.value = value;
if (options.action) {
return gadget.plCreateHttpStorage(value);
return gadget.plCreateDavStorage(value);
}
}
}).push(function() {
......
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<head>
<title>audioplayer io</title>
<!-- renderjs -->
......@@ -11,7 +12,8 @@
<script src="../lib/uritemplate.min.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="../lib/id3-minimized.js" type="text/javascript"></script>
<!-- custom script -->
<script src="./upload.js" type="text/javascript"></script>
......
/*global window, rJS, RSVP, jIO, JSON, promiseEventListener, console,
Math */
Math, ID3, FileAPIReader, dataReader, String, decodeURIComponent, escape */
/*jslint nomen: true*/
(function(window, jIO, rJS) {
"use strict";
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) {
return RSVP.Queue().push(function() {
return g.plEnablePage();
......@@ -15,30 +40,52 @@
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");
}).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>";
post = function() {
var now = new Date(), id;
var now = new Date(), id, file;
if (uploaded === length) {
return;
}
return g.jio_post({
title: input_context.files[uploaded].name,
type: input_context.files[uploaded].type,
format: input_context.files[uploaded].type,
size: input_context.files[uploaded].size,
modified: now.toUTCString(),
date: now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate()
}, 0).then(function(res) {
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({
title: title,
type: file.type,
format: file.type,
size: file.size,
artist: artist,
album: album,
year: year,
picture: picture,
modified: now.toUTCString(),
date: now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate()
}, type);
}).then(function(res) {
id = res.id;
return g.jio_putAttachment({
_id: res.id,
_attachment: "enclosure",
_blob: input_context.files[uploaded]
}, 0);
}, type);
}).then(function() {
uploaded += 1;
info_context.innerHTML += "<li>" + input_context.files[uploaded - 1].name + " " + uploaded + "/" + length + "</li>";
......@@ -62,6 +109,9 @@
queue.push(function() {
return g.plEnablePage();
}).push(function() {
return g.plGiveStorageType();
}).push(function(param) {
type = param;
return promiseEventListener(input_context, "change", false);
}).push(function() {
return g.plDisablePage();
......
......@@ -92,10 +92,42 @@
}
return RSVP.any([ loopEventListener(g.video, "ended", false, function() {
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() {
if (!g.fin) {
return;
}
if (g.seeking) {
return;
}
if (g.mediaSource.sourceBuffers[0].updating) {
return;
}
g.fin = false;
if (g.index >= g.size) {
g.mediaSource.endOfStream();
......@@ -107,11 +139,15 @@
_start: g.index,
_end: g.index + 35e5
}).then(function(blob) {
g.index += 35e5;
return jIO.util.readBlobAsArrayBuffer(blob);
if (g.seeking === false) {
g.index += 35e5;
return jIO.util.readBlobAsArrayBuffer(blob);
}
}).then(function(e) {
g.fin = true;
return g.sourceBuffer.appendBuffer(new Uint8Array(e.target.result));
if (g.seeking === false) {
return g.sourceBuffer.appendBuffer(new Uint8Array(e.target.result));
}
});
}) ]);
}).push(function(error) {
......@@ -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>";
return;
}
g.seeking = false;
g.mediaSource = new MediaSource();
g.video.src = URL.createObjectURL(g.mediaSource);
});
......
This diff is collapsed.
......@@ -9,7 +9,7 @@
var gadget_list = {
"upload" : {"0" : "../audioplayer_upload/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",
"1" : "../audioplayer_playlist_local/index.html",
"2" : "../audioplayer_playlist_online/index.html"},
......@@ -58,12 +58,12 @@
.allowPublicAcquisition("plDisablePage", function () {
disablePage(this);
})
.allowPublicAcquisition("plCreateHttpStorage", function (list) {
.allowPublicAcquisition("plCreateDavStorage", function (list) {
return this.getDeclaredGadget("online")
.push(function (gadget) {
return gadget.createJio(
{ "type" : "http",
"database" : list[0]}
{ "type" : "dav",
"url" : list[0]}
);
});
})
......@@ -77,7 +77,7 @@
this.save[key[0]] = param_list[0][key[0]];
})
.allowPublicAcquisition("plGiveStorageType", function () {
return storageType(this.storageType);
return this.storageType;
})
.allowPublicAcquisition("plGive", function (param_list) {
if (this.save === undefined) {
......@@ -86,7 +86,7 @@
return this.save[param_list[0]];
})
.allowPublicAcquisition("allDocs", function (param_list) {
if (this.storageType !== 0) {
if (this.storageType === 1) {
param_list[0].save = true;
} else {
param_list[0].save = false;
......@@ -98,8 +98,8 @@
})
.allowPublicAcquisition("jio_post", function (param_list) {
var type;
if (param_list[1] === 0) {
type = 0;
if (param_list[1] === 0 || param_list[1] === 1) {
type = param_list[1];
} else {
type = this.storageType;
}
......@@ -110,8 +110,8 @@
})
.allowPublicAcquisition("jio_putAttachment", function (param_list) {
var type;
if (param_list[1] === 0) {
type = 0;
if (param_list[1] === 0 || param_list[1] === 1) {
type = param_list[1];
} else {
type = this.storageType;
}
......@@ -133,20 +133,16 @@
});
})
.allowPublicAcquisition("jio_remove", function (param_list) {
if (this.storageType === 0) {
return this.getDeclaredGadget(storageType(this.storageType))
.push(function (jio_gadget) {
return jio_gadget.remove.apply(jio_gadget, param_list);
});
}
return this.getDeclaredGadget(storageType(this.storageType))
.push(function (jio_gadget) {
return jio_gadget.remove.apply(jio_gadget, param_list);
});
})
.allowPublicAcquisition("jio_removeAttachment", function (param_list) {
if (this.storageType === 0) {
return this.getDeclaredGadget(storageType(this.storageType))
.push(function (jio_gadget) {
return jio_gadget.removeAttachment.apply(jio_gadget, param_list);
});
}
return this.getDeclaredGadget(storageType(this.storageType))
.push(function (jio_gadget) {
return jio_gadget.removeAttachment.apply(jio_gadget, param_list);
});
})
.allowPublicAcquisition("displayThisTitle", function (param_list) {
var header = this.__element.getElementsByTagName("h1")[0];
......@@ -206,7 +202,7 @@
} else if (options.id === "online") {
gadget.storageType = 2;
gadget.__element.getElementsByClassName('addMusic')[0].
style.display = "none";
style.display = "";
}
}
return gadget.declareGadget(
......
......@@ -15,11 +15,17 @@
<li>
{{#compare this.doc.type}}
<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>
{{else}}
<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>
{{/compare}}
<a href=#page=playlist&id={{this.id}}&action=delete>
......
......@@ -15,13 +15,23 @@
<li>
{{#compare this.doc.type}}
<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>
{{else}}
<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>
{{/compare}}
<a href=#page=playlist&id={{this.id}}&action=delete>
data-rel=popup
data-position-to=window
</a>
</li>
{{/each}}
</script>
......
......@@ -33,9 +33,11 @@
http,
port,
portEnd,
tmp,
ipValue = value;
g.__element.getElementsByTagName('ul')[0].innerHTML = " ";
http = ipValue.indexOf("http");
tmp = ipValue.charAt(0);
if (ipValue.indexOf("www.") !== -1) {
if (http === -1) {
info.innerHTML = "please start with http:// or https://";
......@@ -47,27 +49,30 @@
}
} else {
ipValue = ipValue.substring(ipValue.indexOf("//") + 2);
port = ipValue.indexOf(":");
portEnd = ipValue.indexOf(":/");
if (port !== -1) {
ipValue = ipValue.substring(0, port);
}
if (http === -1) {
info.innerHTML = "please start ip with http:// or https://";
return;
}
if (port === -1 || portEnd !== -1) {
info.innerHTML = "input port number";
return;
}
if (checkIp(ipValue) === false) {
info.innerHTML =
"invalide ip: ip should like xxx.xxx.xxx.xxx(xxx is between 0 ~ 255)";
return;
}
if (!endWith(value, "/")) {
info.innerHTML = "not end with /";
return;
tmp = ipValue.charAt(0);
if (tmp >= '0' || tmp <= '9') {
port = ipValue.indexOf(":");
portEnd = ipValue.indexOf(":/");
if (port !== -1) {
ipValue = ipValue.substring(0, port);
}
if (http === -1) {
info.innerHTML = "please start ip with http:// or https://";
return;
}
if (port === -1 || portEnd !== -1) {
info.innerHTML = "input port number";
return;
}
if (checkIp(ipValue) === false) {
info.innerHTML =
"invalide ip: ip should like xxx.xxx.xxx.xxx(xxx is between 0 ~ 255)";
return;
}
if (!endWith(value, "/")) {
info.innerHTML = "not end with /";
return;
}
}
}
return new RSVP.Queue()
......@@ -88,7 +93,7 @@
.declareAcquiredMethod("plGive", "plGive")
.declareAcquiredMethod("displayThisPage", "displayThisPage")
.declareAcquiredMethod("displayThisTitle", "displayThisTitle")
.declareAcquiredMethod("plCreateHttpStorage", "plCreateHttpStorage")
.declareAcquiredMethod("plCreateDavStorage", "plCreateDavStorage")
.declareAcquiredMethod("plEnablePage", "plEnablePage")
.declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash")
.declareMethod('render', function (options) {
......@@ -123,7 +128,7 @@
ipValue = value;
ip_context.value = value;
if (options.action) {
return gadget.plCreateHttpStorage(value);
return gadget.plCreateDavStorage(value);
}
}
})
......
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<head>
<title>audioplayer io</title>
<!-- renderjs -->
......@@ -11,7 +12,8 @@
<script src="../<%= copy.uritemplate.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="../<%= copy.id3.relative_dest %>" type="text/javascript"></script>
<!-- custom script -->
<script src="./upload.js" type="text/javascript"></script>
......
/*global window, rJS, RSVP, jIO, JSON, promiseEventListener, console,
Math */
Math, ID3, FileAPIReader, dataReader, String, decodeURIComponent, escape */
/*jslint nomen: true*/
(function (window, jIO, rJS) {
"use strict";
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) {
return RSVP.Queue()
.push(function () {
......@@ -25,6 +53,7 @@
.declareAcquiredMethod("displayThisTitle", "displayThisTitle")
.declareAcquiredMethod("plEnablePage", "plEnablePage")
.declareAcquiredMethod("plDisablePage", "plDisablePage")
.declareAcquiredMethod("plGiveStorageType", "plGiveStorageType")
.declareMethod("render", function () {
return this.displayThisTitle("upload");
})
......@@ -37,29 +66,62 @@
queue,
uploaded = 0,
post,
type = 0,
length;
info_context.innerHTML = "<ul>";
post = function () {
var now = new Date(),
id;
id,
file;
if (uploaded === length) {
return;
}
return g.jio_post({ "title" : input_context.files[uploaded].name,
"type" : input_context.files[uploaded].type,
"format" : input_context.files[uploaded].type,
"size" : input_context.files[uploaded].size,
"modified" : now.toUTCString(),
"date" : now.getFullYear() + "-" +
(now.getMonth() + 1) + "-" + now.getDate()
}, 0)
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({ "title" : title,
"type" : file.type,
"format" : file.type,
"size" : file.size,
"artist" : artist,
"album" : album,
"year" : year,
"picture" : picture,
"modified" : now.toUTCString(),
"date" : now.getFullYear() + "-" +
(now.getMonth() + 1) + "-" + now.getDate()
}, type);
})
.then(function (res) {
id = res.id;
return g.jio_putAttachment({
"_id" : res.id,
"_attachment" : "enclosure",
"_blob": input_context.files[uploaded]
}, 0);
}, type);
})
.then(function () {
uploaded += 1;
......@@ -84,12 +146,15 @@
JSON.stringify(error);
});
};
queue = new RSVP.Queue();
queue.push(function () {
return g.plEnablePage();
})
.push(function () {
return g.plGiveStorageType();
})
.push(function (param) {
type = param;
return promiseEventListener(input_context, "change", false);
})
.push(function () {
......
......@@ -130,10 +130,43 @@
.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 () {
if (!g.fin) {
return;
}
if (g.seeking) {
return;
}
if (g.mediaSource.sourceBuffers[0].updating) {
return;
}
g.fin = false;
if (g.index >= g.size) {
g.mediaSource.endOfStream();
......@@ -144,12 +177,16 @@
"_start": g.index,
"_end": g.index + 3500000})
.then(function (blob) {
g.index += 3500000;
return jIO.util.readBlobAsArrayBuffer(blob);
if (g.seeking === false) {
g.index += 3500000;
return jIO.util.readBlobAsArrayBuffer(blob);
}
})
.then(function (e) {
g.fin = true;
return g.sourceBuffer.appendBuffer(new Uint8Array(e.target.result));
if (g.seeking === false) {
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>
</ul>";
return;
}
g.seeking = false;
g.mediaSource = new 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