Commit 1ef1d213 authored by Xiaowu Zhang's avatar Xiaowu Zhang

complete audioplayer

parent 0a294037
/*global window, rJS, RSVP, console */
/*global window, rJS, RSVP, console, $, jQuery */
/*jslint nomen: true*/
(function (window, rJS) {
(function (window, rJS, $) {
"use strict";
function AnimationClass(control) {
this.canvas = null;
......@@ -86,9 +86,6 @@
),
g.getDeclaredGadget(
"title"
),
g.getDeclaredGadget(
"log"
)
])
.then(function (all_param) {
......@@ -97,15 +94,65 @@
time = all_param[2],
volume = all_param[3],
title = all_param[4],
log = all_param[5],
animationObject = new AnimationClass(control);
window.setInterval(function () { //double click to play
control.getCurrentTime()
.then(function (e) {
time.setValue(e);
});
}, 1000);
volume.setMax(3);
function nextToPlay() {
g.currentPlayId = Math.floor(Math.random()
* g.playlist.length);
control.setSong(g.playlist[g.currentPlayId]);
control.playSong();
animation.showAnimation();
title.setMessage(g.playlist[g.currentPlayId].name);
control.getTotalTime()
.then(function (e) {
time.setMax(e);
});
}
input_context.onchange = function () {
var tmp;
for (tmp = 0; tmp < input_context.files.length; tmp += 1) {
g.playlist.push(input_context.files[tmp]);
var tmp,
index,
found;
for (index = 0; index < input_context.files.length; index += 1) {
found = false;
for (tmp = 0; tmp < g.playlist.length; tmp += 1) {
if (g.playlist[tmp].name === input_context.files[index].name) {
found = true;
break;
}
}
if (found === false) {
g.playlist.push(input_context.files[index]);
}
}
};
//time configure
time.setAction('onclick', function (e) {
time.getPositionValue(e).
then(function (value) {
control.setCurrentTime(value);
time.setValue(value);
});
});
//volume configure
volume.setMax(3);
volume.setAction('onclick', function (e) {
volume.getPositionValue(e).
then(function (value) {
volume.setValue(value);
control.setVolume(value);
});
});
//control configure
control.onended(nextToPlay);
//animation configure
animation.setAnimation(animationObject);
animation.setAction('onclick', function () {
control.isPaused()
......@@ -117,28 +164,10 @@
}
});
});
animation.setAction('ondblclick', function () {
g.currentPlayId = Math.floor(Math.random()
* g.playlist.length);
control.setSong(g.playlist[g.currentPlayId]);
control.playSong();
animation.showAnimation();
title.setMessage(g.playlist[g.currentPlayId].name);
window.setInterval(function () { //double click to play
control.getCurrentTime()
.then(function (e) {
time.setValue(e);
});
}, 1000);
control.getTotalTime()
.then(function (e) {
time.setMax(e);
});
});
log.showMessage(volume);
animation.setAction('ondblclick', nextToPlay);
})
.fail(function (e) {
console.log("[ERROR]: " + e);
});
});
}(window, rJS));
}(window, rJS, jQuery));
......@@ -7,6 +7,7 @@
<!-- renderjs -->
<script src="../<%= copy.rsvp.relative_dest %>" type="text/javascript"></script>
<script src="../<%= copy.renderjs.relative_dest %>" type="text/javascript"></script>
<script src="../<%= curl.jquery.relative_dest %>" type="text/javascript"></script>
<!-- custom script -->
<script src="./audioplayer.js" type="text/javascript"></script>
......@@ -36,9 +37,6 @@
<div class = "title" data-gadget-url= "../audioplayer_title/index.html" data-gadget-scope= "title" >
</div>
<div class = "logmessgae" data-gadget-url= "../audioplayer_log_message/index.html" data-gadget-scope= "log" >
</div>
</body>
</html>
/*global window, rJS, RSVP, console, document, JSON, Uint8Array */
/*jslint maxlen:80, nomen: true */
/*jslint nomen: true */
(function (window, rJS) {
......@@ -16,10 +16,10 @@
.declareMethod('stopAnimation', function () {
this.animation.stop();
})
.declareMethod('setAction', function (type, Action) {
.declareMethod('setAction', function (type, action) {
var that = this;
that.canvas[type] = function () {
Action.call(that);
action.call(that);
that.showAnimation();
};
});
......
......@@ -34,13 +34,5 @@
gk.ready(function (g) {
g.log = g.__element.getElementsByTagName('div')[0];
var node = document.createElement("pre");
node.setAttribute(
"style",
"background-color:" + logGetColor() +
";margin:0;padding:0;"
);
node.textContent = "use for show message";
g.log.appendChild(node);
});
}(window, rJS));
......@@ -7,7 +7,7 @@
var gk = rJS(window),
scroll;
function BannerObject() {
this.msg = "it's a test";
this.msg = " ";
this.out = " ";
this.Position = 50;
this.pos = this.Position;
......
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