added fancy audio player with volume slide

This commit is contained in:
Jonas Heinrich 2017-08-04 22:08:31 +02:00
parent 1ad95f672f
commit f8709da5fa
5 changed files with 55 additions and 4 deletions

View File

@ -1,3 +1,22 @@
#playbutton{
height:60px;
width: 60px;
margin: 15px;
border: none;
background-size: 100%;
background-position: center;
display: inline;;
}
#volumeslider{
width: 120px;
display: inline-block;
margin-top: 0px;
margin-left: 10px;
}
.play{background: url('../img/play.png') no-repeat;}
.pause{background: url('../img/pause.png') no-repeat;}
/* SETTINGS */ /* SETTINGS */
#files-setting-showhidden { #files-setting-showhidden {
padding-bottom: 8px; padding-bottom: 8px;

BIN
img/pause.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
img/play.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@ -2,11 +2,13 @@ $(function(){
searchTimeout = null; searchTimeout = null;
/*$('body').on('click', 'tr', function() { /* Click on a radio station (table entry) and play it */
$('body').on('click', 'tr', function() {
var stationid = $(this).attr('data-id'); var stationid = $(this).attr('data-id');
play_station(stationid); play_station(stationid);
}); */ });
/*
$('body').on('click', 'tr .icon', function() { $('body').on('click', 'tr .icon', function() {
alert('test'); alert('test');
}); });
@ -14,16 +16,18 @@ $(function(){
$('.icon-star').click(function (){ $('.icon-star').click(function (){
alert('test'); alert('test');
}); });
*/
function play_station(stationid){ function play_station(stationid){
$.ajax({ $.ajax({
method: "GET", method: "GET",
url: "http://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 sourceUrl = data['url'];
$("#player").attr("src", sourceUrl); $("#player").attr("src", sourceUrl);
$('#player').trigger('play'); $('#player').trigger('play');
$('#playbutton').attr("class", "pause");
return true; return true;
} }
}); });
@ -146,5 +150,31 @@ $(function(){
} }
}); });
$('#playbutton').click(function() {
var music = document.getElementById('player');
if (music.paused && $("#player").attr("src") != "") {
music.play();
playbutton.className = "";
playbutton.className = "pause";
} else {
music.pause();
playbutton.className = "";
playbutton.className = "play";
}
});
$('#volumeslider').slider({
orientation: "horizontal",
value: player.volume,
min: 0,
max: 1,
range: 'min',
animate: true,
step: .1,
slide: function(e, ui) {
player.volume = ui.value;
}
});
switch_menu(0); switch_menu(0);
}); });

View File

@ -24,7 +24,9 @@
</li> </li>
</ul> </ul>
<div id="app-settings"> <div id="app-settings">
<audio id="player" src="" controls></audio> <audio id="player" src=""></audio>
<button id="playbutton" class="play"></button>
<div id="volumeslider"></div>
</div> </div>
</div> </div>
<div id="app-content"> <div id="app-content">