radio-parasite-front/assets/app.js

100 lines
2.6 KiB
JavaScript
Raw Permalink Normal View History

2015-10-16 22:43:20 +11:00
/*$( document ).ready(function() {
// var wavesurfer = Object.create(WaveSurfer);
console.log(emissions)
$("[id=^waveform_]").each(function(){
;
//createAudioView( "#{e.url}", "waveform_#{i}")}
})
})
*/
var createAudioView = function ( url, id ) {
var wavesurfer = Object.create(WaveSurfer);
console.log(id)
wavesurfer.init({
container: document.querySelector(id),
backend: 'MediaElement',
waveColor: 'violet',
progressColor: 'purple',
height: 120
});
console.log(wavesurfer)
wavesurfer.load(url)
}
/*
// Init on DOM ready
document.addEventListener('DOMContentLoaded', function () {
wavesurfer.init({
container: '#waveform',
waveColor: 'violet',
progressColor: 'purple',
height: 120
});
});
// Bind controls
document.addEventListener('DOMContentLoaded', function () {
var playPause = document.querySelector('#playPause');
playPause.addEventListener('click', function () {
wavesurfer.playPause();
});
// Toggle play/pause text
wavesurfer.on('play', function () {
document.querySelector('#play').style.display = 'none';
document.querySelector('#pause').style.display = '';
});
wavesurfer.on('pause', function () {
document.querySelector('#play').style.display = '';
document.querySelector('#pause').style.display = 'none';
});
// The playlist links
var links = document.querySelectorAll('#playlist a');
var currentTrack = 0;
// Load a track by index and highlight the corresponding link
var setCurrentSong = function (index) {
links[currentTrack].classList.remove('active');
currentTrack = index;
links[currentTrack].classList.add('active');
wavesurfer.load(links[currentTrack].href);
};
// Load the track on click
Array.prototype.forEach.call(links, function (link, index) {
link.addEventListener('click', function (e) {
e.preventDefault();
setCurrentSong(index);
});
});
// Play on audio load
wavesurfer.on('ready', function () {
wavesurfer.play();
});
// Go to the next track on finish
wavesurfer.on('finish', function () {
setCurrentSong((currentTrack + 1) % links.length);
});
// Load the first track
setCurrentSong(currentTrack);
var request = $.ajax({
url: "/emissions/all",
method: "GET",
dataType: "json"
}).done(function (msg){ console.log(msg)})
});
*/