juniorxsound / Depthkit.js

🎞 A plugin for using DepthKit's volumteric captures in Three.js
https://juniorxsound.github.io/Depthkit.js/
MIT License
89 stars 34 forks source link

character.depthkit.play() doent work sometimes on safari mobile ios #10

Closed CharStiles closed 4 years ago

CharStiles commented 4 years ago

in my app it plays fine on desktop, on mobile (ios safari) i get this error over and over again.

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.
(anonymous function)
rejectPromise
play
value — depthkit.min.js:2:9573
(anonymous function) — main.js:620
update — main.js:300
animate — main.js:321
value — depthkit.min.js:2:9573

I do have it so the the user must tap the screen to start the whole experience, but the play itself is triggered by something else that happens after the user taps the screen. I suspect it might be because its not directly inside a user gesture? I say this because this toy project works fine: https://depthkit.glitch.me

this is whats supposed to happen: https://www.youtube.com/watch?v=_pZPpvudI7I&feature=youtu.be

This is my project: https://glitch.com/~ht94 you dont need to go through the experience just know its like the video except the character doesnt play. Posting it here incase you wanted to see the code (sorry i need to comment it)

how I got that video in the first place is that it used to work but i made some changes, i have been trying to pinpoint them to the exact moment it broken but its been taking hours, I thought id post this, keep looking and update when i find it, incase you have a suggestion for a quick fix... thank you!!

edit: I am not sure why it was working before I couldnt find any change in the code that caused it to break, I am sure it is there somewhere & there is a logical explanation but for now i cant spend any more time looking.

CharStiles commented 4 years ago

I figured it out, so my suspicion was valid. It was that the play() wasnt happening in the user input event handler. This SO answer enlightened me on what to do in this case

for those who may happen upon this & need a solution: First have a global or something named character in the user input event handler: character = new DepthKit( 'mesh', scene1Text, scene1Video); character.depthkit.setVolume(0); character.depthkit.play(); setTimeout(function(){character.depthkit.pause(); },5000); Waiting 5 seconds is a hack since the depthkitplay isn't a promise (i dont think), so i cant make the pause a callback function. I just assume 5 seconds is long enough for the play function to finish. Then whenever/wherever you want you can: character.depthkit.setVolume(1); character.depthkit.play();

is there a way to make the depthkit functions input a callback? Maybe this was a feature request ticket all along haha! Cheers :)