# Sound does not play

**URL:** https://discourse.processing.org/t/sound-does-not-play/33546
**Category:** Libraries
**Created:** [November 16, 2021, 8:59am UTC](https://discourse.processing.org/t/sound-does-not-play/33546 "2021-11-16T08:59:06Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)
#### Post date: [November 16, 2021, 8:59am UTC](https://discourse.processing.org/t/sound-does-not-play/33546/1 "2021-11-16T08:59:06Z")

</div>

I tried to write a program that works on mobile (apple) devices. Everything works except for the sound.  
This is my code:

```auto
// A sound file object
var dingdong;

function preload() {
  // Load the sound file.
  // We have included both an MP3 and an OGG version.
  soundFormats('mp3', 'ogg');
  dingdong = loadSound('bell.mp3');
}

function setup(){
createCanvas(windowWidth,windowHeight);
	background(100);
}
function draw(){
background(100);
	fill(0,256,0);
	ellipse(mouseX,mouseY,80,100);
	if(millis()>=5000){
fill(256);
		if(touchEnded());
		playSound(dingdong);

	}
}

```

---

<div class="post-metadata">

### Author: ![KumuPaul](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kumupaul/32/13072_2.png) [@KumuPaul](https://discourse.processing.org/u/KumuPaul)
#### Post date: [November 16, 2021, 8:24pm UTC](https://discourse.processing.org/t/sound-does-not-play/33546/2 "2021-11-16T20:24:52Z")

</div>

This is not the correct usage of [`touchEnded()`](https://p5js.org/reference/#/p5/touchEnded). Touch ended is not a function you call to get a `true`/`false` value. It is a function that you implement that gets called when a touch action ends (the user lifts their finger of the screen).

This is what you probably want:

```auto
function touchEnded() {
  playSound(dingdong);
}

```

Also your if statement syntax is wrong:

```javascript
    // An if statement with no block (i.e. curly braces { }) will apply to the subsequent statement, however the ; brings an end to the if statement, so the next line is not part of it.
    if (touchEnded());
    // So in this case playSound would run regardless of what touchEnded() returned
    playSound(dingdong);

```

In this case it is mostly academic because this code just crashes because `touchEnded` is undefined. However, as a rule I think it is best to **always** use the block form of if statements and loops:

```javascript
    if (condition) {
      playSound(dingdong);
    }

```

Also it is a good idea to check the JavaScript console for errors as a first step when debugging issues.
