-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
76 lines (62 loc) · 1.26 KB
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
let song;
let slide;
var isIphone;
var isPlaying;
var start = function()
{
if(!isPlaying) {
isPlaying = true;
song.play();
}
}
const songP = 'assets/telephone_ring.mp3';
function preload () {
isIphone = window.navigator.userAgent.match(/iPad/i) || window.navigator.userAgent.match(/iphone/i);
if (isIphone) {
// AUDIO FIX
song = new Audio(songP);
} else {
// loadsound
song = loadSound(songP);
}
}
function setup() {
createCanvas(window.innerWidth, window.innerHeight);
slide = 0;
if (isIphone) {
// AUDIO FIX
isPlaying = false;
//touch fix
var el = document.getElementsByTagName("canvas")[0];
el.addEventListener("touchstart", mouseClicked, false);
}
// ignore this
textSize(32);
textAlign(CENTER, CENTER);
}
function draw() {
if (slide == 0 ) {
background(0);
fill(255);
text('Press to start audio', 0,0, width, height);
} else if (slide == 1) {
background(255);
fill(0);
text('Enjoy your audio on IOS', 0,0, width, height);
}
}
function mouseClicked() {
console.log("touch");
if (slide == 0) {
if (isIphone) {
start();
} else {
if ( !song.isPlaying() ) {
song.play();
}
}
slide = 1;
} else if (slide == 1 ) {
slide=0;
}
}