# P5js video error: Element play method raised an error asynchronously DOMException

**URL:** https://discourse.processing.org/t/p5js-video-error-element-play-method-raised-an-error-asynchronously-domexception/8358
**Category:** Coding Questions
**Created:** [February 13, 2019, 3:54pm UTC](https://discourse.processing.org/t/p5js-video-error-element-play-method-raised-an-error-asynchronously-domexception/8358 "2019-02-13T15:54:38Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![AndreasRef](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/andreasref/32/133_2.png) [@AndreasRef](https://discourse.processing.org/u/AndreasRef)
#### Post date: [February 13, 2019, 3:54pm UTC](https://discourse.processing.org/t/p5js-video-error-element-play-method-raised-an-error-asynchronously-domexception/8358/1 "2019-02-13T15:54:38Z")

</div>

I have a question about an error I get when I want to have a video play in my p5js sketch:

`WARN: Element play method raised an error asynchronously DOMException`

If I press the canvas first with my mouse, the error does not occur.

Is there any trick to not have to press the mouse first?

---

<div class="post-metadata">

### Author: ![ronan-mch](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@ronan-mch](https://discourse.processing.org/u/ronan-mch)
#### Post date: [February 13, 2019, 8:58pm UTC](https://discourse.processing.org/t/p5js-video-error-element-play-method-raised-an-error-asynchronously-domexception/8358/2 "2019-02-13T20:58:56Z")

</div>

I’m also having issues with opening a video capture. I tried to replicate by running the sketch from the [documentation for createCapture](https://p5js.org/examples/dom-video-capture.html). However, this fails with the error:

```auto
MediaStreamError
​
constraint: ""
​
message: "The object can not be found here."
​
name: "NotFoundError"
​
stack: ""

```

Could this be a bug in p5dom? Release is 0.7.2. Upgrading to 0.7.3 doesn’t fix anything.

See [my sketch here](https://editor.p5js.org/ronan-mch/sketches/0t6lt8A1N) for replication.

---

<div class="post-metadata">

### Author: ![AndreasRef](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/andreasref/32/133_2.png) [@AndreasRef](https://discourse.processing.org/u/AndreasRef)
#### Post date: [February 14, 2019, 8:11am UTC](https://discourse.processing.org/t/p5js-video-error-element-play-method-raised-an-error-asynchronously-domexception/8358/3 "2019-02-14T08:11:54Z")

</div>

I can run your sketch without any errors or issues.

For clarification: My issues is about playing back a video file, not streaming the webcam.

---

<div class="post-metadata">

### Author: ![ronan-mch](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@ronan-mch](https://discourse.processing.org/u/ronan-mch)
#### Post date: [February 15, 2019, 9:49am UTC](https://discourse.processing.org/t/p5js-video-error-element-play-method-raised-an-error-asynchronously-domexception/8358/4 "2019-02-15T09:49:30Z")

</div>

Hi Andreas, sorry about the confusion, seems like my webcam was misbehaving for unrelated reasons. I haven’t seen your code, but just reasoning about it I have a few ideas:

1. You can probably simulate a click event in code, to save yourself the manual input. There is an [example in MDN](https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events#Triggering_built-in_events) of how to do so in vanilla Javascript. Trimming it down I get:

```auto
  var event = new MouseEvent('click', {
    view: window,
    bubbles: true,
    cancelable: true
  });
  var cb = document.getElementById('yourElementId'); 
  cb.dispatchEvent(event);

```

1. Presuming the click event is triggering something, you should be able to figure out what this is (the EventHandler) and call that directly. Chrome’s developer tools allow you to inspect the Event Handlers for a given DOM element so that might help you.

Let me know if that helps. If you want I can take a look at your sketch and see if I can figure something out (total p5js noob btw, but I know a bit of coding).
