Skip to content

Commit 708e4df

Browse files
committed
Handle audio context issue with a click to start button
1 parent 9e084a8 commit 708e4df

File tree

5 files changed

+98
-19
lines changed

5 files changed

+98
-19
lines changed

app/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@
3939
<script src="/public/js/main.js"></script>
4040
</head>
4141
<body>
42+
<div class="click-to-play" id="clickToPlay">
43+
<img
44+
class="play-button"
45+
src="/public/images/play-button.svg"
46+
alt="Click to play"
47+
onmouseover="playButtonHover(this);"
48+
onmouseout="playButtonUnhover(this);"
49+
onclick="playButtonClick(this);"/>
50+
</div>
4251
<header>
4352
<h1 class="header-text">
4453
Project Audio for GitHub&nbsp;

app/public/css/main.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,26 @@ html,body{
5858
visibility: hidden;
5959
}
6060

61+
.click-to-play{
62+
position: fixed;
63+
top: 0;
64+
left: 0;
65+
background-color: rgba(0, 0, 0, 0.7);
66+
z-index: 1;
67+
width: 100%;
68+
height: 100%;
69+
text-align: center;
70+
}
71+
72+
.play-button{
73+
width: 30rem;
74+
margin-top: 20rem;
75+
}
76+
77+
.play-button:hover{
78+
cursor: pointer;
79+
}
80+
6181
header{
6282
position: relative;;
6383
width: 100%;
Lines changed: 23 additions & 0 deletions
Loading

app/public/images/play-button.svg

Lines changed: 23 additions & 0 deletions
Loading

app/public/js/main.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
var eventQueue = [];
2+
var startConsuming = false;
23
var svg;
34
var element;
45
var drawingArea;
56
var width;
67
var height;
7-
var volume = 0.6;
8+
var volume = 0.5;
89
var ULTIMATE_DREAM_KILLER = false; // https://github.com/debugger22/github-audio/pull/19
910
var orgRepoFilterNames = [];
1011

@@ -139,9 +140,7 @@ $(function(){
139140
loaded_sounds += 1;
140141
if (loaded_sounds == total_sounds) {
141142
all_loaded = true;
142-
setTimeout(playFromQueueExchange1, Math.floor(Math.random() * 1000));
143-
// Starting the second exchange makes music a bad experience
144-
// setTimeout(playFromQueueExchange2, Math.floor(Math.random() * 2000));
143+
setTimeout(playFromQueue, Math.floor(Math.random() * 1000));
145144
}
146145
}
147146

@@ -230,7 +229,11 @@ function playSound(size, type) {
230229
// Following are the n numbers of event consumers
231230
// consuming n events each per second with a random delay between them
232231

233-
function playFromQueueExchange1(){
232+
function playFromQueue(){
233+
if (!startConsuming) {
234+
setTimeout(playFromQueue, Math.floor(Math.random() * 1000) + 500);
235+
return;
236+
}
234237
var event = eventQueue.shift();
235238
if(event != null && event.actor.display_login != null && !shouldEventBeIgnored(event) && svg != null){
236239
playSound(event.actor.display_login.length*1.1, event.type);
@@ -239,20 +242,7 @@ function playFromQueueExchange1(){
239242
}else{
240243
console.log("Ignored ex 1");
241244
}
242-
setTimeout(playFromQueueExchange1, Math.floor(Math.random() * 1000) + 500);
243-
$('.events-remaining-value').html(eventQueue.length);
244-
}
245-
246-
function playFromQueueExchange2(){
247-
var event = eventQueue.shift();
248-
if(event != null && event.actor.display_login != null && !shouldEventBeIgnored(event) && svg != null){
249-
playSound(event.actor.display_login.length, event.type);
250-
if(!document.hidden)
251-
drawEvent(event, svg);
252-
}else{
253-
console.log("Ignored ex 2");
254-
}
255-
setTimeout(playFromQueueExchange2, Math.floor(Math.random() * 800) + 500);
245+
setTimeout(playFromQueue, Math.floor(Math.random() * 1000) + 500);
256246
$('.events-remaining-value').html(eventQueue.length);
257247
}
258248

@@ -376,3 +366,17 @@ function drawEvent(data, svg_area) {
376366
$('#area svg g:lt(10)').remove();
377367
}
378368
}
369+
370+
371+
function playButtonHover(e){
372+
e.setAttribute('src', '/public/images/play-button-hover.svg');
373+
}
374+
375+
function playButtonUnhover(e){
376+
e.setAttribute('src', '/public/images/play-button.svg');
377+
}
378+
379+
function playButtonClick(e) {
380+
startConsuming = true;
381+
$('#clickToPlay').remove();
382+
}

0 commit comments

Comments
 (0)