scrolling station meta text, autoupdating

This commit is contained in:
Jonas Heinrich 2017-08-08 23:47:37 +02:00
parent c8e86558d0
commit c62ee87b49
4 changed files with 100 additions and 45 deletions

View File

@ -1,9 +1,11 @@
## 0.6.0 2017-09-20 ## 0.6.0 2017-09-20
### Added ### Added
- Display station metadata - Display station metadata
[#1523](https://github.com/owncloud/mail/pull/1523) @tahaalibra [#22](https://github.com/owncloud/mail/pull/1523) @onny
- Changelog file - Add changelog file
[#1523](https://github.com/owncloud/mail/pull/1523) @tahaalibra [#28](https://git.project-insanity.org/onny/nextcloud-app-radio/commit/04b1bbf49c8d7eb95e9e5d08e9e3b4b7cdc7f4ee) @onny
- Continious scrolling
[#13](https://git.project-insanity.org/onny/nextcloud-app-radio/commit/c8e86558d0a1ceeea21f801f6e2391ab70046a4e) @onny
### Changed ### Changed
- Minimum server is Nextcloud 10/ownCloud 9.1 - Minimum server is Nextcloud 10/ownCloud 9.1

View File

@ -1,22 +1,26 @@
#playbutton{ #playbutton{
height:60px; height:50px;
width: 60px; width: 50px;
margin: 15px; margin: 10px;
border: none; border: none;
background-size: 100%; background-size: 100%;
background-position: center; background-position: center;
display: inline;; /* display: inline; */
float: left;
} }
#volumeslider{ #volumeslider{
width: 120px; width: 150px;
display: inline-block; display: inline-block;
margin-top: 0px; margin-top: 15px;
margin-left: 10px; margin-left: 5px;
} }
#station_metadata{ #station_metadata{
margin: 15px; margin: 5px 20px;
padding-left: 5px;
white-space:nowrap;
overflow:hidden;
} }
.play{background: url('../img/play.png') no-repeat;} .play{background: url('../img/play.png') no-repeat;}

View File

@ -1,6 +1,23 @@
$(function(){ $(function(){
searchTimeout = null; searchTimeout = null;
var scheduled;
function isElementOverflowing(element) {
var overflowX = element.offsetWidth < element.scrollWidth,
overflowY = element.offsetHeight < element.scrollHeight;
return (overflowX || overflowY);
}
function wrapContentsInMarquee(element) {
var marquee = document.createElement('marquee'),
contents = element.innerText;
marquee.innerText = contents;
element.innerHTML = '';
element.appendChild(marquee);
}
/* ============== /* ==============
// EVENTS // // EVENTS //
@ -9,7 +26,17 @@ $(function(){
/* Click on a radio station (table entry) and play it */ /* Click on a radio station (table entry) and play it */
$('body').on('click', '.filename', function() { $('body').on('click', '.filename', function() {
var stationid = $(this).parent().attr('data-id'); var stationid = $(this).parent().attr('data-id');
var stationname = $(this).parent().find('.nametext').text();
action_play(stationid); action_play(stationid);
$('#player').attr('data-id',stationid);
$("#station_metadata").html("Playing: "+stationname);
var element = document.getElementById('station_metadata');
if (isElementOverflowing(element)) {
wrapContentsInMarquee(element);
};
if (!scheduled){
schedule_get_metadata(stationid);
};
}); });
/* Save station to favorites */ /* Save station to favorites */
@ -23,7 +50,16 @@ $(function(){
if ($(this).height() == ($(this).get(0).scrollHeight - $(this).scrollTop())) { if ($(this).height() == ($(this).get(0).scrollHeight - $(this).scrollTop())) {
if(!$(this).data("didfire")) { if(!$(this).data("didfire")) {
$(this).data("didfire", true); $(this).data("didfire", true);
if ($('li.nav-files').hasClass('active')){
radio_query(1, ""); radio_query(1, "");
} else if ($('li.nav-recent').hasClass('active')) {
radio_query(2, "");
} else if ($('li.nav-favorites').hasClass('active')) {
console.log("todo");
} else {
var query = $('#searchbox').val();
radio_query(0, query);
};
var ref = $(this); var ref = $(this);
setTimeout(function(){ setTimeout(function(){
ref.data("didfire", false); ref.data("didfire", false);
@ -36,10 +72,28 @@ $(function(){
// ACTIONS // // ACTIONS //
/===============*/ /===============*/
function schedule_get_metadata(stationid){
scheduled = true;
var stationid = $('#player').attr('data-id');
req = $.get('https://onny.project-insanity.org/getmetadata/'+stationid, function(data) {
var metadata = data['metadata'];
if (metadata != $("#station_metadata").text()) {
$("#station_metadata").html(metadata);
var element = document.getElementById('station_metadata');
if (isElementOverflowing(element)) {
wrapContentsInMarquee(element);
};
};
setTimeout(function(){schedule_get_metadata(stationid);}, 10000);
}).fail(function(){
scheduled = false;
});
};
function action_favorite(stationid){ function action_favorite(stationid){
var removed = false; var removed = false;
var stations = [] var stations = [];
var baseUrl = OC.generateUrl('/apps/radio'); var baseUrl = OC.generateUrl('/apps/radio');
$.get(baseUrl + '/stations', function ( data ) { $.get(baseUrl + '/stations', function ( data ) {
@ -74,22 +128,13 @@ $(function(){
}; };
function action_play(stationid){ function action_play(stationid){
$.ajax({
method: "GET",
url: "https://onny.project-insanity.org/getmetadata/"+stationid,
dataType: 'json',
success: function(data){
var title = data['metadata'];
$("#station_metadata").html(title);
}
});
$.ajax({ $.ajax({
method: "GET", method: "GET",
url: "https://www.radio-browser.info/webservice/v2/json/url/"+stationid, url: "https://www.radio-browser.info/webservice/v2/json/url/"+stationid,
dataType: 'json', dataType: 'json',
success: function(data){ success: function(data){
var sourceUrl = data['url']; var streamurl = data['url'];
$("#player").attr("src", sourceUrl); $("#player").attr("src", streamurl);
$('#player').trigger('play'); $('#player').trigger('play');
$('#playbutton').attr("class", "pause"); $('#playbutton').attr("class", "pause");
} }
@ -113,7 +158,7 @@ $(function(){
$('tbody').append('<tr data-src='+station['url']+' data-id='+station['id']+'>\ $('tbody').append('<tr data-src='+station['url']+' data-id='+station['id']+'>\
<td class="favcolumn">\ <td class="favcolumn">\
<a href="#" class="favpls" onclick="station_fav();">\ <a href="#" class="favpls">\
<span class="icon-stationfav ' + isstarred + '"></span>\ <span class="icon-stationfav ' + isstarred + '"></span>\
<span class="hidden-visually">Favorite</span>\ <span class="hidden-visually">Favorite</span>\
</a>\ </a>\
@ -183,6 +228,8 @@ $(function(){
}; };
function switch_menu(type) { function switch_menu(type) {
clearTimeout(searchTimeout);
searchTimeout = setTimeout(function(){
$('#app-navigation').find('li').removeClass("active"); $('#app-navigation').find('li').removeClass("active");
$("tbody > tr").remove(); $("tbody > tr").remove();
switch (type) { switch (type) {
@ -199,6 +246,7 @@ $(function(){
action_load_favorites(); action_load_favorites();
break; break;
} }
}, 500);
} }
$('a.nav-icon-files').click(function() { $('a.nav-icon-files').click(function() {
@ -217,6 +265,7 @@ $(function(){
if (query != "") { if (query != "") {
clearTimeout(searchTimeout); clearTimeout(searchTimeout);
searchTimeout = setTimeout(function(){ searchTimeout = setTimeout(function(){
$('#app-navigation').find('li').removeClass("active");
$("tbody > tr").remove(); $("tbody > tr").remove();
radio_query(0, query); radio_query(0, query);
}, 500); }, 500);

View File

@ -27,7 +27,7 @@
<audio id="player" src=""></audio> <audio id="player" src=""></audio>
<button id="playbutton" class="play"></button> <button id="playbutton" class="play"></button>
<div id="volumeslider"></div> <div id="volumeslider"></div>
<p id="station_metadata">Test</p> <p id="station_metadata"></p>
</div> </div>
</div> </div>
<div id="app-content"> <div id="app-content">