-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
89 lines (86 loc) · 3.07 KB
/
index.php
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
$dir = 'Music';
$filenames = scandir($dir);
$no_of_files = count($filenames);
?>
<html>
<head>
<title>AudioWeb</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
function play(element){
var audio = document.getElementById(element);
audio.play();
}
function onlyPlayOneIn(container) {
container.addEventListener("play", function(event) {
audio_elements = container.getElementsByTagName("audio")
for(i=0; i < audio_elements.length; i++) {
audio_element = audio_elements[i];
if (audio_element !== event.target) {
audio_element.pause();
audio_element.currentTime=0;
}
}
}, true);
}
document.addEventListener("DOMContentLoaded", function() {
onlyPlayOneIn(document.body);
});
function universalPlay(){
var flag = 0;
var audio = document.getElementsByTagName('audio');
for(i=0;i<audio.length;i++){
if(audio[i].currentTime > 0 && audio[i].paused){
audio[i].play();
flag = 1;
break;
}
}
if(flag == 0){
audio[0].play();
}
}
function pauseAllAudio() {
var sounds = document.getElementsByTagName('audio');
for(i=0; i<sounds.length; i++){
sounds[i].pause();
}
}
function stopAllAudio(){
var audio = document.getElementsByTagName('audio');
for(i=0;i<audio.length;i++){
audio[i].pause();
audio[i].currentTime = 0;
}
}
</script>
</head>
<body>
<h2 style = 'text-align:center'> Audio Web</h2>
<div style = 'text-align:center'>
<a href="#" class="btn btn-info btn-lg" onclick="universalPlay()">
<span class="glyphicon glyphicon-play"></span> Play
</a>
<a href="#" class="btn btn-info btn-lg" onclick="pauseAllAudio()">
<span class="glyphicon glyphicon-play"></span> Pause
</a>
<a href="#" class="btn btn-info btn-lg" onclick="stopAllAudio()">
<span class="glyphicon glyphicon-play"></span> Stop
</a><br><br>
</div>
<div style = 'text-align:center' class = "row">
<?php
for($i=2,$n=1;$i<$no_of_files;$i++,$n++){
?>
<a href="#" class="btn btn-primary " onclick="play('<?php echo $filenames[$i];?>')"><span class="glyphicon glyphicon-music"></span> <?php echo '#'.$n.' '.trim($filenames[$i],".mp3");?></a>
<audio id="<?php echo $filenames[$i];?>" src="<?php echo $dir.'\\'.$filenames[$i];?>" ></audio>
<?php
}
?>
</div>
</body>
</html>