mirror of
https://github.com/jcreek/SelectionWheel.git
synced 2026-07-12 18:53:45 +00:00
feat(#11): Add spinner audio and mute button
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,17 @@
|
|||||||
|
export default {
|
||||||
|
pauseAudio(audio: HTMLAudioElement) {
|
||||||
|
audio.pause();
|
||||||
|
},
|
||||||
|
playAudio(audio: HTMLAudioElement) {
|
||||||
|
audio.play();
|
||||||
|
},
|
||||||
|
stopAudio(audio: HTMLAudioElement) {
|
||||||
|
audio.pause();
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
audio.currentTime = 0;
|
||||||
|
},
|
||||||
|
toggleMute(audio: HTMLAudioElement) {
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
audio.muted = !audio.muted;
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
import * as d3 from 'd3';
|
import * as d3 from 'd3';
|
||||||
import loadServiceWorker from './loadServiceWorker';
|
import loadServiceWorker from './loadServiceWorker';
|
||||||
|
import audioControls from './audioControls';
|
||||||
|
import spinnerMp3 from './assets/spinner-sound.mp3';
|
||||||
|
|
||||||
require('./assets/favicon.ico');
|
require('./assets/favicon.ico');
|
||||||
require('./assets/android-chrome-192x192.png');
|
require('./assets/android-chrome-192x192.png');
|
||||||
@@ -9,6 +11,11 @@ require('./assets/favicon-16x16.png');
|
|||||||
require('./assets/favicon-32x32.png');
|
require('./assets/favicon-32x32.png');
|
||||||
require('./styles/main.scss');
|
require('./styles/main.scss');
|
||||||
|
|
||||||
|
const wheelSpinningSound = new Audio(spinnerMp3);
|
||||||
|
if (window.localStorage.audioMuteSetting) {
|
||||||
|
wheelSpinningSound.muted = window.localStorage.audioMuteSetting;
|
||||||
|
}
|
||||||
|
|
||||||
const padding = {
|
const padding = {
|
||||||
top: 20,
|
top: 20,
|
||||||
right: 40,
|
right: 40,
|
||||||
@@ -159,6 +166,8 @@ function drawWheel() {
|
|||||||
stopSpinning();
|
stopSpinning();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
audioControls.playAudio(wheelSpinningSound);
|
||||||
const ps = 360 / data.length;
|
const ps = 360 / data.length;
|
||||||
const rng = Math.floor(Math.random() * 1440 + 360);
|
const rng = Math.floor(Math.random() * 1440 + 360);
|
||||||
|
|
||||||
@@ -185,6 +194,8 @@ function drawWheel() {
|
|||||||
d3.select('#question h1').text(data[picked].label.trim());
|
d3.select('#question h1').text(data[picked].label.trim());
|
||||||
oldrotation = rotation;
|
oldrotation = rotation;
|
||||||
|
|
||||||
|
audioControls.stopAudio(wheelSpinningSound);
|
||||||
|
|
||||||
/* Get the result value from object "data" */
|
/* Get the result value from object "data" */
|
||||||
// console.log(data[picked].value);
|
// console.log(data[picked].value);
|
||||||
|
|
||||||
@@ -200,6 +211,13 @@ function drawWheel() {
|
|||||||
|
|
||||||
function startOver() {
|
function startOver() {
|
||||||
stopSpinning();
|
stopSpinning();
|
||||||
|
audioControls.stopAudio(wheelSpinningSound);
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleMute() {
|
||||||
|
audioControls.toggleMute(wheelSpinningSound);
|
||||||
|
this.textContent = wheelSpinningSound.muted ? 'Unmute' : 'Mute';
|
||||||
|
window.localStorage.audioMuteSetting = wheelSpinningSound.muted;
|
||||||
}
|
}
|
||||||
|
|
||||||
function startSpinning() {
|
function startSpinning() {
|
||||||
@@ -231,7 +249,14 @@ function startSpinning() {
|
|||||||
startOverElement.setAttribute('role', 'button');
|
startOverElement.setAttribute('role', 'button');
|
||||||
startOverElement.onclick = startOver;
|
startOverElement.onclick = startOver;
|
||||||
startOverElement.textContent = 'Start over';
|
startOverElement.textContent = 'Start over';
|
||||||
|
const muteElement = document.createElement('button');
|
||||||
|
muteElement.setAttribute('id', 'mute');
|
||||||
|
muteElement.setAttribute('class', 'button button-red');
|
||||||
|
muteElement.setAttribute('role', 'button');
|
||||||
|
muteElement.onclick = toggleMute;
|
||||||
|
muteElement.textContent = 'Mute';
|
||||||
chartElement.appendChild(startOverElement);
|
chartElement.appendChild(startOverElement);
|
||||||
|
chartElement.appendChild(muteElement);
|
||||||
document.getElementById('spinner-container').appendChild(chartElement);
|
document.getElementById('spinner-container').appendChild(chartElement);
|
||||||
const questionElement = document.createElement('div');
|
const questionElement = document.createElement('div');
|
||||||
questionElement.setAttribute('id', 'question');
|
questionElement.setAttribute('id', 'question');
|
||||||
|
|||||||
@@ -91,6 +91,12 @@ body {
|
|||||||
left: auto;
|
left: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#mute {
|
||||||
|
position: absolute;
|
||||||
|
top: 140px;
|
||||||
|
left: auto;
|
||||||
|
}
|
||||||
|
|
||||||
#spinner-container {
|
#spinner-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
|||||||
Reference in New Issue
Block a user