Skip to content

Commit

Permalink
11. Playing audio
Browse files Browse the repository at this point in the history
  • Loading branch information
ApayRus committed Jun 27, 2022
1 parent f468ce3 commit c9521ff
Show file tree
Hide file tree
Showing 47 changed files with 28 additions and 0 deletions.
23 changes: 23 additions & 0 deletions components/Keyboard.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import Key from './Key.js'

const getAudioFileName = (keyContent, shiftKey) => {
const { main, mainName, shifted, shiftedName, code } = keyContent

let fileName

if (shiftKey) {
// will be returned 1 of 3 values (if it exist). priority to the first one
fileName = shiftedName || shifted || code
} else {
fileName = mainName || main || code
}

// to have a guarantee, that everything is written in the same (lower) case
return fileName.toLowerCase()
}

const Keyboard = {
template: `
<div>activeKey: {{activeKey}}</div>
Expand Down Expand Up @@ -71,6 +87,13 @@ const Keyboard = {
this.keyboardData = keyboardData
},
setActiveKey(keyContent) {
/* add: */
const fileName = getAudioFileName(keyContent, this.shiftKey)
const audio = new Audio(
`./keyboardData/${this.currentLang}/${fileName}.mp3`
)
audio.play()
//
this.activeKey = keyContent
clearTimeout(this.timeout)
this.timeout = setTimeout(() => (this.activeKey = { code: '' }), 1000)
Expand Down
5 changes: 5 additions & 0 deletions keyboardData/ar.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,31 @@ const keyboard = [
{
code: 'Digit1',
main: '١',
mainName: '1',
shifted: '!'
},
{
code: 'Digit2',
main: '٢',
mainName: '2',
shifted: '@'
},
{
code: 'Digit3',
main: '٣',
mainName: '3',
shifted: '#'
},
{
code: 'Digit4',
main: '٤',
mainName: '4',
shifted: '$'
},
{
code: 'Digit5',
main: '٥',
mainName: '5',
shifted: '٪'
}
],
Expand Down
Binary file added keyboardData/ar/1.mp3
Binary file not shown.
Binary file added keyboardData/ar/2.mp3
Binary file not shown.
Binary file added keyboardData/ar/3.mp3
Binary file not shown.
Binary file added keyboardData/ar/4.mp3
Binary file not shown.
Binary file added keyboardData/ar/5.mp3
Binary file not shown.
Binary file added keyboardData/ar/ث.mp3
Binary file not shown.
Binary file added keyboardData/ar/ص.mp3
Binary file not shown.
Binary file added keyboardData/ar/ض.mp3
Binary file not shown.
Binary file added keyboardData/ar/ق.mp3
Binary file not shown.
Binary file added keyboardData/en/1.mp3
Binary file not shown.
Binary file added keyboardData/en/2.mp3
Binary file not shown.
Binary file added keyboardData/en/3.mp3
Binary file not shown.
Binary file added keyboardData/en/4.mp3
Binary file not shown.
Binary file added keyboardData/en/5.mp3
Binary file not shown.
Binary file added keyboardData/en/at sign.mp3
Binary file not shown.
Binary file added keyboardData/en/backslash.mp3
Binary file not shown.
Binary file added keyboardData/en/dollar sign.mp3
Binary file not shown.
Binary file added keyboardData/en/e.mp3
Binary file not shown.
Binary file added keyboardData/en/escape.mp3
Binary file not shown.
Binary file added keyboardData/en/exclamation mark.mp3
Binary file not shown.
Binary file added keyboardData/en/f1.mp3
Binary file not shown.
Binary file added keyboardData/en/f2.mp3
Binary file not shown.
Binary file added keyboardData/en/f3.mp3
Binary file not shown.
Binary file added keyboardData/en/f4.mp3
Binary file not shown.
Binary file added keyboardData/en/f5.mp3
Binary file not shown.
Binary file added keyboardData/en/f6.mp3
Binary file not shown.
Binary file added keyboardData/en/hash.mp3
Binary file not shown.
Binary file added keyboardData/en/left shift.mp3
Binary file not shown.
Binary file added keyboardData/en/percent sign.mp3
Binary file not shown.
Binary file added keyboardData/en/q.mp3
Binary file not shown.
Binary file added keyboardData/en/r.mp3
Binary file not shown.
Binary file added keyboardData/en/right shift.mp3
Binary file not shown.
Binary file added keyboardData/en/tab.mp3
Binary file not shown.
Binary file added keyboardData/en/tilde.mp3
Binary file not shown.
Binary file added keyboardData/en/w.mp3
Binary file not shown.
Binary file added keyboardData/ru/1.mp3
Binary file not shown.
Binary file added keyboardData/ru/2.mp3
Binary file not shown.
Binary file added keyboardData/ru/3.mp3
Binary file not shown.
Binary file added keyboardData/ru/4.mp3
Binary file not shown.
Binary file added keyboardData/ru/5.mp3
Binary file not shown.
Binary file added keyboardData/ru/й.mp3
Binary file not shown.
Binary file added keyboardData/ru/к.mp3
Binary file not shown.
Binary file added keyboardData/ru/у.mp3
Binary file not shown.
Binary file added keyboardData/ru/ц.mp3
Binary file not shown.
Binary file added keyboardData/ru/ё.mp3
Binary file not shown.

0 comments on commit c9521ff

Please sign in to comment.