Sounds: subtler sounds

This change sets different sounds to different volume levels, and
replaces the Play sound with one that sounds different than the Add
sound.
This commit is contained in:
Feross Aboukhadijeh
2016-03-23 20:44:40 -07:00
parent 1f2985bbc3
commit 4895fb930c
3 changed files with 48 additions and 21 deletions

View File

@@ -25,14 +25,38 @@ module.exports = {
ROOT_PATH: __dirname,
STATIC_PATH: path.join(__dirname, 'static'),
SOUND_ADD: 'file://' + path.join(__dirname, 'static', 'sound', 'add.wav'),
SOUND_DELETE: 'file://' + path.join(__dirname, 'static', 'sound', 'delete.wav'),
SOUND_DISABLE: 'file://' + path.join(__dirname, 'static', 'sound', 'disable.wav'),
SOUND_DONE: 'file://' + path.join(__dirname, 'static', 'sound', 'done.wav'),
SOUND_ENABLE: 'file://' + path.join(__dirname, 'static', 'sound', 'enable.wav'),
SOUND_ERROR: 'file://' + path.join(__dirname, 'static', 'sound', 'error.wav'),
SOUND_PLAY: 'file://' + path.join(__dirname, 'static', 'sound', 'play.wav'),
SOUND_STARTUP: 'file://' + path.join(__dirname, 'static', 'sound', 'startup.wav')
SOUND_ADD: {
url: 'file://' + path.join(__dirname, 'static', 'sound', 'add.wav'),
volume: 0.2
},
SOUND_DELETE: {
url: 'file://' + path.join(__dirname, 'static', 'sound', 'delete.wav'),
volume: 0.1
},
SOUND_DISABLE: {
url: 'file://' + path.join(__dirname, 'static', 'sound', 'disable.wav'),
volume: 0.2
},
SOUND_DONE: {
url: 'file://' + path.join(__dirname, 'static', 'sound', 'done.wav'),
volume: 0.2
},
SOUND_ENABLE: {
url: 'file://' + path.join(__dirname, 'static', 'sound', 'enable.wav'),
volume: 0.2
},
SOUND_ERROR: {
url: 'file://' + path.join(__dirname, 'static', 'sound', 'error.wav'),
volume: 0.2
},
SOUND_PLAY: {
url: 'file://' + path.join(__dirname, 'static', 'sound', 'play.wav'),
volume: 0.2
},
SOUND_STARTUP: {
url: 'file://' + path.join(__dirname, 'static', 'sound', 'startup.wav'),
volume: 0.4
}
}
function isProduction () {

View File

@@ -131,7 +131,7 @@ function init () {
// Done! Ideally we want to get here <100ms after the user clicks the app
document.querySelector('.loading').remove() /* TODO: no spinner once fast enough */
playInterfaceSound(config.SOUND_STARTUP)
playInterfaceSound('STARTUP')
console.timeEnd('init')
}
@@ -423,7 +423,7 @@ function addTorrentToList (torrent) {
infoHash: torrent.infoHash
})
saveState()
playInterfaceSound(config.SOUND_ADD)
playInterfaceSound('ADD')
}
}
@@ -667,13 +667,13 @@ function stopServer () {
// Opens the video player
function openPlayer (torrentSummary, index, cb) {
var torrent = state.client.get(torrentSummary.infoHash)
if (!torrent || !torrent.done) playInterfaceSound(config.SOUND_PLAY)
if (!torrent || !torrent.done) playInterfaceSound('PLAY')
torrentSummary.playStatus = 'requested'
update()
var timeout = setTimeout(function () {
torrentSummary.playStatus = 'timeout' /* no seeders available? */
playInterfaceSound(config.SOUND_ERROR)
playInterfaceSound('ERROR')
update()
}, 10000) /* give it a few seconds */
@@ -681,7 +681,7 @@ function openPlayer (torrentSummary, index, cb) {
clearTimeout(timeout)
if (err) {
torrentSummary.playStatus = 'unplayable'
playInterfaceSound(config.SOUND_ERROR)
playInterfaceSound('ERROR')
update()
return onError(err)
}
@@ -741,11 +741,11 @@ function toggleTorrent (torrentSummary) {
if (torrentSummary.status === 'paused') {
torrentSummary.status = 'new'
startTorrentingSummary(torrentSummary)
playInterfaceSound(config.SOUND_ENABLE)
playInterfaceSound('ENABLE')
} else {
torrentSummary.status = 'paused'
stopTorrenting(torrentSummary.infoHash)
playInterfaceSound(config.SOUND_DISABLE)
playInterfaceSound('DISABLE')
}
}
@@ -758,7 +758,7 @@ function deleteTorrent (torrentSummary) {
if (index > -1) state.saved.torrents.splice(index, 1)
saveState()
state.location.clearForward() // prevent user from going forward to a deleted torrent
playInterfaceSound(config.SOUND_DELETE)
playInterfaceSound('DELETE')
}
function toggleSelectTorrent (infoHash) {
@@ -812,7 +812,7 @@ function restoreBounds () {
function onError (err) {
console.error(err.stack || err)
playInterfaceSound(config.SOUND_ERROR)
playInterfaceSound('ERROR')
state.errors.push({
time: new Date().getTime(),
message: err.message || err
@@ -836,12 +836,15 @@ function showDoneNotification (torrent) {
window.focus()
}
playInterfaceSound(config.SOUND_DONE)
playInterfaceSound('DONE')
}
function playInterfaceSound (url) {
function playInterfaceSound (name) {
var sound = config[`SOUND_${name}`]
if (!sound) throw new Error('Invalid sound name')
var audio = new window.Audio()
audio.volume = 0.3
audio.src = url
audio.volume = sound.volume
audio.src = sound.url
audio.play()
}

Binary file not shown.