Commit 62a826ce authored by Xiaowu Zhang's avatar Xiaowu Zhang

add android compatibility

parent a94351dc
...@@ -4,19 +4,17 @@ ...@@ -4,19 +4,17 @@
margin: 30px 0 20px 0; margin: 30px 0 20px 0;
left :-100px; left :-100px;
} }
.title {
position: absolute;
top: 1%;
margin: 30px 0 20px 0;
}
input.notice{ input.notice{
background: black; background: black;
color: white; color: white;
position: absolute;
top: 30px;
} }
.progress_time{ .progress_time{
position: absolute; position: relative;
top: 65%; top: -180px;
margin: 50px 0 20px 0; margin: 50px 0 20px 0;
} }
/*global window, rJS, RSVP, console, $, jQuery, URL, location */ /*global window, rJS, RSVP, console, $, jQuery, URL, location, webkitURL */
/*jslint nomen: true*/ /*jslint nomen: true*/
(function (window, rJS, $, RSVP) { (function (window, rJS, $, RSVP) {
...@@ -24,7 +24,8 @@ ...@@ -24,7 +24,8 @@
initializeFlag = false, initializeFlag = false,
list, list,
titleSave, titleSave,
playlist = []; playlist = {};
function nextId() { function nextId() {
if (totalId <= 0) { if (totalId <= 0) {
return -1; return -1;
...@@ -33,6 +34,19 @@ ...@@ -33,6 +34,19 @@
currentId %= totalId; currentId %= totalId;
return currentId; return currentId;
} }
function orient() {
if (window.orientation === 0 || window.orientation === 180) {
$("body").attr("class", "portrait");
window.orientation = 'portrait';
return;
}
if (window.orientation === 90 || window.orientation === -90) {
$("body").attr("class", "landscape");
window.orientation = 'landscape';
}
}
rJS(window) rJS(window)
.declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash") .declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash")
.allowPublicAcquisition("setCurrentTime", function (value) { .allowPublicAcquisition("setCurrentTime", function (value) {
...@@ -51,23 +65,26 @@ ...@@ -51,23 +65,26 @@
}) })
.allowPublicAcquisition("nextToPlay", function () { .allowPublicAcquisition("nextToPlay", function () {
var id = nextId(), var id = nextId(),
name = playlist[id]; name = playlist.url[id];
control.setSong("http://localhost:8080/" + name)
io.getIO(name).then(function (file) { .then(function () {
control.setSong(URL.createObjectURL(file)).then(function () {
control.playSong(); control.playSong();
title.setMessage(name); title.setMessage(playlist.name[id]);
animation.showAnimation(); animation.showAnimation();
}); });
/* io.getIO(name).then(function (file) {
control.setSong(URL.createObjectURL(file)).then(function () {
control.playSong();
title.setMessage(playlist.name[id]);
animation.showAnimation();
}); });
});*/
}) })
.allowPublicAcquisition("sendPlaylist", function (value) { .allowPublicAcquisition("sendPlaylist", function (value) {
playlist = value[0]; playlist = value[0];
totalId = playlist.length; //array parameter totalId = playlist.url.length; //array parameter
if (initializeFlag === false) {
that.render();
initializeFlag = true; initializeFlag = true;
} that.render();
}) })
.allowPublicAcquisition("sendTotalTime", function (value) { .allowPublicAcquisition("sendTotalTime", function (value) {
time.setMax(value[0]); time.setMax(value[0]);
...@@ -79,7 +96,9 @@ ...@@ -79,7 +96,9 @@
addMusic_context = array[array.length - 2]; addMusic_context = array[array.length - 2];
list_context = array[array.length - 1]; list_context = array[array.length - 1];
that = g; that = g;
initializeFlag = false; window.addEventListener("orientationchange", function (e) {
orient();
});
RSVP.all([ RSVP.all([
g.getDeclaredGadget( g.getDeclaredGadget(
"control" "control"
...@@ -174,12 +193,14 @@ ...@@ -174,12 +193,14 @@
return this.aq_pleasePublishMyState({page: param}); return this.aq_pleasePublishMyState({page: param});
}) })
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var id = nextId(), var id,
name = playlist[id]; name,
urlDemand;
if (initializeFlag === false) { if (initializeFlag === false) {
return; return;
} }
id = nextId();
name = playlist.name[id];
that.showPage(name) that.showPage(name)
.then(function (result) { .then(function (result) {
next_context.href = result; next_context.href = result;
...@@ -235,7 +256,7 @@ ...@@ -235,7 +256,7 @@
return; return;
} }
if (playlist.indexOf(options.page) === -1) { if (playlist.name.indexOf(options.page) === -1) {
animation.stopAnimation(); animation.stopAnimation();
error.display(); error.display();
that.noDisplay(); that.noDisplay();
...@@ -246,14 +267,17 @@ ...@@ -246,14 +267,17 @@
animation.showAnimation(); animation.showAnimation();
return; return;
} }
io.getIO(options.page).then(function (file) { urlDemand = playlist.url[
control.setSong(URL.createObjectURL(file)).then(function () { playlist.name.indexOf(options.page)
];
control.setSong("http://localhost:8080/" +
urlDemand)
.then(function () {
control.playSong(); control.playSong();
title.setMessage(options.page); title.setMessage(options.page);
titleSave = options.page; titleSave = options.page;
animation.showAnimation(); animation.showAnimation();
}); });
});
} else { } else {
error.noDisplay(); error.noDisplay();
list.noDisplay(); list.noDisplay();
......
/*global window, rJS, RSVP, console, URL, Math, /*global window, rJS, RSVP, console, URL, Math,
FileReader, Uint8Array, File */ FileReader, Uint8Array, File, Audio*/
/*jslint nomen: true*/ /*jslint nomen: true*/
(function (window, rJS) { (function (window, rJS) {
"use strict"; "use strict";
var gk = rJS(window); var gk = rJS(window),
arraytmp = [];
gk.declareMethod('setSong', function (url) { //configure a song gk.declareMethod('setSong', function (url) { //configure a song
var gadget = this; var gadget = this;
gadget.source.connect(gadget.analyser); gadget.source.connect(gadget.analyser);
...@@ -13,7 +14,12 @@ ...@@ -13,7 +14,12 @@
gadget.gain.connect(gadget.audioCtx.destination); gadget.gain.connect(gadget.audioCtx.destination);
gadget.audio.src = url; gadget.audio.src = url;
gadget.audio.onloadedmetadata = function () { gadget.audio.onloadedmetadata = function () {
window.setTimeout(
function () {
gadget.sendTotalTime(gadget.audio.duration); gadget.sendTotalTime(gadget.audio.duration);
},
3000
);
}; };
gadget.audio.load(); gadget.audio.load();
}) })
...@@ -47,8 +53,26 @@ ...@@ -47,8 +53,26 @@
.declareMethod('getFFTValue', function () { .declareMethod('getFFTValue', function () {
var gadget = this, var gadget = this,
tmp = {}, tmp = {},
i,
array = new Uint8Array(gadget.analyser.frequencyBinCount); array = new Uint8Array(gadget.analyser.frequencyBinCount);
gadget.analyser.getByteFrequencyData(array); gadget.analyser.getByteFrequencyData(array);
// if fft failed, random value
if (array[0] === 0 && array[50] === 0 && array[100] === 0) {
for (i = 0; i < 1024; i += 1) {
if (Math.floor(Math.random() * 10) > 5) {
arraytmp[i] -= 5;
if (arraytmp[i] < 0) {
arraytmp[i] = 0;
}
} else {
arraytmp[i] += 5;
if (arraytmp[i] > 255) {
arraytmp[i] = 100;
}
}
array[i] = arraytmp[i];
}
}
tmp.array = array; tmp.array = array;
tmp.length = array.length; tmp.length = array.length;
return tmp; return tmp;
...@@ -56,6 +80,7 @@ ...@@ -56,6 +80,7 @@
.declareAcquiredMethod("nextToPlay", "nextToPlay") .declareAcquiredMethod("nextToPlay", "nextToPlay")
.declareAcquiredMethod("sendTotalTime", "sendTotalTime"); .declareAcquiredMethod("sendTotalTime", "sendTotalTime");
gk.ready(function (g) { gk.ready(function (g) {
var i;
g.volume = 1; g.volume = 1;
window.AudioContext = window.AudioContext || window.webkitAudioContext window.AudioContext = window.AudioContext || window.webkitAudioContext
|| window.mozAudiocontext || window.msAudioContext; || window.mozAudiocontext || window.msAudioContext;
...@@ -66,7 +91,11 @@ ...@@ -66,7 +91,11 @@
"ERROR:[control] " + e "ERROR:[control] " + e
); );
} }
g.audio = new window.Audio(); for (i = 0; i < 1024; i += 1) {
arraytmp[i] = Math.floor(Math.random() * 255);
}
g.audio = g.__element.getElementsByTagName('audio')[0];
g.audio.style.display = "none";
g.source = g.audioCtx.createMediaElementSource(g.audio); g.source = g.audioCtx.createMediaElementSource(g.audio);
g.analyser = g.audioCtx.createAnalyser(); g.analyser = g.audioCtx.createAnalyser();
g.gain = g.audioCtx.createGain(); g.gain = g.audioCtx.createGain();
......
...@@ -15,5 +15,8 @@ ...@@ -15,5 +15,8 @@
<script src="./control.js" type="text/javascript"></script> <script src="./control.js" type="text/javascript"></script>
</head> </head>
<body> <body>
<audio controls>
<type="audio/mpeg">
</audio>
</body> </body>
</html> </html>
/*global window, rJS, RSVP, jIO, JSON, console, indexedDB, Components */
/*jslint nomen: true*/
(function (window, jIO, rJS) {
"use strict";
var gk = rJS(window),
input_context;
gk.declareMethod('createIO', function (description, key) {
this.jio = jIO.createJIO(description);
})
.declareMethod('getIO', function (attachment) {
var gadget = this;
return gadget.jio.getAttachment({
"_id": attachment
}).then(function (response) {
return response.data;
}).fail(function (response) {
return "jio getIO error : " + response.target.result;
});
})
.declareMethod('removeIO', function (attachment) {
var gadget = this,
index;
index = gadget.playlist.name.indexOf(attachment);
gadget.playlist.url.splice(index, 1);
gadget.playlist.name.splice(index, 1);
gadget.sendPlaylist(gadget.playlist);
})
.declareMethod('display', function (attachment) {
input_context.style.display = "";
})
.declareMethod('noDisplay', function (attachment) {
input_context.style.display = "none";
})
.declareMethod('showAllIO', function () {
var gadget = this;
return gadget.jio.allDocs().then(function (result) {
return result.data.rows[0];
}).fail(function (error) {
return "ERROR : " + error;
});
})
.declareAcquiredMethod("sendPlaylist", "sendPlaylist");
gk.ready(function (g) {
var index,
url,
name,
urlArray = [],
nameArray = [];
input_context = g.__element.getElementsByTagName('input')[0];
input_context.style.display = "none";
g.playlist = {};
g.createIO({ "type" : "http",
"database": "http://localhost:8080/"})
.then(function () {
g.showAllIO().then(function (result) {
while (result) {
index = result.indexOf("href=\"/");
if (index === -1) {
break;
}
result = result.substring(index + 7);
index = result.indexOf("\">");
url = result.substring(0, index);
if (url.indexOf(".mp3") === -1) {
result = result.substring(index + 2);
} else {
urlArray.push(url);
result = result.substring(index + 2);
index = result.indexOf("</a>");
name = result.substring(0, index);
nameArray.push(name);
}
}
g.playlist.url = urlArray;
g.playlist.name = nameArray;
g.sendPlaylist(g.playlist);
});
});
});
}(window, jIO, rJS));
...@@ -13,13 +13,13 @@ ...@@ -13,13 +13,13 @@
<!-- custom script --> <!-- custom script -->
<script src="./io.js" type="text/javascript"></script> <script src="./http.js" type="text/javascript"></script>
</head> </head>
<body> <body>
<input type = "file" multiple /> <input type = "file" webkitdirectory />
</body> </body>
</html> </html>
/*global window, rJS, RSVP, jIO, JSON, console, indexedDB */ /*global window, rJS, RSVP, jIO, JSON, console, indexedDB, Components */
/*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),
input_context; input_context;
// Components.utils.import("resource://gre/modules/FileUtils.jsm");
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);
......
...@@ -13,21 +13,21 @@ ...@@ -13,21 +13,21 @@
this.playlist.style.display = "none"; this.playlist.style.display = "none";
this.home.style.display = "none"; this.home.style.display = "none";
}) })
.declareMethod('initList', function (array) { .declareMethod('initList', function (playlist) {
var i, var i,
docFragment = document.createDocumentFragment(), docFragment = document.createDocumentFragment(),
li; li;
this.list.innerHTML = ""; this.list.innerHTML = "";
for (i = 0; i < array.length; i += 1) { for (i = 0; i < playlist.url.length; i += 1) {
li = document.createElement("li"); li = document.createElement("li");
li.innerHTML = li.innerHTML =
"<a href=#page=" "<a href=#page="
+ array[i] + playlist.url[i]
+ ">" + ">"
+ array[i] + playlist.name[i]
+ "</a> " + "</a> "
+ " <a href=#page=" + " <a href=#page="
+ array[i] + playlist.name[i]
+ "&id=delete " + "&id=delete "
+ "data-rel=popup " + "data-rel=popup "
+ "data-position-to=window " + "data-position-to=window "
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
<div class="time" style="position:absolute;"> <div class="time" style="position:absolute;">
</div> </div>
<progress class="pro"> <progress class="pro" style="width: 100%;">
</progress> </progress>
......
progress.pro { progress.pro {
position: absolute;
display: block;
height: 25px; height: 25px;
padding: 5px; padding: 5px;
width:100%;
margin: 50px 0 20px 0; margin: 50px 0 20px 0;
-moz-border-radius: 5px; -moz-border-radius: 5px;
-webkit-border-radius: 5px; -webkit-border-radius: 5px;
......
...@@ -58,7 +58,6 @@ ...@@ -58,7 +58,6 @@
g.time = g.__element.getElementsByTagName('div')[1]; g.time = g.__element.getElementsByTagName('div')[1];
g.bar.value = 0; g.bar.value = 0;
g.bar.max = 1000; g.bar.max = 1000;
g.bar.style.width = window.screen.availWidth + "px";
g.time.style.left = g.bar.style.left; g.time.style.left = g.bar.style.left;
$(g.time).offset().top = $(g.bar).offset().top + 5; $(g.time).offset().top = $(g.bar).offset().top + 5;
g.time.innerHTML = "--"; g.time.innerHTML = "--";
......
...@@ -15,6 +15,6 @@ ...@@ -15,6 +15,6 @@
<body> <body>
<input type="text" class="notice" size="150"> <input type="text" class="notice" size="150" style="width: 100%;">
</body> </body>
</html> </html>
...@@ -44,7 +44,6 @@ ...@@ -44,7 +44,6 @@
gk.ready(function (g) { gk.ready(function (g) {
g.scroll = new BannerObject(); g.scroll = new BannerObject();
g.input = g.__element.getElementsByTagName('input')[0]; g.input = g.__element.getElementsByTagName('input')[0];
g.input.style.width = window.screen.availWidth + "px";
g.scroll.size = g.input.size; g.scroll.size = g.input.size;
function scroller() { function scroller() {
g.scroll.out += " "; g.scroll.out += " ";
......
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