-
Notifications
You must be signed in to change notification settings - Fork 3
/
audioplayer.htm
57 lines (44 loc) · 2.79 KB
/
audioplayer.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<html>
<body>
<head><meta name="viewport" content="width=device-width, initial-scale=1.0"></head>
<header><button id="scanBtn" class="btn-scan">Scan</button></header>
<main style="display: none;"><a id="output" style="white-space: pre;" download='pulse.csv'></a></main>
<input type="file" id="file-upload" accept="audio/*" multiple /> <!-- style='background:grey' -->
<button id="shot">►</button>
<button onclick='audio.onended()'>⏭</button> <!-- -->
<select onclick='i=this.selectedIndex-1;audio.onended()'></select>
<script>
var pause=true, player=true, concat=true, repeat=false //edit here
if(location.search.slice(1)=='0') pause=!pause //?0
var audio=new Audio(), filesArray=[], i=0
var pls, j, level=0 //advaced playlist
if(player) audio=document.createElement('audio');audio.controls=true;document.body.append(audio) //
document.getElementById('file-upload').onchange = function(e) {
filesArray = concat? filesArray.concat(Array.from(this.files)):Array.from(this.files); //var
Array.from(this.files).forEach(function(it) {var option=document.createElement("option");option.text=it.name;document.querySelector('select').add(option)})
i--;audio.onended()
but.textContent="\u2759\u2759"
}
var but=document.querySelector('#shot')
but.onclick = pause? playpause:nexttrack
but.oncontextmenu = function(e) {e.preventDefault(); pause? nexttrack():playpause()} //rightclick //
audio.onended = function() {
if(!level)
{i++; if(repeat && i==filesArray.length) i=0
if(filesArray[i].name.match(/m3u8?$/)) {var reader=new FileReader();reader.onload=function(){m3(reader.result)};reader.readAsText(filesArray[i])} else //
{audio.src=URL.createObjectURL(filesArray[i]);audio.play()}; document.title=filesArray[i].name}
else
{j++; if(j==pls.length) {level=0;audio.onended();return} //level--
{audio.src=pls[j];audio.play()}; document.title=audio.src}
}
function playpause() {if(audio.paused) {audio.play();but.textContent="\u2759\u2759"} else {audio.pause();but.textContent="\u25BA"}}
function nexttrack() {audio.onended()}
function m3(that) {var tmp=that.match(/^(?!#)(?!\s).*$/mg).map(encodeURI); level++;pls=tmp;j=-1;audio.onended()}
if(location.search.slice(1)>=1) {var event=new Event('contextmenu');window.setInterval(function(){document.querySelector('#scanBtn').dispatchEvent(event)}, location.search.slice(1)*60000)} //?1 hr every 1 min
output.onclick=function(){output.href='data:,'+encodeURI(this.innerHTML.match(/Finished\.\n([^]*)/)[1])} //download
if(isNaN(location.search.slice(1))) {level=1;pls=location.search.slice(1).split('%0A');j=-1;audio.onended()} //?http... open stream
audio.onerror=function(){if(audio.src.slice(-1)!=";") {audio.src+=";"; audio.play()}} //SHOUTcast1
</script>
<script src="webapp.bundle.js"></script>
</body>
</html>