Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Server Development
Habbo Retros
Habbo Q&A
Radio PLayer not working or finding my radio
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="EngeldesTodes" data-source="post: 418093" data-attributes="member: 2432"><p>the rscript and client radio and client.php</p><p>[doublepost=1504653933,1504652107][/doublepost]rscript.php</p><p>[PHP]<script></p><p>;</p><p>(function(window, undefined) {</p><p></p><p> 'use strict';</p><p></p><p> var AudioPlayer = (function() {</p><p></p><p> // Player vars</p><p> var</p><p> player = document.getElementById('ap'),</p><p> playBtn,</p><p> prevBtn,</p><p> nextBtn,</p><p> plBtn,</p><p> repeatBtn,</p><p> volumeBtn,</p><p> progressBar,</p><p> preloadBar,</p><p> curTime,</p><p> durTime,</p><p> trackTitle,</p><p> audio,</p><p> index = 0,</p><p> playList,</p><p> volumeBar,</p><p> volumeLength,</p><p> repeating = false,</p><p> seeking = false,</p><p> rightClick = false,</p><p> apActive = false,</p><p> // playlist vars</p><p> pl,</p><p> plLi,</p><p> // settings</p><p> settings = {</p><p> volume: 0.3,</p><p> autoPlay: false,</p><p> notification: true,</p><p> playList: []</p><p> };</p><p></p><p> function init(options) {</p><p></p><p> if (!('classList' in document.documentElement)) {</p><p> return false;</p><p> }</p><p></p><p> if (apActive || player === null) {</p><p> return;</p><p> }</p><p></p><p> settings = extend(settings, options);</p><p></p><p> // get player elements</p><p> playBtn = player.querySelector('.ap-toggle-btn');</p><p> prevBtn = player.querySelector('.ap-prev-btn');</p><p> nextBtn = player.querySelector('.ap-next-btn');</p><p> repeatBtn = player.querySelector('.ap-repeat-btn');</p><p> volumeBtn = player.querySelector('.ap-volume-btn');</p><p> plBtn = player.querySelector('.ap-playlist-btn');</p><p> curTime = player.querySelector('.ap-time--current');</p><p> durTime = player.querySelector('.ap-time--duration');</p><p> trackTitle = player.querySelector('.ap-title');</p><p> progressBar = player.querySelector('.ap-bar');</p><p> preloadBar = player.querySelector('.ap-preload-bar');</p><p> volumeBar = player.querySelector('.ap-volume-bar');</p><p></p><p> playList = settings.playList;</p><p></p><p> playBtn.addEventListener('click', playToggle, false);</p><p> volumeBtn.addEventListener('click', volumeToggle, false);</p><p> repeatBtn.addEventListener('click', repeatToggle, false);</p><p></p><p> progressBar.parentNode.parentNode.addEventListener('mousedown', handlerBar, false);</p><p> progressBar.parentNode.parentNode.addEventListener('mousemove', seek, false);</p><p> document.documentElement.addEventListener('mouseup', seekingFalse, false);</p><p></p><p> volumeBar.parentNode.parentNode.addEventListener('mousedown', handlerVol, false);</p><p> volumeBar.parentNode.parentNode.addEventListener('mousemove', setVolume);</p><p> document.documentElement.addEventListener('mouseup', seekingFalse, false);</p><p></p><p> prevBtn.addEventListener('click', prev, false);</p><p> nextBtn.addEventListener('click', next, false);</p><p></p><p> apActive = true;</p><p></p><p> // Create playlist</p><p> renderPL();</p><p> plBtn.addEventListener('click', plToggle, false);</p><p></p><p> // Create audio object</p><p> audio = new Audio();</p><p> audio.volume = settings.volume;</p><p></p><p> if (isEmptyList()) {</p><p> empty();</p><p> return;</p><p> }</p><p></p><p> audio.src = playList[index].file;</p><p> audio.preload = 'auto';</p><p> trackTitle.innerHTML = playList[index].title;</p><p> volumeBar.style.height = audio.volume * 100 + '%';</p><p> volumeLength = volumeBar.css('height');</p><p></p><p> audio.addEventListener('error', error, false);</p><p> audio.addEventListener('timeupdate', update, false);</p><p> audio.addEventListener('ended', doEnd, false);</p><p></p><p> if (settings.autoPlay) {</p><p> audio.play();</p><p> playBtn.classList.add('playing');</p><p> plLi[index].classList.add('pl-current');</p><p> }</p><p> }</p><p>//'<img src="http://switchhotel.net/app/tpl/skins/SwitchCMS/images/logo2.png" />' ;</p><p> /**</p><p> * PlayList methods</p><p> */</p><p> function renderPL() {</p><p> var html = [];</p><p> var tpl =</p><p> </p><p> '<li data-track="{count}">' +</p><p> '<div class="pl-number">' +</p><p> '<div class="pl-count">' +</p><p> '<svg fill="#000000" height="20" viewBox="0 0 24 24" width="20" xmlns="http://www.w3.org/2000/svg">' +</p><p> '<path d="M0 0h24v24H0z" fill="none"/>' +</p><p> '<path d="M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z"/>' +</p><p> '</svg>' +</p><p> '</div>' +</p><p> '<div class="pl-playing">' +</p><p> '<div class="eq">' +</p><p> '<div class="eq-bar"></div>' +</p><p> '<div class="eq-bar"></div>' +</p><p> '<div class="eq-bar"></div>' +</p><p> '</div>' +</p><p> '</div>' +</p><p> '</div>' +</p><p> '<div class="pl-title"><b>{title}</b></div>' +</p><p> '<button class="pl-remove">' +</p><p> '<svg fill="#000000" height="20" viewBox="0 0 24 24" width="20" xmlns="http://www.w3.org/2000/svg">' +</p><p> '<path d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"/>' +</p><p> '<path d="M0 0h24v24H0z" fill="none"/>' +</p><p> '</svg>' +</p><p> '</button>' +</p><p> '</li>';</p><p></p><p> playList.forEach(function(item, i) {</p><p> html.push(</p><p> tpl.replace('{count}', i).replace('{title}', item.title)</p><p> );</p><p> });</p><p></p><p> pl = create('div', {</p><p> 'className': 'pl-container hide',</p><p> 'id': 'pl',</p><p> 'innerHTML': !isEmptyList() ? '<ul class="pl-list">' + html.join('') + '</ul>' : '<div class="pl-empty">PlayList is empty</div>'</p><p> });</p><p></p><p> player.parentNode.insertBefore(pl, player.nextSibling);</p><p></p><p> plLi = pl.querySelectorAll('li');</p><p></p><p> pl.addEventListener('click', listHandler, false);</p><p> }</p><p></p><p> function listHandler(evt) {</p><p> evt.preventDefault();</p><p> if (evt.target.className === 'pl-title') {</p><p> var current = parseInt(evt.target.parentNode.getAttribute('data-track'), 10);</p><p> index = current;</p><p> play();</p><p> plActive();</p><p> } else {</p><p> var target = evt.target;</p><p> while (target.className !== pl.className) {</p><p> if (target.className === 'pl-remove') {</p><p> var isDel = parseInt(target.parentNode.getAttribute('data-track'), 10);</p><p></p><p> playList.splice(isDel, 1);</p><p> target.parentNode.parentNode.removeChild(target.parentNode);</p><p></p><p> plLi = pl.querySelectorAll('li');</p><p></p><p> [].forEach.call(plLi, function(el, i) {</p><p> el.setAttribute('data-track', i);</p><p> });</p><p></p><p> if (!audio.paused) {</p><p></p><p> if (isDel === index) {</p><p> play();</p><p> }</p><p></p><p> } else {</p><p> if (isEmptyList()) {</p><p> empty();</p><p> } else {</p><p> // audio.currentTime = 0;</p><p> audio.src = playList[index].file;</p><p> document.title = trackTitle.innerHTML = playList[index].title;</p><p> progressBar.style.width = 0;</p><p> }</p><p> }</p><p> if (isDel < index) {</p><p> index--;</p><p> }</p><p></p><p> return;</p><p> }</p><p> target = target.parentNode;</p><p> }</p><p></p><p> }</p><p> }</p><p></p><p> function plActive() {</p><p> if (audio.paused) {</p><p> plLi[index].classList.remove('pl-current');</p><p> return;</p><p> }</p><p> var current = index;</p><p> for (var i = 0, len = plLi.length; len > i; i++) {</p><p> plLi[i].classList.remove('pl-current');</p><p> }</p><p> plLi[current].classList.add('pl-current');</p><p> }</p><p></p><p> /**</p><p> * Player methods</p><p> */</p><p> function error() {</p><p> !isEmptyList() && next();</p><p> }</p><p></p><p> function play() {</p><p></p><p> index = (index > playList.length - 1) ? 0 : index;</p><p> if (index < 0) index = playList.length - 1;</p><p></p><p> if (isEmptyList()) {</p><p> empty();</p><p> return;</p><p> }</p><p></p><p> audio.src = playList[index].file;</p><p> audio.preload = 'auto';</p><p> document.title = trackTitle.innerHTML = playList[index].title;</p><p> audio.play();</p><p> notify(playList[index].title, {</p><p> icon: playList[index].icon,</p><p> body: 'Now playing',</p><p> tag: 'music-player'</p><p> });</p><p> playBtn.classList.add('playing');</p><p> plActive();</p><p> }</p><p></p><p> function prev() {</p><p> index = index - 1;</p><p> play();</p><p> }</p><p></p><p> function next() {</p><p> index = index + 1;</p><p> play();</p><p> }</p><p></p><p> function isEmptyList() {</p><p> return playList.length === 0;</p><p> }</p><p></p><p> function empty() {</p><p> audio.pause();</p><p> audio.src = '';</p><p> trackTitle.innerHTML = 'queue is empty';</p><p> curTime.innerHTML = '--';</p><p> durTime.innerHTML = '--';</p><p> progressBar.style.width = 0;</p><p> preloadBar.style.width = 0;</p><p> playBtn.classList.remove('playing');</p><p> pl.innerHTML = '<div class="pl-empty">PlayList is empty</div>';</p><p> }</p><p></p><p> function playToggle() {</p><p> if (isEmptyList()) {</p><p> return;</p><p> }</p><p> if (audio.paused) {</p><p> audio.play();</p><p> notify(playList[index].title, {</p><p> icon: playList[index].icon,</p><p> body: 'Now playing'</p><p> });</p><p> this.classList.add('playing');</p><p> } else {</p><p> audio.pause();</p><p> this.classList.remove('playing');</p><p> }</p><p> plActive();</p><p> }</p><p></p><p> function volumeToggle() {</p><p> if (audio.muted) {</p><p> if (parseInt(volumeLength, 10) === 0) {</p><p> volumeBar.style.height = '100%';</p><p> audio.volume = 1;</p><p> } else {</p><p> volumeBar.style.height = volumeLength;</p><p> }</p><p> audio.muted = false;</p><p> this.classList.remove('muted');</p><p> } else {</p><p> audio.muted = true;</p><p> volumeBar.style.height = 0;</p><p> this.classList.add('muted');</p><p> }</p><p> }</p><p></p><p> function repeatToggle() {</p><p> var repeat = this.classList;</p><p> if (repeat.contains('ap-active')) {</p><p> repeating = false;</p><p> repeat.remove('ap-active');</p><p> } else {</p><p> repeating = true;</p><p> repeat.add('ap-active');</p><p> }</p><p> }</p><p></p><p> function plToggle() {</p><p> this.classList.toggle('ap-active');</p><p> pl.classList.toggle('hide');</p><p> }</p><p></p><p> function update() {</p><p> if (audio.readyState === 0) return;</p><p></p><p> var barlength = Math.round(audio.currentTime * (100 / audio.duration));</p><p> progressBar.style.width = barlength + '%';</p><p></p><p> var</p><p> curMins = Math.floor(audio.currentTime / 60),</p><p> curSecs = Math.floor(audio.currentTime - curMins * 60),</p><p> mins = Math.floor(audio.duration / 60),</p><p> secs = Math.floor(audio.duration - mins * 60);</p><p> (curSecs < 10) && (curSecs = '0' + curSecs);</p><p> (secs < 10) && (secs = '0' + secs);</p><p></p><p> curTime.innerHTML = curMins + ':' + curSecs;</p><p> durTime.innerHTML = mins + ':' + secs;</p><p></p><p> var buffered = audio.buffered;</p><p> if (buffered.length) {</p><p> var loaded = Math.round(100 * buffered.end(0) / audio.duration);</p><p> preloadBar.style.width = loaded + '%';</p><p> }</p><p> }</p><p></p><p> function doEnd() {</p><p> if (index === playList.length - 1) {</p><p> if (!repeating) {</p><p> audio.pause();</p><p> plActive();</p><p> playBtn.classList.remove('playing');</p><p> return;</p><p> } else {</p><p> index = 0;</p><p> play();</p><p> }</p><p> } else {</p><p> index = (index === playList.length - 1) ? 0 : index + 1;</p><p> play();</p><p> }</p><p> }</p><p></p><p> function moveBar(evt, el, dir) {</p><p> var value;</p><p> if (dir === 'horizontal') {</p><p> value = Math.round((evt.clientX - el.offset().left) * 100 / el.parentNode.offsetWidth);</p><p> el.style.width = value + '%';</p><p> return value;</p><p> } else {</p><p> var offset = el.offset().top + el.offsetHeight;</p><p> value = Math.round((offset - evt.clientY));</p><p> if (value > 100) value = 100;</p><p> if (value < 0) value = 0;</p><p> volumeBar.style.height = value + '%';</p><p> return value;</p><p> }</p><p> }</p><p></p><p> function handlerBar(evt) {</p><p> rightClick = (evt.which === 3) ? true : false;</p><p> seeking = true;</p><p> seek(evt);</p><p> }</p><p></p><p> function handlerVol(evt) {</p><p> rightClick = (evt.which === 3) ? true : false;</p><p> seeking = true;</p><p> setVolume(evt);</p><p> }</p><p></p><p> function seek(evt) {</p><p> if (seeking && rightClick === false && audio.readyState !== 0) {</p><p> var value = moveBar(evt, progressBar, 'horizontal');</p><p> audio.currentTime = audio.duration * (value / 100);</p><p> }</p><p> }</p><p></p><p> function seekingFalse() {</p><p> seeking = false;</p><p> }</p><p></p><p> function setVolume(evt) {</p><p> volumeLength = volumeBar.css('height');</p><p> if (seeking && rightClick === false) {</p><p> var value = moveBar(evt, volumeBar.parentNode, 'vertical') / 100;</p><p> if (value <= 0) {</p><p> audio.volume = 0;</p><p> volumeBtn.classList.add('muted');</p><p> } else {</p><p> if (audio.muted) audio.muted = false;</p><p> audio.volume = value;</p><p> volumeBtn.classList.remove('muted');</p><p> }</p><p> }</p><p> }</p><p></p><p> function notify(title, attr) {</p><p> if (!settings.notification) {</p><p> return;</p><p> }</p><p> if (window.Notification === undefined) {</p><p> return;</p><p> }</p><p> window.Notification.requestPermission(function(access) {</p><p> if (access === 'granted') {</p><p> var notice = new Notification(title.substr(0, 110), attr);</p><p> notice.onshow = function() {</p><p> setTimeout(function() {</p><p> notice.close();</p><p> }, 5000);</p><p> }</p><p> // notice.onclose = function() {</p><p> // if(noticeTimer) {</p><p> // clearTimeout(noticeTimer);</p><p> // }</p><p> // }</p><p> }</p><p> })</p><p> }</p><p></p><p> /* Destroy method. Clear All */</p><p> function destroy() {</p><p> if (!apActive) return;</p><p></p><p> playBtn.removeEventListener('click', playToggle, false);</p><p> volumeBtn.removeEventListener('click', volumeToggle, false);</p><p> repeatBtn.removeEventListener('click', repeatToggle, false);</p><p> plBtn.removeEventListener('click', plToggle, false);</p><p></p><p> progressBar.parentNode.parentNode.removeEventListener('mousedown', handlerBar, false);</p><p> progressBar.parentNode.parentNode.removeEventListener('mousemove', seek, false);</p><p> document.documentElement.removeEventListener('mouseup', seekingFalse, false);</p><p></p><p> volumeBar.parentNode.parentNode.removeEventListener('mousedown', handlerVol, false);</p><p> volumeBar.parentNode.parentNode.removeEventListener('mousemove', setVolume);</p><p> document.documentElement.removeEventListener('mouseup', seekingFalse, false);</p><p></p><p> prevBtn.removeEventListener('click', prev, false);</p><p> nextBtn.removeEventListener('click', next, false);</p><p></p><p> audio.removeEventListener('error', error, false);</p><p> audio.removeEventListener('timeupdate', update, false);</p><p> audio.removeEventListener('ended', doEnd, false);</p><p> player.parentNode.removeChild(player);</p><p></p><p> // Playlist</p><p> pl.removeEventListener('click', listHandler, false);</p><p> pl.parentNode.removeChild(pl);</p><p></p><p> audio.pause();</p><p> apActive = false;</p><p> }</p><p></p><p> /**</p><p> * Helpers</p><p> */</p><p> function extend(defaults, options) {</p><p> for (var name in options) {</p><p> if (defaults.hasOwnProperty(name)) {</p><p> defaults[name] = options[name];</p><p> }</p><p> }</p><p> return defaults;</p><p> }</p><p></p><p> function create(el, attr) {</p><p> var element = document.createElement(el);</p><p> if (attr) {</p><p> for (var name in attr) {</p><p> if (element[name] !== undefined) {</p><p> element[name] = attr[name];</p><p> }</p><p> }</p><p> }</p><p> return element;</p><p> }</p><p></p><p> Element.prototype.offset = function() {</p><p> var el = this.getBoundingClientRect(),</p><p> scrollLeft = window.pageXOffset || document.documentElement.scrollLeft,</p><p> scrollTop = window.pageYOffset || document.documentElement.scrollTop;</p><p></p><p> return {</p><p> top: el.top + scrollTop,</p><p> left: el.left + scrollLeft</p><p> };</p><p> };</p><p></p><p> Element.prototype.css = function(attr) {</p><p> if (typeof attr === 'string') {</p><p> return getComputedStyle(this, '')[attr];</p><p> } else if (typeof attr === 'object') {</p><p> for (var name in attr) {</p><p> if (this.style[name] !== undefined) {</p><p> this.style[name] = attr[name];</p><p> }</p><p> }</p><p> }</p><p> };</p><p></p><p> /**</p><p> * Public methods</p><p> */</p><p> return {</p><p> init: init,</p><p> destroy: destroy</p><p> };</p><p></p><p> })();</p><p></p><p> window.AP = AudioPlayer;</p><p></p><p>})(window);</p><p></p><p></p><p></p><p>// test image for web notifications</p><p>var iconImage = 'http://nitrohotel.stream/images/headset.png';</p><p></p><p>AP.init({</p><p> playList: [</p><p> {'icon': iconImage, 'title': 'Nitro FM', 'file': 'http://perseus.shoutca.st:8580/stream'},</p><p> </p><p> ]</p><p>});</p><p></p><p>setTimeout(function() {</p><p> $('.overlay-ribbon').fadeOut('fast');</p><p>}, 1000); // <-- time in milliseconds</p><p></script>[/PHP]</p></blockquote><p></p>
[QUOTE="EngeldesTodes, post: 418093, member: 2432"] the rscript and client radio and client.php [doublepost=1504653933,1504652107][/doublepost]rscript.php [PHP]<script> ; (function(window, undefined) { 'use strict'; var AudioPlayer = (function() { // Player vars var player = document.getElementById('ap'), playBtn, prevBtn, nextBtn, plBtn, repeatBtn, volumeBtn, progressBar, preloadBar, curTime, durTime, trackTitle, audio, index = 0, playList, volumeBar, volumeLength, repeating = false, seeking = false, rightClick = false, apActive = false, // playlist vars pl, plLi, // settings settings = { volume: 0.3, autoPlay: false, notification: true, playList: [] }; function init(options) { if (!('classList' in document.documentElement)) { return false; } if (apActive || player === null) { return; } settings = extend(settings, options); // get player elements playBtn = player.querySelector('.ap-toggle-btn'); prevBtn = player.querySelector('.ap-prev-btn'); nextBtn = player.querySelector('.ap-next-btn'); repeatBtn = player.querySelector('.ap-repeat-btn'); volumeBtn = player.querySelector('.ap-volume-btn'); plBtn = player.querySelector('.ap-playlist-btn'); curTime = player.querySelector('.ap-time--current'); durTime = player.querySelector('.ap-time--duration'); trackTitle = player.querySelector('.ap-title'); progressBar = player.querySelector('.ap-bar'); preloadBar = player.querySelector('.ap-preload-bar'); volumeBar = player.querySelector('.ap-volume-bar'); playList = settings.playList; playBtn.addEventListener('click', playToggle, false); volumeBtn.addEventListener('click', volumeToggle, false); repeatBtn.addEventListener('click', repeatToggle, false); progressBar.parentNode.parentNode.addEventListener('mousedown', handlerBar, false); progressBar.parentNode.parentNode.addEventListener('mousemove', seek, false); document.documentElement.addEventListener('mouseup', seekingFalse, false); volumeBar.parentNode.parentNode.addEventListener('mousedown', handlerVol, false); volumeBar.parentNode.parentNode.addEventListener('mousemove', setVolume); document.documentElement.addEventListener('mouseup', seekingFalse, false); prevBtn.addEventListener('click', prev, false); nextBtn.addEventListener('click', next, false); apActive = true; // Create playlist renderPL(); plBtn.addEventListener('click', plToggle, false); // Create audio object audio = new Audio(); audio.volume = settings.volume; if (isEmptyList()) { empty(); return; } audio.src = playList[index].file; audio.preload = 'auto'; trackTitle.innerHTML = playList[index].title; volumeBar.style.height = audio.volume * 100 + '%'; volumeLength = volumeBar.css('height'); audio.addEventListener('error', error, false); audio.addEventListener('timeupdate', update, false); audio.addEventListener('ended', doEnd, false); if (settings.autoPlay) { audio.play(); playBtn.classList.add('playing'); plLi[index].classList.add('pl-current'); } } //'<img src="http://switchhotel.net/app/tpl/skins/SwitchCMS/images/logo2.png" />' ; /** * PlayList methods */ function renderPL() { var html = []; var tpl = '<li data-track="{count}">' + '<div class="pl-number">' + '<div class="pl-count">' + '<svg fill="#000000" height="20" viewBox="0 0 24 24" width="20" xmlns="http://www.w3.org/2000/svg">' + '<path d="M0 0h24v24H0z" fill="none"/>' + '<path d="M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z"/>' + '</svg>' + '</div>' + '<div class="pl-playing">' + '<div class="eq">' + '<div class="eq-bar"></div>' + '<div class="eq-bar"></div>' + '<div class="eq-bar"></div>' + '</div>' + '</div>' + '</div>' + '<div class="pl-title"><b>{title}</b></div>' + '<button class="pl-remove">' + '<svg fill="#000000" height="20" viewBox="0 0 24 24" width="20" xmlns="http://www.w3.org/2000/svg">' + '<path d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"/>' + '<path d="M0 0h24v24H0z" fill="none"/>' + '</svg>' + '</button>' + '</li>'; playList.forEach(function(item, i) { html.push( tpl.replace('{count}', i).replace('{title}', item.title) ); }); pl = create('div', { 'className': 'pl-container hide', 'id': 'pl', 'innerHTML': !isEmptyList() ? '<ul class="pl-list">' + html.join('') + '</ul>' : '<div class="pl-empty">PlayList is empty</div>' }); player.parentNode.insertBefore(pl, player.nextSibling); plLi = pl.querySelectorAll('li'); pl.addEventListener('click', listHandler, false); } function listHandler(evt) { evt.preventDefault(); if (evt.target.className === 'pl-title') { var current = parseInt(evt.target.parentNode.getAttribute('data-track'), 10); index = current; play(); plActive(); } else { var target = evt.target; while (target.className !== pl.className) { if (target.className === 'pl-remove') { var isDel = parseInt(target.parentNode.getAttribute('data-track'), 10); playList.splice(isDel, 1); target.parentNode.parentNode.removeChild(target.parentNode); plLi = pl.querySelectorAll('li'); [].forEach.call(plLi, function(el, i) { el.setAttribute('data-track', i); }); if (!audio.paused) { if (isDel === index) { play(); } } else { if (isEmptyList()) { empty(); } else { // audio.currentTime = 0; audio.src = playList[index].file; document.title = trackTitle.innerHTML = playList[index].title; progressBar.style.width = 0; } } if (isDel < index) { index--; } return; } target = target.parentNode; } } } function plActive() { if (audio.paused) { plLi[index].classList.remove('pl-current'); return; } var current = index; for (var i = 0, len = plLi.length; len > i; i++) { plLi[i].classList.remove('pl-current'); } plLi[current].classList.add('pl-current'); } /** * Player methods */ function error() { !isEmptyList() && next(); } function play() { index = (index > playList.length - 1) ? 0 : index; if (index < 0) index = playList.length - 1; if (isEmptyList()) { empty(); return; } audio.src = playList[index].file; audio.preload = 'auto'; document.title = trackTitle.innerHTML = playList[index].title; audio.play(); notify(playList[index].title, { icon: playList[index].icon, body: 'Now playing', tag: 'music-player' }); playBtn.classList.add('playing'); plActive(); } function prev() { index = index - 1; play(); } function next() { index = index + 1; play(); } function isEmptyList() { return playList.length === 0; } function empty() { audio.pause(); audio.src = ''; trackTitle.innerHTML = 'queue is empty'; curTime.innerHTML = '--'; durTime.innerHTML = '--'; progressBar.style.width = 0; preloadBar.style.width = 0; playBtn.classList.remove('playing'); pl.innerHTML = '<div class="pl-empty">PlayList is empty</div>'; } function playToggle() { if (isEmptyList()) { return; } if (audio.paused) { audio.play(); notify(playList[index].title, { icon: playList[index].icon, body: 'Now playing' }); this.classList.add('playing'); } else { audio.pause(); this.classList.remove('playing'); } plActive(); } function volumeToggle() { if (audio.muted) { if (parseInt(volumeLength, 10) === 0) { volumeBar.style.height = '100%'; audio.volume = 1; } else { volumeBar.style.height = volumeLength; } audio.muted = false; this.classList.remove('muted'); } else { audio.muted = true; volumeBar.style.height = 0; this.classList.add('muted'); } } function repeatToggle() { var repeat = this.classList; if (repeat.contains('ap-active')) { repeating = false; repeat.remove('ap-active'); } else { repeating = true; repeat.add('ap-active'); } } function plToggle() { this.classList.toggle('ap-active'); pl.classList.toggle('hide'); } function update() { if (audio.readyState === 0) return; var barlength = Math.round(audio.currentTime * (100 / audio.duration)); progressBar.style.width = barlength + '%'; var curMins = Math.floor(audio.currentTime / 60), curSecs = Math.floor(audio.currentTime - curMins * 60), mins = Math.floor(audio.duration / 60), secs = Math.floor(audio.duration - mins * 60); (curSecs < 10) && (curSecs = '0' + curSecs); (secs < 10) && (secs = '0' + secs); curTime.innerHTML = curMins + ':' + curSecs; durTime.innerHTML = mins + ':' + secs; var buffered = audio.buffered; if (buffered.length) { var loaded = Math.round(100 * buffered.end(0) / audio.duration); preloadBar.style.width = loaded + '%'; } } function doEnd() { if (index === playList.length - 1) { if (!repeating) { audio.pause(); plActive(); playBtn.classList.remove('playing'); return; } else { index = 0; play(); } } else { index = (index === playList.length - 1) ? 0 : index + 1; play(); } } function moveBar(evt, el, dir) { var value; if (dir === 'horizontal') { value = Math.round((evt.clientX - el.offset().left) * 100 / el.parentNode.offsetWidth); el.style.width = value + '%'; return value; } else { var offset = el.offset().top + el.offsetHeight; value = Math.round((offset - evt.clientY)); if (value > 100) value = 100; if (value < 0) value = 0; volumeBar.style.height = value + '%'; return value; } } function handlerBar(evt) { rightClick = (evt.which === 3) ? true : false; seeking = true; seek(evt); } function handlerVol(evt) { rightClick = (evt.which === 3) ? true : false; seeking = true; setVolume(evt); } function seek(evt) { if (seeking && rightClick === false && audio.readyState !== 0) { var value = moveBar(evt, progressBar, 'horizontal'); audio.currentTime = audio.duration * (value / 100); } } function seekingFalse() { seeking = false; } function setVolume(evt) { volumeLength = volumeBar.css('height'); if (seeking && rightClick === false) { var value = moveBar(evt, volumeBar.parentNode, 'vertical') / 100; if (value <= 0) { audio.volume = 0; volumeBtn.classList.add('muted'); } else { if (audio.muted) audio.muted = false; audio.volume = value; volumeBtn.classList.remove('muted'); } } } function notify(title, attr) { if (!settings.notification) { return; } if (window.Notification === undefined) { return; } window.Notification.requestPermission(function(access) { if (access === 'granted') { var notice = new Notification(title.substr(0, 110), attr); notice.onshow = function() { setTimeout(function() { notice.close(); }, 5000); } // notice.onclose = function() { // if(noticeTimer) { // clearTimeout(noticeTimer); // } // } } }) } /* Destroy method. Clear All */ function destroy() { if (!apActive) return; playBtn.removeEventListener('click', playToggle, false); volumeBtn.removeEventListener('click', volumeToggle, false); repeatBtn.removeEventListener('click', repeatToggle, false); plBtn.removeEventListener('click', plToggle, false); progressBar.parentNode.parentNode.removeEventListener('mousedown', handlerBar, false); progressBar.parentNode.parentNode.removeEventListener('mousemove', seek, false); document.documentElement.removeEventListener('mouseup', seekingFalse, false); volumeBar.parentNode.parentNode.removeEventListener('mousedown', handlerVol, false); volumeBar.parentNode.parentNode.removeEventListener('mousemove', setVolume); document.documentElement.removeEventListener('mouseup', seekingFalse, false); prevBtn.removeEventListener('click', prev, false); nextBtn.removeEventListener('click', next, false); audio.removeEventListener('error', error, false); audio.removeEventListener('timeupdate', update, false); audio.removeEventListener('ended', doEnd, false); player.parentNode.removeChild(player); // Playlist pl.removeEventListener('click', listHandler, false); pl.parentNode.removeChild(pl); audio.pause(); apActive = false; } /** * Helpers */ function extend(defaults, options) { for (var name in options) { if (defaults.hasOwnProperty(name)) { defaults[name] = options[name]; } } return defaults; } function create(el, attr) { var element = document.createElement(el); if (attr) { for (var name in attr) { if (element[name] !== undefined) { element[name] = attr[name]; } } } return element; } Element.prototype.offset = function() { var el = this.getBoundingClientRect(), scrollLeft = window.pageXOffset || document.documentElement.scrollLeft, scrollTop = window.pageYOffset || document.documentElement.scrollTop; return { top: el.top + scrollTop, left: el.left + scrollLeft }; }; Element.prototype.css = function(attr) { if (typeof attr === 'string') { return getComputedStyle(this, '')[attr]; } else if (typeof attr === 'object') { for (var name in attr) { if (this.style[name] !== undefined) { this.style[name] = attr[name]; } } } }; /** * Public methods */ return { init: init, destroy: destroy }; })(); window.AP = AudioPlayer; })(window); // test image for web notifications var iconImage = 'http://nitrohotel.stream/images/headset.png'; AP.init({ playList: [ {'icon': iconImage, 'title': 'Nitro FM', 'file': 'http://perseus.shoutca.st:8580/stream'}, ] }); setTimeout(function() { $('.overlay-ribbon').fadeOut('fast'); }, 1000); // <-- time in milliseconds </script>[/PHP] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Server Development
Habbo Retros
Habbo Q&A
Radio PLayer not working or finding my radio
Top