Lloyd Jones
asked on
Is it possible to access the play or pause functionality in the html5 video control on the code behind in a C# asp.net application?
I have a c# asp.net application that needs to play 10 videos. Each video will need to be started by the user pressing the next button. Once a video ends then I need to write to the database that user completed the video. I have setup a Ajax control with a timer for the length of each video. Once the timer fires, then I want to stop the video from looping, record to the database the user id and the video id. Then when the user presses the next button start the next video.
Well this is currently a big problem.
All major browsers have completely blocked the play method to start videos by any other means then actual video controls.
For older browsers, Scott's suggestion will work. For newer browser, you'll get a Javascript console error.
There are a few work arounds. Each time someone comes up with a work around, next browser release blocks the work around.
Best to just stick with <video controls> as your tag, so user is presented with controls so they can start videos as they choose.
Exception: You can do this <video muted autoplay controls> so autoplay is currently allowed, if video is muted.
I'm unsure if this is allowed on more than one <video> tag at a time. My guess is many mobile devices will only play first <video>. Best you test your target devices to make a determination.
Note: That said, dev channel talk for all browsers suggests autoplay + muted will also be blocked soon.
If you really must do what you describe, then you'll likely have to write some custom Flash player, except Adobe has set Flash EOL (end or life) to 2020, so this option will likely only work for a while longer.
Might be best to come up with an alternative plan.
All major browsers have completely blocked the play method to start videos by any other means then actual video controls.
For older browsers, Scott's suggestion will work. For newer browser, you'll get a Javascript console error.
There are a few work arounds. Each time someone comes up with a work around, next browser release blocks the work around.
Best to just stick with <video controls> as your tag, so user is presented with controls so they can start videos as they choose.
Exception: You can do this <video muted autoplay controls> so autoplay is currently allowed, if video is muted.
I'm unsure if this is allowed on more than one <video> tag at a time. My guess is many mobile devices will only play first <video>. Best you test your target devices to make a determination.
Note: That said, dev channel talk for all browsers suggests autoplay + muted will also be blocked soon.
If you really must do what you describe, then you'll likely have to write some custom Flash player, except Adobe has set Flash EOL (end or life) to 2020, so this option will likely only work for a while longer.
Might be best to come up with an alternative plan.
My solution is to change the action of the button. David misinterpreted my response.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
After the ajax fires to write to the database, use javascript to change what happens when the button is clicked.