clicktone 0.0.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -7
- package/dist/index.js +18 -17
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +18 -17
- package/dist/index.module.js.map +1 -1
- package/package.json +13 -3
- package/src/index.js +24 -24
package/README.md
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
</div>
|
|
11
11
|
|
|
12
|
-
<p align="center">A simple class
|
|
12
|
+
<p align="center">A simple class that provides a convenient abstraction for handling<br>
|
|
13
|
+
audio playback by web applications, with support for iOS devices.</p>
|
|
13
14
|
<p align="center"><a href="https://n2q8x8.csb.app/">Demo</a></p>
|
|
14
15
|
<br>
|
|
15
16
|
|
|
@@ -30,14 +31,11 @@ import ClickTone from 'clicktone';
|
|
|
30
31
|
|
|
31
32
|
➤ **Usage**
|
|
32
33
|
|
|
33
|
-
<
|
|
34
|
+
<sub>Class uses the Web Audio API, which supports many audio file formats: MP3, WAV, OGG, AAC and others. Please note that not all browsers support these formats.</sub>
|
|
34
35
|
```javascript
|
|
35
|
-
const
|
|
36
|
-
el: '#button',
|
|
37
|
-
sound: 'sound.mp3',
|
|
38
|
-
});
|
|
36
|
+
const clickSound = new ClickTone('./sound.mp3');
|
|
39
37
|
|
|
40
|
-
|
|
38
|
+
myButton.addEventListener('click', () => clickSound.play());
|
|
41
39
|
```
|
|
42
40
|
<br>
|
|
43
41
|
|
package/dist/index.js
CHANGED
|
@@ -11,13 +11,12 @@ $parcel$defineInteropFlag(module.exports);
|
|
|
11
11
|
|
|
12
12
|
$parcel$export(module.exports, "default", () => $4fa36e821943b400$export$2e2bcd8739ae039);
|
|
13
13
|
class $4fa36e821943b400$var$ClickTone {
|
|
14
|
-
constructor(
|
|
15
|
-
this.
|
|
16
|
-
this.sound = sound;
|
|
14
|
+
constructor(file){
|
|
15
|
+
this.file = file;
|
|
17
16
|
this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
|
18
|
-
this.
|
|
17
|
+
this.iOSFixAudioContext();
|
|
19
18
|
}
|
|
20
|
-
|
|
19
|
+
iOSFixAudioContext() {
|
|
21
20
|
if (this.audioContext.state === "suspended" && "ontouchstart" in window) {
|
|
22
21
|
const unlock = ()=>{
|
|
23
22
|
this.audioContext.resume().then(()=>{
|
|
@@ -29,20 +28,22 @@ class $4fa36e821943b400$var$ClickTone {
|
|
|
29
28
|
document.body.addEventListener("touchend", unlock, false);
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
this.playAudio(this.sound);
|
|
31
|
+
audio(url) {
|
|
32
|
+
return new Promise((resolve, reject)=>{
|
|
33
|
+
fetch(url).then((response)=>response.arrayBuffer()).then((buffer)=>this.audioContext.decodeAudioData(buffer)).then((audioData)=>{
|
|
34
|
+
const source = this.audioContext.createBufferSource();
|
|
35
|
+
source.buffer = audioData;
|
|
36
|
+
source.connect(this.audioContext.destination);
|
|
37
|
+
source.start(0);
|
|
38
|
+
resolve();
|
|
39
|
+
}).catch((error)=>{
|
|
40
|
+
reject(error);
|
|
41
|
+
});
|
|
44
42
|
});
|
|
45
43
|
}
|
|
44
|
+
play(url = this.file) {
|
|
45
|
+
return this.audio(url);
|
|
46
|
+
}
|
|
46
47
|
}
|
|
47
48
|
var $4fa36e821943b400$export$2e2bcd8739ae039 = $4fa36e821943b400$var$ClickTone;
|
|
48
49
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;AAAA,MAAM;IACJ,YAAY,
|
|
1
|
+
{"mappings":";;;;;;;;;;;;AAAA,MAAM;IACJ,YAAY,IAAI,CAAE;QAChB,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,YAAY,GAAG,IAAK,CAAA,OAAO,YAAY,IAAI,OAAO,kBAAkB,AAAD;QACxE,IAAI,CAAC,kBAAkB;IACzB;IAEA,qBAAqB;QACnB,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,KAAK,eAAe,kBAAkB,QAAQ;YACvE,MAAM,SAAS;gBACb,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC;oBAC9B,SAAS,IAAI,CAAC,mBAAmB,CAAC,cAAc;oBAChD,SAAS,IAAI,CAAC,mBAAmB,CAAC,YAAY;gBAChD;YACF;YAEA,SAAS,IAAI,CAAC,gBAAgB,CAAC,cAAc,QAAQ;YACrD,SAAS,IAAI,CAAC,gBAAgB,CAAC,YAAY,QAAQ;QACrD;IACF;IAEA,MAAM,GAAG,EAAE;QACT,OAAO,IAAI,QAAQ,CAAC,SAAS;YAC3B,MAAM,KACH,IAAI,CAAC,CAAC,WAAa,SAAS,WAAW,IACvC,IAAI,CAAC,CAAC,SAAW,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,SACnD,IAAI,CAAC,CAAC;gBACL,MAAM,SAAS,IAAI,CAAC,YAAY,CAAC,kBAAkB;gBAEnD,OAAO,MAAM,GAAG;gBAChB,OAAO,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW;gBAC5C,OAAO,KAAK,CAAC;gBAEb;YACF,GACC,KAAK,CAAC,CAAC;gBACN,OAAO;YACT;QACJ;IACF;IAEA,KAAK,MAAM,IAAI,CAAC,IAAI,EAAE;QACpB,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB;AACF;IAEA,2CAAe","sources":["src/index.js"],"sourcesContent":["class ClickTone {\n constructor(file) {\n this.file = file;\n this.audioContext = new (window.AudioContext || window.webkitAudioContext)();\n this.iOSFixAudioContext();\n }\n\n iOSFixAudioContext() {\n if (this.audioContext.state === 'suspended' && 'ontouchstart' in window) {\n const unlock = () => {\n this.audioContext.resume().then(() => {\n document.body.removeEventListener('touchstart', unlock);\n document.body.removeEventListener('touchend', unlock);\n });\n };\n\n document.body.addEventListener('touchstart', unlock, false);\n document.body.addEventListener('touchend', unlock, false);\n }\n }\n\n audio(url) {\n return new Promise((resolve, reject) => {\n fetch(url)\n .then((response) => response.arrayBuffer())\n .then((buffer) => this.audioContext.decodeAudioData(buffer))\n .then((audioData) => {\n const source = this.audioContext.createBufferSource();\n\n source.buffer = audioData;\n source.connect(this.audioContext.destination);\n source.start(0);\n\n resolve();\n })\n .catch((error) => {\n reject(error);\n });\n });\n }\n\n play(url = this.file) {\n return this.audio(url);\n }\n}\n\nexport default ClickTone;\n"],"names":[],"version":3,"file":"index.js.map"}
|
package/dist/index.module.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
class $cf838c15c8b009ba$var$ClickTone {
|
|
2
|
-
constructor(
|
|
3
|
-
this.
|
|
4
|
-
this.sound = sound;
|
|
2
|
+
constructor(file){
|
|
3
|
+
this.file = file;
|
|
5
4
|
this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
|
6
|
-
this.
|
|
5
|
+
this.iOSFixAudioContext();
|
|
7
6
|
}
|
|
8
|
-
|
|
7
|
+
iOSFixAudioContext() {
|
|
9
8
|
if (this.audioContext.state === "suspended" && "ontouchstart" in window) {
|
|
10
9
|
const unlock = ()=>{
|
|
11
10
|
this.audioContext.resume().then(()=>{
|
|
@@ -17,20 +16,22 @@ class $cf838c15c8b009ba$var$ClickTone {
|
|
|
17
16
|
document.body.addEventListener("touchend", unlock, false);
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
this.playAudio(this.sound);
|
|
19
|
+
audio(url) {
|
|
20
|
+
return new Promise((resolve, reject)=>{
|
|
21
|
+
fetch(url).then((response)=>response.arrayBuffer()).then((buffer)=>this.audioContext.decodeAudioData(buffer)).then((audioData)=>{
|
|
22
|
+
const source = this.audioContext.createBufferSource();
|
|
23
|
+
source.buffer = audioData;
|
|
24
|
+
source.connect(this.audioContext.destination);
|
|
25
|
+
source.start(0);
|
|
26
|
+
resolve();
|
|
27
|
+
}).catch((error)=>{
|
|
28
|
+
reject(error);
|
|
29
|
+
});
|
|
32
30
|
});
|
|
33
31
|
}
|
|
32
|
+
play(url = this.file) {
|
|
33
|
+
return this.audio(url);
|
|
34
|
+
}
|
|
34
35
|
}
|
|
35
36
|
var $cf838c15c8b009ba$export$2e2bcd8739ae039 = $cf838c15c8b009ba$var$ClickTone;
|
|
36
37
|
|
package/dist/index.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,MAAM;IACJ,YAAY,
|
|
1
|
+
{"mappings":"AAAA,MAAM;IACJ,YAAY,IAAI,CAAE;QAChB,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,YAAY,GAAG,IAAK,CAAA,OAAO,YAAY,IAAI,OAAO,kBAAkB,AAAD;QACxE,IAAI,CAAC,kBAAkB;IACzB;IAEA,qBAAqB;QACnB,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,KAAK,eAAe,kBAAkB,QAAQ;YACvE,MAAM,SAAS;gBACb,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC;oBAC9B,SAAS,IAAI,CAAC,mBAAmB,CAAC,cAAc;oBAChD,SAAS,IAAI,CAAC,mBAAmB,CAAC,YAAY;gBAChD;YACF;YAEA,SAAS,IAAI,CAAC,gBAAgB,CAAC,cAAc,QAAQ;YACrD,SAAS,IAAI,CAAC,gBAAgB,CAAC,YAAY,QAAQ;QACrD;IACF;IAEA,MAAM,GAAG,EAAE;QACT,OAAO,IAAI,QAAQ,CAAC,SAAS;YAC3B,MAAM,KACH,IAAI,CAAC,CAAC,WAAa,SAAS,WAAW,IACvC,IAAI,CAAC,CAAC,SAAW,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,SACnD,IAAI,CAAC,CAAC;gBACL,MAAM,SAAS,IAAI,CAAC,YAAY,CAAC,kBAAkB;gBAEnD,OAAO,MAAM,GAAG;gBAChB,OAAO,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW;gBAC5C,OAAO,KAAK,CAAC;gBAEb;YACF,GACC,KAAK,CAAC,CAAC;gBACN,OAAO;YACT;QACJ;IACF;IAEA,KAAK,MAAM,IAAI,CAAC,IAAI,EAAE;QACpB,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB;AACF;IAEA,2CAAe","sources":["src/index.js"],"sourcesContent":["class ClickTone {\n constructor(file) {\n this.file = file;\n this.audioContext = new (window.AudioContext || window.webkitAudioContext)();\n this.iOSFixAudioContext();\n }\n\n iOSFixAudioContext() {\n if (this.audioContext.state === 'suspended' && 'ontouchstart' in window) {\n const unlock = () => {\n this.audioContext.resume().then(() => {\n document.body.removeEventListener('touchstart', unlock);\n document.body.removeEventListener('touchend', unlock);\n });\n };\n\n document.body.addEventListener('touchstart', unlock, false);\n document.body.addEventListener('touchend', unlock, false);\n }\n }\n\n audio(url) {\n return new Promise((resolve, reject) => {\n fetch(url)\n .then((response) => response.arrayBuffer())\n .then((buffer) => this.audioContext.decodeAudioData(buffer))\n .then((audioData) => {\n const source = this.audioContext.createBufferSource();\n\n source.buffer = audioData;\n source.connect(this.audioContext.destination);\n source.start(0);\n\n resolve();\n })\n .catch((error) => {\n reject(error);\n });\n });\n }\n\n play(url = this.file) {\n return this.audio(url);\n }\n}\n\nexport default ClickTone;\n"],"names":[],"version":3,"file":"index.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clicktone",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "A simple class
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A simple class that provides a convenient abstraction for handling audio playback by web applications, with support for iOS devices.",
|
|
5
5
|
"author": "ux-ui.pro",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -34,5 +34,15 @@
|
|
|
34
34
|
"parcel": "^2.11.0",
|
|
35
35
|
"postcss-html": "^1.6.0"
|
|
36
36
|
},
|
|
37
|
-
"keywords": [
|
|
37
|
+
"keywords": [
|
|
38
|
+
"MP3",
|
|
39
|
+
"WAV",
|
|
40
|
+
"OGG",
|
|
41
|
+
"AAC",
|
|
42
|
+
"iOS",
|
|
43
|
+
"sound",
|
|
44
|
+
"audio",
|
|
45
|
+
"playback",
|
|
46
|
+
"mobile"
|
|
47
|
+
]
|
|
38
48
|
}
|
package/src/index.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
class ClickTone {
|
|
2
|
-
constructor(
|
|
3
|
-
this.
|
|
4
|
-
this.
|
|
5
|
-
|
|
6
|
-
this.audioContext = new (window.AudioContext
|
|
7
|
-
|| window.webkitAudioContext)();
|
|
8
|
-
this.setupIOSAudioContextFix();
|
|
2
|
+
constructor(file) {
|
|
3
|
+
this.file = file;
|
|
4
|
+
this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
|
5
|
+
this.iOSFixAudioContext();
|
|
9
6
|
}
|
|
10
7
|
|
|
11
|
-
|
|
8
|
+
iOSFixAudioContext() {
|
|
12
9
|
if (this.audioContext.state === 'suspended' && 'ontouchstart' in window) {
|
|
13
10
|
const unlock = () => {
|
|
14
11
|
this.audioContext.resume().then(() => {
|
|
@@ -22,26 +19,29 @@ class ClickTone {
|
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
21
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
source.connect(this.audioContext.destination);
|
|
33
|
-
source.start(0);
|
|
34
|
-
})
|
|
35
|
-
.catch();
|
|
36
|
-
}
|
|
22
|
+
audio(url) {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
fetch(url)
|
|
25
|
+
.then((response) => response.arrayBuffer())
|
|
26
|
+
.then((buffer) => this.audioContext.decodeAudioData(buffer))
|
|
27
|
+
.then((audioData) => {
|
|
28
|
+
const source = this.audioContext.createBufferSource();
|
|
37
29
|
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
source.buffer = audioData;
|
|
31
|
+
source.connect(this.audioContext.destination);
|
|
32
|
+
source.start(0);
|
|
40
33
|
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
resolve();
|
|
35
|
+
})
|
|
36
|
+
.catch((error) => {
|
|
37
|
+
reject(error);
|
|
38
|
+
});
|
|
43
39
|
});
|
|
44
40
|
}
|
|
41
|
+
|
|
42
|
+
play(url = this.file) {
|
|
43
|
+
return this.audio(url);
|
|
44
|
+
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
export default ClickTone;
|