Commit dc4e3bc8 authored by Xiaowu Zhang's avatar Xiaowu Zhang

add time show in playlist

parent aa39dcf4
...@@ -118,6 +118,10 @@ ...@@ -118,6 +118,10 @@
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_put", function(param_list) {
return this.getDeclaredGadget(storageType(this.storageType)).push(function(jio_gadget) {
return jio_gadget.put.apply(jio_gadget, param_list);
});
}).allowPublicAcquisition("jio_removeAttachment", function(param_list) { }).allowPublicAcquisition("jio_removeAttachment", function(param_list) {
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);
......
...@@ -40,14 +40,6 @@ ...@@ -40,14 +40,6 @@
} }
return new RSVP.Promise(itsANonResolvableTrap, canceller); return new RSVP.Promise(itsANonResolvableTrap, canceller);
}; };
function set() {
//configure a song
var gadget = this;
gadget.source.connect(gadget.filter);
gadget.filter.connect(gadget.analyser);
gadget.analyser.connect(gadget.gain);
gadget.gain.connect(audioCtx.destination);
}
function timeFormat(seconds) { function timeFormat(seconds) {
var result = "00:" + Math.round(seconds), min, sec; var result = "00:" + Math.round(seconds), min, sec;
if (seconds > 59) { if (seconds > 59) {
...@@ -57,6 +49,14 @@ ...@@ -57,6 +49,14 @@
} }
return result; return result;
} }
function set() {
//configure a song
var gadget = this;
gadget.source.connect(gadget.filter);
gadget.filter.connect(gadget.analyser);
gadget.analyser.connect(gadget.gain);
gadget.gain.connect(audioCtx.destination);
}
function getTime(context, x) { function getTime(context, x) {
var posX = x, targetLeft = $(context).offset().left; var posX = x, targetLeft = $(context).offset().left;
posX = (posX - targetLeft) / $(context).width(); posX = (posX - targetLeft) / $(context).width();
...@@ -102,9 +102,9 @@ ...@@ -102,9 +102,9 @@
canvasCtx.clearRect(0, 0, cwidth, cheight); canvasCtx.clearRect(0, 0, cwidth, cheight);
step = Math.round(array.length / meterNum); step = Math.round(array.length / meterNum);
bar_context.value = that.audio.currentTime; bar_context.value = that.audio.currentTime;
if (isFinite(that.audio.duration)) { /* if (isFinite(that.audio.duration)) {
bar_context.max = that.audio.duration; bar_context.max = that.audio.duration;
} }*/
time_context.innerHTML = timeFormat(that.audio.duration - that.audio.currentTime); time_context.innerHTML = timeFormat(that.audio.duration - that.audio.currentTime);
for (i = 0; i < meterNum; i += 1) { for (i = 0; i < meterNum; i += 1) {
value = array[i * step]; value = array[i * step];
...@@ -114,7 +114,7 @@ ...@@ -114,7 +114,7 @@
}; };
return promiseRequestAnimation(drawFrame); return promiseRequestAnimation(drawFrame);
} }
gk.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment").declareAcquiredMethod("jio_get", "jio_get").declareAcquiredMethod("jio_remove", "jio_remove").declareAcquiredMethod("plSave", "plSave").declareAcquiredMethod("plGive", "plGive").declareAcquiredMethod("displayThisPage", "displayThisPage").declareAcquiredMethod("displayThisTitle", "displayThisTitle").declareAcquiredMethod("allDocs", "allDocs").declareAcquiredMethod("plEnablePage", "plEnablePage").declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash").declareMethod("render", function(options) { gk.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment").declareAcquiredMethod("jio_get", "jio_get").declareAcquiredMethod("jio_put", "jio_put").declareAcquiredMethod("jio_remove", "jio_remove").declareAcquiredMethod("plSave", "plSave").declareAcquiredMethod("plGive", "plGive").declareAcquiredMethod("displayThisPage", "displayThisPage").declareAcquiredMethod("displayThisTitle", "displayThisTitle").declareAcquiredMethod("allDocs", "allDocs").declareAcquiredMethod("plEnablePage", "plEnablePage").declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash").declareMethod("render", function(options) {
var g = this; var g = this;
if (options.id) { if (options.id) {
return new RSVP.Queue().push(function() { return new RSVP.Queue().push(function() {
...@@ -150,14 +150,13 @@ ...@@ -150,14 +150,13 @@
}); });
}).push(function(url) { }).push(function(url) {
g.__element.getElementsByClassName("next")[0].href = url; g.__element.getElementsByClassName("next")[0].href = url;
g.id = options.id;
return g.jio_get({ return g.jio_get({
_id: options.id _id: options.id
}); });
}).push(function(result) { }).push(function(result) {
var share_context = g.__element.getElementsByClassName("share")[0]; var share_context = g.__element.getElementsByClassName("share")[0];
share_context.href = "https://twitter.com/intent/tweet?hashtags=MusicPlayer&text=" + encodeURI(result.data.title); share_context.href = "https://twitter.com/intent/tweet?hashtags=MusicPlayer&text=" + encodeURI(result.data.title);
g.size = result.data.size; g.metadata = result.data;
return g.displayThisTitle(options.action + " : " + result.data.title); return g.displayThisTitle(options.action + " : " + result.data.title);
}).push(function() { }).push(function() {
g.index = 2e6; g.index = 2e6;
...@@ -204,7 +203,7 @@ ...@@ -204,7 +203,7 @@
time_context.innerHTML = timeFormat(g.audio.duration); time_context.innerHTML = timeFormat(g.audio.duration);
if (g.rebuild) { if (g.rebuild) {
return g.jio_getAttachment({ return g.jio_getAttachment({
_id: g.id, _id: g.currentId,
_attachment: "enclosure" _attachment: "enclosure"
}); });
} }
...@@ -212,25 +211,63 @@ ...@@ -212,25 +211,63 @@
blob = result; blob = result;
return g.plEnablePage(); return g.plEnablePage();
}).push(function() { }).push(function() {
if (blob) { if (g.rebuild) {
g.audio.src = URL.createObjectURL(blob); g.audio.src = URL.createObjectURL(blob);
g.audio.load(); g.audio.load();
g.audio.play(); g.audio.play();
return promiseEventListener(g.audio, "loadedmetadata", false);
}
}).push(function() {
if (g.rebuild) {
bar_context.max = g.audio.duration;
if (g.metadata.time === undefined) {
return g.jio_put({
_id: g.currentId,
title: g.metadata.title,
type: g.metadata.type,
format: g.metadata.type,
size: g.metadata.size,
artist: g.metadata.artist,
album: g.metadata.album,
year: g.metadata.year,
picture: g.metadata.picture,
modified: g.metadata.modified,
date: g.metadata.date,
time: timeFormat(g.audio.duration)
});
}
} else { } else {
g.sourceBuffer.appendBuffer(new Uint8Array(g.buffer)); g.sourceBuffer.appendBuffer(new Uint8Array(g.buffer));
} }
}).push(function() {
return RSVP.any([ play.call(g), loopEventListener(g.sourceBuffer, "updateend", false, function() { return RSVP.any([ play.call(g), loopEventListener(g.sourceBuffer, "updateend", false, function() {
if (!g.fin) { if (!g.fin) {
return; return;
} }
g.fin = false; g.fin = false;
if (g.index >= g.size) { if (g.index >= g.metadata.size) {
g.mediaSource.endOfStream(); g.mediaSource.endOfStream();
bar_context.max = g.audio.duration; bar_context.max = g.audio.duration;
if (g.metadata.time === undefined) {
return g.jio_put({
_id: g.currentId,
title: g.metadata.title,
type: g.metadata.type,
format: g.metadata.type,
size: g.metadata.size,
artist: g.metadata.artist,
album: g.metadata.album,
year: g.metadata.year,
picture: g.metadata.picture,
modified: g.metadata.modified,
date: g.metadata.date,
time: timeFormat(g.audio.duration)
});
}
return; return;
} }
return g.jio_getAttachment({ return g.jio_getAttachment({
_id: g.id, _id: g.currentId,
_attachment: "enclosure", _attachment: "enclosure",
_start: g.index, _start: g.index,
_end: g.index + 1e6 _end: g.index + 1e6
......
...@@ -17,8 +17,9 @@ ...@@ -17,8 +17,9 @@
<a href=#page=control&id={{this.id}}&action=offline> <a href=#page=control&id={{this.id}}&action=offline>
<img src={{this.doc.picture}}> <img src={{this.doc.picture}}>
<h3> {{this.doc.title}} </h3> <h3> {{this.doc.title}} </h3>
<P> {{this.doc.artist}} </p> <P>{{this.doc.artist}}</p>
<P> {{this.doc.album}} </p> <P>{{this.doc.album}} </p>
<p class="ui-li-count">{{this.doc.time}} </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>
...@@ -26,6 +27,7 @@ ...@@ -26,6 +27,7 @@
<h3> {{this.doc.title}} </h3> <h3> {{this.doc.title}} </h3>
<P> {{this.doc.artist}} </p> <P> {{this.doc.artist}} </p>
<P> {{this.doc.album}} </p> <P> {{this.doc.album}} </p>
<p class="ui-li-count">{{this.doc.time}} </p>
</a> </a>
{{/compare}} {{/compare}}
<a href=#page=playlist&id={{this.id}}&action=delete> <a href=#page=playlist&id={{this.id}}&action=delete>
......
...@@ -10,7 +10,16 @@ ...@@ -10,7 +10,16 @@
(function(window, rJS, RSVP, loopEventListener, $, promiseEventListener) { (function(window, rJS, RSVP, loopEventListener, $, promiseEventListener) {
"use strict"; "use strict";
var gk = rJS(window), MediaSource = window.MediaSource || window.WebKitMediaSource || window.mozMediaSource; var gk = rJS(window), MediaSource = window.MediaSource || window.WebKitMediaSource || window.mozMediaSource;
gk.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment").declareAcquiredMethod("jio_get", "jio_get").declareAcquiredMethod("jio_remove", "jio_remove").declareAcquiredMethod("plSave", "plSave").declareAcquiredMethod("plGive", "plGive").declareAcquiredMethod("displayThisPage", "displayThisPage").declareAcquiredMethod("displayThisTitle", "displayThisTitle").declareAcquiredMethod("allDocs", "allDocs").declareAcquiredMethod("plEnablePage", "plEnablePage").declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash").declareMethod("render", function(options) { function timeFormat(seconds) {
var result = "00:" + Math.round(seconds), min, sec;
if (seconds > 59) {
min = Math.floor(seconds / 60);
sec = Math.floor(seconds % 60);
result = (min > 9 ? min : "0" + min) + ":" + (sec > 9 ? sec : "0" + sec);
}
return result;
}
gk.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment").declareAcquiredMethod("jio_get", "jio_get").declareAcquiredMethod("jio_put", "jio_put").declareAcquiredMethod("jio_remove", "jio_remove").declareAcquiredMethod("plSave", "plSave").declareAcquiredMethod("plGive", "plGive").declareAcquiredMethod("displayThisPage", "displayThisPage").declareAcquiredMethod("displayThisTitle", "displayThisTitle").declareAcquiredMethod("allDocs", "allDocs").declareAcquiredMethod("plEnablePage", "plEnablePage").declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash").declareMethod("render", function(options) {
var g = this; var g = this;
if (options.id) { if (options.id) {
return new RSVP.Queue().push(function() { return new RSVP.Queue().push(function() {
...@@ -21,8 +30,7 @@ ...@@ -21,8 +30,7 @@
}).push(function(result) { }).push(function(result) {
var share_context = g.__element.getElementsByClassName("share")[0]; var share_context = g.__element.getElementsByClassName("share")[0];
share_context.href = "https://twitter.com/intent/tweet?hashtags=MusicPlayer&text=" + encodeURI(result.data.title); share_context.href = "https://twitter.com/intent/tweet?hashtags=MusicPlayer&text=" + encodeURI(result.data.title);
g.size = result.data.size; g.metadata = result.data;
g.format = result.data.format;
return g.displayThisTitle(options.action + " : " + result.data.title); return g.displayThisTitle(options.action + " : " + result.data.title);
}).push(function() { }).push(function() {
return g.allDocs({ return g.allDocs({
...@@ -48,7 +56,6 @@ ...@@ -48,7 +56,6 @@
}); });
}).push(function(url) { }).push(function(url) {
g.__element.getElementsByClassName("next")[0].href = url; g.__element.getElementsByClassName("next")[0].href = url;
g.id = options.id;
g.index = 35e5; g.index = 35e5;
return g.jio_getAttachment({ return g.jio_getAttachment({
_id: g.id, _id: g.id,
...@@ -76,7 +83,7 @@ ...@@ -76,7 +83,7 @@
return new RSVP.Queue().push(function() { return new RSVP.Queue().push(function() {
if (g.rebuild) { if (g.rebuild) {
return g.jio_getAttachment({ return g.jio_getAttachment({
_id: g.id, _id: g.currentId,
_attachment: "enclosure" _attachment: "enclosure"
}); });
} }
...@@ -84,32 +91,59 @@ ...@@ -84,32 +91,59 @@
blob = result; blob = result;
return g.plEnablePage(); return g.plEnablePage();
}).push(function() { }).push(function() {
if (blob) { if (g.rebuild) {
g.video.src = URL.createObjectURL(blob); g.video.src = URL.createObjectURL(blob);
g.video.load(); g.video.load();
g.video.play(); g.video.play();
return promiseEventListener(g.video, "loadedmetadata", false);
}
}).push(function() {
if (g.rebuild) {
if (g.metadata.time === undefined) {
return g.jio_put({
_id: g.currentId,
title: g.metadata.title,
type: g.metadata.type,
format: g.metadata.type,
size: g.metadata.size,
artist: g.metadata.artist,
album: g.metadata.album,
year: g.metadata.year,
picture: g.metadata.picture,
modified: g.metadata.modified,
date: g.metadata.date,
time: timeFormat(g.video.duration)
});
}
} else { } else {
g.sourceBuffer.appendBuffer(new Uint8Array(g.buffer)); g.sourceBuffer.appendBuffer(new Uint8Array(g.buffer));
g.video.play(); g.video.play();
} }
return RSVP.any([ loopEventListener(g.video, "ended", false, function() { }).push(function() {
window.location = g.__element.getElementsByClassName("next")[0].href; return RSVP.any([ loopEventListener(g.sourceBuffer, "updateend", false, function() {
}), loopEventListener(g.video, "seeking", false, function(e) {
if (g.buffedTime === undefined) {
g.video.currentTime = 0;
} else {
if (g.video.currentTime > g.buffedTime) {
g.video.currentTime = g.buffedTime;
}
}
}), loopEventListener(g.sourceBuffer, "updateend", false, function() {
g.buffedTime = g.sourceBuffer.buffered.end(0); g.buffedTime = g.sourceBuffer.buffered.end(0);
if (!g.fin) { if (!g.fin) {
return; return;
} }
g.fin = false; g.fin = false;
if (g.index >= g.size) { if (g.index >= g.metadata.size) {
g.mediaSource.endOfStream(); g.mediaSource.endOfStream();
if (g.metadata.time === undefined) {
return g.jio_put({
_id: g.currentId,
title: g.metadata.title,
type: g.metadata.type,
format: g.metadata.type,
size: g.metadata.size,
artist: g.metadata.artist,
album: g.metadata.album,
year: g.metadata.year,
picture: g.metadata.picture,
modified: g.metadata.modified,
date: g.metadata.date,
time: timeFormat(g.video.duration)
});
}
return; return;
} }
return g.jio_getAttachment({ return g.jio_getAttachment({
...@@ -124,6 +158,16 @@ ...@@ -124,6 +158,16 @@
g.fin = true; g.fin = true;
g.sourceBuffer.appendBuffer(new Uint8Array(e.target.result)); g.sourceBuffer.appendBuffer(new Uint8Array(e.target.result));
}); });
}), loopEventListener(g.video, "ended", false, function() {
window.location = g.__element.getElementsByClassName("next")[0].href;
}), loopEventListener(g.video, "seeking", false, function(e) {
if (g.buffedTime === undefined) {
g.video.currentTime = 0;
} else {
if (g.video.currentTime > g.buffedTime) {
g.video.currentTime = g.buffedTime;
}
}
}) ]); }) ]);
}); });
}); });
......
...@@ -138,6 +138,12 @@ ...@@ -138,6 +138,12 @@
return jio_gadget.remove.apply(jio_gadget, param_list); return jio_gadget.remove.apply(jio_gadget, param_list);
}); });
}) })
.allowPublicAcquisition("jio_put", function (param_list) {
return this.getDeclaredGadget(storageType(this.storageType))
.push(function (jio_gadget) {
return jio_gadget.put.apply(jio_gadget, param_list);
});
})
.allowPublicAcquisition("jio_removeAttachment", function (param_list) { .allowPublicAcquisition("jio_removeAttachment", function (param_list) {
return this.getDeclaredGadget(storageType(this.storageType)) return this.getDeclaredGadget(storageType(this.storageType))
.push(function (jio_gadget) { .push(function (jio_gadget) {
......
...@@ -53,16 +53,6 @@ ...@@ -53,16 +53,6 @@
return new RSVP.Promise(itsANonResolvableTrap, canceller); return new RSVP.Promise(itsANonResolvableTrap, canceller);
}; };
function set() { //configure a song
var gadget = this;
gadget.source.connect(gadget.filter);
gadget.filter.connect(gadget.analyser);
gadget.analyser.connect(gadget.gain);
gadget.gain.connect(audioCtx.destination);
}
function timeFormat(seconds) { function timeFormat(seconds) {
var result = '00:' + Math.round(seconds), var result = '00:' + Math.round(seconds),
min, min,
...@@ -76,6 +66,15 @@ ...@@ -76,6 +66,15 @@
return result; return result;
} }
function set() { //configure a song
var gadget = this;
gadget.source.connect(gadget.filter);
gadget.filter.connect(gadget.analyser);
gadget.analyser.connect(gadget.gain);
gadget.gain.connect(audioCtx.destination);
}
function getTime(context, x) { function getTime(context, x) {
var posX = x, var posX = x,
targetLeft = $(context).offset().left; targetLeft = $(context).offset().left;
...@@ -141,9 +140,9 @@ ...@@ -141,9 +140,9 @@
canvasCtx.clearRect(0, 0, cwidth, cheight); canvasCtx.clearRect(0, 0, cwidth, cheight);
step = Math.round(array.length / meterNum); step = Math.round(array.length / meterNum);
bar_context.value = that.audio.currentTime; bar_context.value = that.audio.currentTime;
if (isFinite(that.audio.duration)) { /* if (isFinite(that.audio.duration)) {
bar_context.max = that.audio.duration; bar_context.max = that.audio.duration;
} }*/
time_context.innerHTML = timeFormat(that.audio.duration - time_context.innerHTML = timeFormat(that.audio.duration -
that.audio.currentTime); that.audio.currentTime);
for (i = 0; i < meterNum; i += 1) { for (i = 0; i < meterNum; i += 1) {
...@@ -160,6 +159,7 @@ ...@@ -160,6 +159,7 @@
gk.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment") gk.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("jio_get", "jio_get") .declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("jio_remove", "jio_remove") .declareAcquiredMethod("jio_remove", "jio_remove")
.declareAcquiredMethod("plSave", "plSave") .declareAcquiredMethod("plSave", "plSave")
.declareAcquiredMethod("plGive", "plGive") .declareAcquiredMethod("plGive", "plGive")
...@@ -210,7 +210,6 @@ ...@@ -210,7 +210,6 @@
}) })
.push(function (url) { .push(function (url) {
g.__element.getElementsByClassName("next")[0].href = url; g.__element.getElementsByClassName("next")[0].href = url;
g.id = options.id;
return g.jio_get({"_id" : options.id}); return g.jio_get({"_id" : options.id});
}) })
.push(function (result) { .push(function (result) {
...@@ -218,7 +217,7 @@ ...@@ -218,7 +217,7 @@
share_context.href = share_context.href =
"https://twitter.com/intent/tweet?hashtags=MusicPlayer&text=" "https://twitter.com/intent/tweet?hashtags=MusicPlayer&text="
+ encodeURI(result.data.title); + encodeURI(result.data.title);
g.size = result.data.size; g.metadata = result.data;
return g.displayThisTitle(options.action + " : " return g.displayThisTitle(options.action + " : "
+ result.data.title); + result.data.title);
}) })
...@@ -285,7 +284,7 @@ ...@@ -285,7 +284,7 @@
$(time_context).offset().top = $(bar_context).offset().top + 3; $(time_context).offset().top = $(bar_context).offset().top + 3;
time_context.innerHTML = timeFormat(g.audio.duration); time_context.innerHTML = timeFormat(g.audio.duration);
if (g.rebuild) { if (g.rebuild) {
return g.jio_getAttachment({"_id" : g.id, return g.jio_getAttachment({"_id" : g.currentId,
"_attachment" : "enclosure"}); "_attachment" : "enclosure"});
} }
}) })
...@@ -294,13 +293,35 @@ ...@@ -294,13 +293,35 @@
return g.plEnablePage(); return g.plEnablePage();
}) })
.push(function () { .push(function () {
if (blob) { if (g.rebuild) {
g.audio.src = URL.createObjectURL(blob); g.audio.src = URL.createObjectURL(blob);
g.audio.load(); g.audio.load();
g.audio.play(); g.audio.play();
return promiseEventListener(g.audio, "loadedmetadata", false);
}
})
.push(function () {
if (g.rebuild) {
bar_context.max = g.audio.duration;
if (g.metadata.time === undefined) {
return g.jio_put({"_id": g.currentId,
"title" : g.metadata.title,
"type" : g.metadata.type,
"format" : g.metadata.type,
"size" : g.metadata.size,
"artist" : g.metadata.artist,
"album" : g.metadata.album,
"year" : g.metadata.year,
"picture" : g.metadata.picture,
"modified" : g.metadata.modified,
"date" : g.metadata.date,
"time": timeFormat(g.audio.duration)});
}
} else { } else {
g.sourceBuffer.appendBuffer(new Uint8Array(g.buffer)); g.sourceBuffer.appendBuffer(new Uint8Array(g.buffer));
} }
})
.push(function () {
return RSVP.any([ return RSVP.any([
play.call(g), play.call(g),
loopEventListener(g.sourceBuffer, "updateend", false, function () { loopEventListener(g.sourceBuffer, "updateend", false, function () {
...@@ -308,12 +329,26 @@ ...@@ -308,12 +329,26 @@
return; return;
} }
g.fin = false; g.fin = false;
if (g.index >= g.size) { if (g.index >= g.metadata.size) {
g.mediaSource.endOfStream(); g.mediaSource.endOfStream();
bar_context.max = g.audio.duration; bar_context.max = g.audio.duration;
if (g.metadata.time === undefined) {
return g.jio_put({"_id": g.currentId,
"title" : g.metadata.title,
"type" : g.metadata.type,
"format" : g.metadata.type,
"size" : g.metadata.size,
"artist" : g.metadata.artist,
"album" : g.metadata.album,
"year" : g.metadata.year,
"picture" : g.metadata.picture,
"modified" : g.metadata.modified,
"date" : g.metadata.date,
"time": timeFormat(g.audio.duration)});
}
return; return;
} }
return g.jio_getAttachment({"_id" : g.id, return g.jio_getAttachment({"_id" : g.currentId,
"_attachment" : "enclosure", "_attachment" : "enclosure",
"_start": g.index, "_start": g.index,
"_end": g.index + 1000000}) "_end": g.index + 1000000})
......
...@@ -17,8 +17,9 @@ ...@@ -17,8 +17,9 @@
<a href=#page=control&id={{this.id}}&action=offline> <a href=#page=control&id={{this.id}}&action=offline>
<img src={{this.doc.picture}}> <img src={{this.doc.picture}}>
<h3> {{this.doc.title}} </h3> <h3> {{this.doc.title}} </h3>
<P> {{this.doc.artist}} </p> <P>{{this.doc.artist}}</p>
<P> {{this.doc.album}} </p> <P>{{this.doc.album}} </p>
<p class="ui-li-count">{{this.doc.time}} </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>
...@@ -26,6 +27,7 @@ ...@@ -26,6 +27,7 @@
<h3> {{this.doc.title}} </h3> <h3> {{this.doc.title}} </h3>
<P> {{this.doc.artist}} </p> <P> {{this.doc.artist}} </p>
<P> {{this.doc.album}} </p> <P> {{this.doc.album}} </p>
<p class="ui-li-count">{{this.doc.time}} </p>
</a> </a>
{{/compare}} {{/compare}}
<a href=#page=playlist&id={{this.id}}&action=delete> <a href=#page=playlist&id={{this.id}}&action=delete>
......
...@@ -17,8 +17,23 @@ ...@@ -17,8 +17,23 @@
var gk = rJS(window), var gk = rJS(window),
MediaSource = window.MediaSource || window.WebKitMediaSource MediaSource = window.MediaSource || window.WebKitMediaSource
|| window.mozMediaSource; || window.mozMediaSource;
function timeFormat(seconds) {
var result = '00:' + Math.round(seconds),
min,
sec;
if (seconds > 59) {
min = Math.floor(seconds / 60);
sec = Math.floor(seconds % 60);
result = (min > 9 ? min : ('0' + min)) +
':' + (sec > 9 ? sec : ('0' + sec));
}
return result;
}
gk.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment") gk.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("jio_get", "jio_get") .declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("jio_remove", "jio_remove") .declareAcquiredMethod("jio_remove", "jio_remove")
.declareAcquiredMethod("plSave", "plSave") .declareAcquiredMethod("plSave", "plSave")
.declareAcquiredMethod("plGive", "plGive") .declareAcquiredMethod("plGive", "plGive")
...@@ -40,8 +55,7 @@ ...@@ -40,8 +55,7 @@
share_context.href = share_context.href =
"https://twitter.com/intent/tweet?hashtags=MusicPlayer&text=" "https://twitter.com/intent/tweet?hashtags=MusicPlayer&text="
+ encodeURI(result.data.title); + encodeURI(result.data.title);
g.size = result.data.size; g.metadata = result.data;
g.format = result.data.format;
return g.displayThisTitle(options.action + " : " return g.displayThisTitle(options.action + " : "
+ result.data.title); + result.data.title);
}) })
...@@ -71,7 +85,6 @@ ...@@ -71,7 +85,6 @@
}) })
.push(function (url) { .push(function (url) {
g.__element.getElementsByClassName("next")[0].href = url; g.__element.getElementsByClassName("next")[0].href = url;
g.id = options.id;
g.index = 3500000; g.index = 3500000;
return g.jio_getAttachment({"_id" : g.id, return g.jio_getAttachment({"_id" : g.id,
"_attachment" : "enclosure", "_attachment" : "enclosure",
...@@ -109,7 +122,7 @@ ...@@ -109,7 +122,7 @@
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
if (g.rebuild) { if (g.rebuild) {
return g.jio_getAttachment({"_id" : g.id, return g.jio_getAttachment({"_id" : g.currentId,
"_attachment" : "enclosure"}); "_attachment" : "enclosure"});
} }
}) })
...@@ -118,37 +131,58 @@ ...@@ -118,37 +131,58 @@
return g.plEnablePage(); return g.plEnablePage();
}) })
.push(function () { .push(function () {
if (blob) { if (g.rebuild) {
g.video.src = URL.createObjectURL(blob); g.video.src = URL.createObjectURL(blob);
g.video.load(); g.video.load();
g.video.play(); g.video.play();
return promiseEventListener(g.video, "loadedmetadata", false);
}
})
.push(function () {
if (g.rebuild) {
if (g.metadata.time === undefined) {
return g.jio_put({"_id": g.currentId,
"title" : g.metadata.title,
"type" : g.metadata.type,
"format" : g.metadata.type,
"size" : g.metadata.size,
"artist" : g.metadata.artist,
"album" : g.metadata.album,
"year" : g.metadata.year,
"picture" : g.metadata.picture,
"modified" : g.metadata.modified,
"date" : g.metadata.date,
"time": timeFormat(g.video.duration)});
}
} else { } else {
g.sourceBuffer.appendBuffer(new Uint8Array(g.buffer)); g.sourceBuffer.appendBuffer(new Uint8Array(g.buffer));
g.video.play(); g.video.play();
} }
})
.push(function () {
return RSVP.any([ return RSVP.any([
loopEventListener(g.video, "ended", false, function () {
window.location = g.__element
.getElementsByClassName("next")[0].href;
}),
loopEventListener(g.video, "seeking", false, function (e) {
if (g.buffedTime === undefined) {
g.video.currentTime = 0;
} else {
if (g.video.currentTime > g.buffedTime) {
g.video.currentTime = g.buffedTime;
}
}
}),
loopEventListener(g.sourceBuffer, "updateend", false, function () { loopEventListener(g.sourceBuffer, "updateend", false, function () {
g.buffedTime = g.sourceBuffer.buffered.end(0); g.buffedTime = g.sourceBuffer.buffered.end(0);
if (!g.fin) { if (!g.fin) {
return; return;
} }
g.fin = false; g.fin = false;
if (g.index >= g.size) { if (g.index >= g.metadata.size) {
g.mediaSource.endOfStream(); g.mediaSource.endOfStream();
if (g.metadata.time === undefined) {
return g.jio_put({"_id": g.currentId,
"title" : g.metadata.title,
"type" : g.metadata.type,
"format" : g.metadata.type,
"size" : g.metadata.size,
"artist" : g.metadata.artist,
"album" : g.metadata.album,
"year" : g.metadata.year,
"picture" : g.metadata.picture,
"modified" : g.metadata.modified,
"date" : g.metadata.date,
"time": timeFormat(g.video.duration)});
}
return; return;
} }
return g.jio_getAttachment({"_id" : g.id, return g.jio_getAttachment({"_id" : g.id,
...@@ -163,6 +197,19 @@ ...@@ -163,6 +197,19 @@
g.fin = true; g.fin = true;
g.sourceBuffer.appendBuffer(new Uint8Array(e.target.result)); g.sourceBuffer.appendBuffer(new Uint8Array(e.target.result));
}); });
}),
loopEventListener(g.video, "ended", false, function () {
window.location = g.__element
.getElementsByClassName("next")[0].href;
}),
loopEventListener(g.video, "seeking", false, function (e) {
if (g.buffedTime === undefined) {
g.video.currentTime = 0;
} else {
if (g.video.currentTime > g.buffedTime) {
g.video.currentTime = g.buffedTime;
}
}
}) })
]); ]);
}); });
......
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