forked from marcusbusby/relaxing_sounds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
104 lines (98 loc) · 2.64 KB
/
script.js
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
var soundArray = [];
var uniqueSoundArray = [];
var randomPlaylistName = ['Homeless Planes',
'Disastrous Rule',
'Ethereal Spade',
'Cloistered Fifth',
'Broad Babies',
'Fragile Fire',
'Rapid Rice',
'Exciting Pain',
'Fretful Cook',
'Young Yoke',
'Psychedelic Need',
'Abnormal Account',
'Aware Beginner',
'Super Scene',
'Frantic Week',
'Scintillating Look',
'Simplistic Cord',
'Motionless Mass',
'Utopian Apparatus',
'Chunky Bushes',
'Steadfast Salt',
'Low Afterthought',
'Proud Engine',
'Marvelous Egg',
'Shallow Snow',
'Unarmed Giraffe',
'Fearless Pancake',
'Sable System',
'Sophisticated Wilderness',
'Perfect Feeling',
'Big Bean',
'Rhetorical Pizzas',
'Elastic Twig',
'Windy Week',
'Disillusioned Time',
'Combative Crime',
'Sudden Pocket',
'Youthful Tiger',
'Vengeful Nest',
'Brown Baby']
$('.audio_container').click(function() {
$(this).css('border','6px solid green')
tempJson = {};
tempJson["id"] = $(this).find('audio').attr('id');
tempJson["vol"] = $(this).find('audio')[0].volume;
if (uniqueSoundArray.indexOf(tempJson["id"]) == -1) {
uniqueSoundArray.push(tempJson["id"]);
soundArray.push(tempJson);
$('#sound_playlist').append('<li><b>'+tempJson.id+'</b> | <b>'+Math.round(tempJson.vol*10000)/100+'%</b><i class="fa fa-times"></i></li>')
}
})
$('#play').click(function() {
for (var i=0;i<uniqueSoundArray.length;i++) {
document.getElementById(uniqueSoundArray[i]).play();
}
})
$("#play_list").on('click', '.fa-times', function() {
var id = $(this).prev().prev().html();
$(this).parent().remove();
$('#'+id).parent().parent().parent().css('border','6px solid indianred');
$('#'+id)[0].pause(); // Stop playing
$('#'+id)[0].currentTime = 0; // Reset time
for (var i=0;i<uniqueSoundArray.length;i++) {
if (uniqueSoundArray[i] == id) {
uniqueSoundArray.splice(i,1)
soundArray.splice(i,1);
}
}
})
$('#save').click(function() {
tempJson = {};
tempJson["name"] = $('#playlist_name').val();
soundArray.push(tempJson)
console.log(soundArray);
})
$('#cancel').click(function() {
$('audio').each(function(){
this.pause(); // Stop playing
this.currentTime = 0; // Reset time
});
soundArray = [];
uniqueSoundArray = [];
$('#playlist_name').val('');
$('.audio_container').css('border','6px solid indianred');
$('#sound_playlist li').remove();
})
$('#random').click(function() {
$('#cancel').click();
var randNum = Math.round((Math.random()*8));
var randNumC = Math.round((Math.random()*40));
$('#playlist_name').val(randomPlaylistName[randNumC]);
for (var i=0;i<randNum;i++) {
var randNumB = Math.round((Math.random()*8));
$('#sound_container').children()[randNumB].click()
}
})