0

I try to execute an action when user press a button (An event listener needed because https://webkit.org/blog/6784/new-video-policies-for-ios/), but I guess, I have some syntax/logic mistake. Some help would be nice :D.

Here is the code:

HTML:

   <a-image id="playbutton_1" position="-5 0 0" width="2" height="2" rotation="0 -90 0" ></a-image>

JS:

var playthisvid_1 = document.querySelector('#playbutton_1');

    playthisvid_1.addEventListener('click', () => { console.log("it clicks");  })

3 Answers 3

4

Aframe elements won't simply react to touch / mouse events. You need a ray based cursor.

A good way to simulate the mouse is with the cursors attribute:

<a-scene cursor="rayOrigin: mouse">

It should also work with touch events on mobile devices.

Check it out here.


Otherwise use the a-frame cursor.

<a-cursor></a-cursor>
Sign up to request clarification or add additional context in comments.

5 Comments

i get this Unhandled Promise Rejection: NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission. on iphone if i try to play a video with the listener any idea why it appears?
is it on safari, or other browsers ? If not, can you check if it works on other browsers on iOS ?
dosn´t work on chrome/safari on iphone (desktop everthings fine)
stackoverflow.com/questions/51878346/… here some more informations
thx now it works. The problem was the button in your examplepage isn´t in the a-scene its a normal html-element. So i changed my <a-image> to an normal <image> and it works. Only problem i can´t gaze on them now with my cardboard.
1

I think the problem is with aframe. The javascript code is working perfect. I just replaced the aframe element with a normal button and the function is working.

var playthisvid_1 = document.querySelector('#playbutton_1');

    playthisvid_1.addEventListener('click', () => { console.log("it clicks");  })
<a id="playbutton_1" href="#">Test</a>

Maybe this can solve your problem ? AFrame: how to add a touch event listener to an entity

2 Comments

thx for the information looks like i need a workaround for aframe :)
Yes :) no problem
0

check this out for a complete example:

https://curious-electric.com/w/experiments/aframe/audiosprite/

It is an audio example, but the same technique applies for video (i.e. get the user to click a button first).

Best, Dirk

3 Comments

thx i tried to use it but it still won´t work with <a-image> the console says the value of my button is always zero.
var vrButton = document.querySelector('#playbutton_1'); var enter = function () { console.log("it clicks"); } vrButton.addEventListener('click', enter);
Could you post your full example in a codepen or jsFiddle?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.