added loop tool
This commit is contained in:
@@ -72,12 +72,23 @@
|
|||||||
<div class="col-xs-2">
|
<div class="col-xs-2">
|
||||||
<button id='stopBtn' class='btn btn-danger'><i class='fa fa-stop'></i></button>
|
<button id='stopBtn' class='btn btn-danger'><i class='fa fa-stop'></i></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-xs-4">
|
<div class="col-xs-8">
|
||||||
|
<button id='aLoopBtn' class='btn btn-warning'><b>A</b></button>
|
||||||
|
<label class="info-txt-small" id="txt-aLoop">0:00</label>
|
||||||
|
<i class='fa fa-repeat'></i>
|
||||||
|
<label class="info-txt-small" id="txt-bLoop">0:00</label>
|
||||||
|
<button id='bLoopBtn' class='btn btn-danger'><b>B</b></button>
|
||||||
|
<button id='resetLoopBtn' class='btn btn-danger'><i class='fa fa-times'></i></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-6">
|
||||||
<label class="info-txt-small">Geschwindigkeit:</label>
|
<label class="info-txt-small">Geschwindigkeit:</label>
|
||||||
<label class="info-txt-small align-right" id="txt-speed">100%</label>
|
<label class="info-txt-small align-right" id="txt-speed">100%</label>
|
||||||
<input type="range" min="50" max="200" value="100" class="slider" id="speed-slider">
|
<input type="range" min="50" max="200" value="100" class="slider" id="speed-slider">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-xs-4">
|
<div class="col-xs-6">
|
||||||
<label class="info-txt-small">Lautstärke:</label>
|
<label class="info-txt-small">Lautstärke:</label>
|
||||||
<label class="info-txt-small align-right" id="txt-volume">70%</label>
|
<label class="info-txt-small align-right" id="txt-volume">70%</label>
|
||||||
<input type="range" min="0" max="1000" value="700" class="slider" id="volume-slider">
|
<input type="range" min="0" max="1000" value="700" class="slider" id="volume-slider">
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ var columns = [
|
|||||||
var currentSong = null;
|
var currentSong = null;
|
||||||
var songDir = [];
|
var songDir = [];
|
||||||
var player = null;
|
var player = null;
|
||||||
|
var aLoopTime = null;
|
||||||
|
var bLoopTime = null;
|
||||||
|
|
||||||
// init socket io and
|
// init socket io and
|
||||||
$(function () {
|
$(function () {
|
||||||
@@ -62,6 +64,29 @@ $(function () {
|
|||||||
player.stop();
|
player.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$( '#aLoopBtn' ).click(function(){
|
||||||
|
if(player == null)
|
||||||
|
return
|
||||||
|
aLoopTime = player.getPosition();
|
||||||
|
$( '#bLoopBtn' ).prop("disabled", false);
|
||||||
|
$( '#txt-aLoop' ).html(player.formatTime(Math.round(aLoopTime)));
|
||||||
|
});
|
||||||
|
|
||||||
|
$( '#bLoopBtn' ).click(function(){
|
||||||
|
if(player == null)
|
||||||
|
return
|
||||||
|
bLoopTime = player.getPosition();
|
||||||
|
$( '#aLoopBtn' ).prop("disabled", false);
|
||||||
|
$( '#resetLoopBtn' ).prop("disabled", false);
|
||||||
|
$( '#txt-bLoop' ).html(player.formatTime(Math.round(bLoopTime)));
|
||||||
|
});
|
||||||
|
|
||||||
|
$( '#resetLoopBtn' ).click(function(){
|
||||||
|
if(player == null)
|
||||||
|
return
|
||||||
|
resetLoop();
|
||||||
|
});
|
||||||
|
|
||||||
//dropdown
|
//dropdown
|
||||||
|
|
||||||
$( '#dir-dropdown' ).change(function () {
|
$( '#dir-dropdown' ).change(function () {
|
||||||
@@ -93,6 +118,9 @@ $(function () {
|
|||||||
function updateDisplay(){
|
function updateDisplay(){
|
||||||
playBtn = $( '#playBtn' );
|
playBtn = $( '#playBtn' );
|
||||||
stopBtn = $( '#stopBtn' );
|
stopBtn = $( '#stopBtn' );
|
||||||
|
aLoopBtn = $( '#aLoopBtn' );
|
||||||
|
bLoopBtn = $( '#bLoopBtn' );
|
||||||
|
resetLoopBtn= $( '#resetLoopBtn' );
|
||||||
|
|
||||||
volumeSl = $( '#volume-slider' );
|
volumeSl = $( '#volume-slider' );
|
||||||
speedSl = $( '#speed-slider' );
|
speedSl = $( '#speed-slider' );
|
||||||
@@ -100,17 +128,18 @@ function updateDisplay(){
|
|||||||
|
|
||||||
speedTxt = $( '#txt-speed' );
|
speedTxt = $( '#txt-speed' );
|
||||||
volumeTxt = $( '#txt-volume' );
|
volumeTxt = $( '#txt-volume' );
|
||||||
timerTxt = $( '#txt-timer' );
|
|
||||||
durationTxt = $( '#txt-duration' );
|
|
||||||
titelTxt = $( '#txt-titel' );
|
|
||||||
|
|
||||||
if(player == null){
|
if(player == null){
|
||||||
playBtn.prop("disabled", true);
|
playBtn.prop("disabled", true);
|
||||||
stopBtn.prop("disabled", true);
|
stopBtn.prop("disabled", true);
|
||||||
|
aLoopBtn.prop("disabled", true);
|
||||||
|
bLoopBtn.prop("disabled", true);
|
||||||
|
resetLoopBtn.prop("disabled", true);
|
||||||
positionSl.prop("disabled", true);
|
positionSl.prop("disabled", true);
|
||||||
}else{
|
}else{
|
||||||
stopBtn.prop("disabled", false);
|
stopBtn.prop("disabled", false);
|
||||||
positionSl.prop("disabled", false);
|
positionSl.prop("disabled", false);
|
||||||
|
aLoopBtn.prop("disabled", false);
|
||||||
player.rate(speedSl[0].value/100);
|
player.rate(speedSl[0].value/100);
|
||||||
player.volume(volumeSl[0].value/1000);
|
player.volume(volumeSl[0].value/1000);
|
||||||
}
|
}
|
||||||
@@ -148,16 +177,26 @@ function tableClickListener(){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resetLoop(){
|
||||||
|
aLoopTime = null;
|
||||||
|
bLoopTime = null;
|
||||||
|
$( '#txt-aLoop' ).html('0:00');
|
||||||
|
$( '#txt-bLoop' ).html('0:00');
|
||||||
|
$( '#bLoopBtn' ).prop("disabled", true);
|
||||||
|
$( '#resetLoopBtn' ).prop("disabled", true);
|
||||||
|
}
|
||||||
|
|
||||||
var Player = function(songName) {
|
var Player = function(songName) {
|
||||||
this.song = songName;
|
this.song = songName;
|
||||||
let dir = $( '#dir-dropdown' ).find(":selected").text();
|
let dir = $( '#dir-dropdown' ).find(":selected").text();
|
||||||
this.url = './songs/' + dir + '/' + songName;
|
this.url = './songs/' + dir + '/' + songName;
|
||||||
this.howl = null;
|
this.howl = null;
|
||||||
|
resetLoop();
|
||||||
|
|
||||||
// Display the title of the first track.
|
// Display the title of the first track.
|
||||||
$( '#txt-titel' ).text(songName);
|
$( '#txt-titel' ).text(songName);
|
||||||
};
|
};
|
||||||
|
|
||||||
Player.prototype = {
|
Player.prototype = {
|
||||||
/**
|
/**
|
||||||
* Play a song.
|
* Play a song.
|
||||||
@@ -184,6 +223,7 @@ Player.prototype = {
|
|||||||
onload: function() {
|
onload: function() {
|
||||||
$( '#txt-duration' ).text(self.formatTime(Math.round(sound.duration())));
|
$( '#txt-duration' ).text(self.formatTime(Math.round(sound.duration())));
|
||||||
$( '#playBtn' ).prop("disabled", false);
|
$( '#playBtn' ).prop("disabled", false);
|
||||||
|
self.step();
|
||||||
},
|
},
|
||||||
onend: function() {
|
onend: function() {
|
||||||
$( '#playBtn' ).removeClass('btn-warning').addClass('btn-succes');
|
$( '#playBtn' ).removeClass('btn-warning').addClass('btn-succes');
|
||||||
@@ -290,6 +330,10 @@ Player.prototype = {
|
|||||||
|
|
||||||
// Determine our current seek position.
|
// Determine our current seek position.
|
||||||
var seek = sound.seek() || 0;
|
var seek = sound.seek() || 0;
|
||||||
|
if(aLoopTime != null && bLoopTime != null){
|
||||||
|
if(seek > bLoopTime)
|
||||||
|
sound.seek(aLoopTime);
|
||||||
|
}
|
||||||
$( '#txt-timer' ).text(self.formatTime(Math.round(seek)));
|
$( '#txt-timer' ).text(self.formatTime(Math.round(seek)));
|
||||||
$( '#position-slider' ).val(((seek / sound.duration())*1000) || 0);
|
$( '#position-slider' ).val(((seek / sound.duration())*1000) || 0);
|
||||||
|
|
||||||
@@ -314,6 +358,18 @@ Player.prototype = {
|
|||||||
return (sound.playing());
|
return (sound.playing());
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get raw position in seconds
|
||||||
|
* @return {long} seconds
|
||||||
|
*/
|
||||||
|
getPosition: function() {
|
||||||
|
var self = this;
|
||||||
|
var sound = self.howl;
|
||||||
|
if (sound == null)
|
||||||
|
return 0;
|
||||||
|
return sound.seek();
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format the time from seconds to M:SS.
|
* Format the time from seconds to M:SS.
|
||||||
* @param {Number} secs Seconds to format.
|
* @param {Number} secs Seconds to format.
|
||||||
|
|||||||
Reference in New Issue
Block a user