0

I have the need to stop javascript code execution until a video in my app stops playing. In order to do this, I have a function that looks like the following...

function playVideo(source, volume) {
   //Some stuff
   return media.play(source).finally(function() {
        //Some cleanup stuff
     }
   )
}

On all browsers except for Safari 9, the code inside the finally block does not execute until my video has stopped playing. How can I get the code to behave the same for Safari 9 also?

user1066568
  • 717
  • 3
  • 15
  • 32
  • to answer the question, you would probably need to listen for [ended event](https://developer.mozilla.org/en-US/docs/Web/Events/ended) – Jaromanda X Aug 05 '17 at 06:38
  • I'd be surprised if that works in any browser, clearly there's some library involved to have a `finally` method on the object returned by `play` – Jaromanda X Aug 05 '17 at 06:41
  • The call to media.play(source) returns a javascript Promise. So that means that the finally block should only execute once the promise has been fulfilled and not before that right? – user1066568 Aug 05 '17 at 23:45
  • yes, it is fulfilled once the media **begins** to play ... also `finally` is nothing to do with promises (yet?) which is why I'm surprised this works in any browser ... you say all browsers except safari 9 ... so this even work in internet explorer? – Jaromanda X Aug 06 '17 at 00:23
  • Yes, this works on all browsers including IE except for Safari 9. I've checked on Safari 10, Chrome & Firefox. – user1066568 Aug 12 '17 at 08:27

0 Answers0