javascript - playing videos with html5 on android device -


I am creating a mobile site and I'm having trouble running the video on Android device. I can get the video to play but it seems unsure. Sometimes this causes the browser to crash, other times the controls are not responsive. Most of my testing is on the Galaxy S3 and Nexus.

The code is a link that you can click to play the video.

  & lt; Div id = "player" & gt; & Lt; / Div & gt; & Lt; A href = "#" onclick = "duplicate ('  

The javascript / jquery mix (this is probably the problem if not very optimal):

  function DoNav (theUrl) {// only add player if It does not exist yet ($ ('$ myfileplayer'). Length == 0) {var mydiv = $ ("# player"); Var myvideo = $ ("Video id = 'myfileplayer' src = '" + theUrl + "' width = '320' height = '240' control> gt; & lt; / video & gt;"); Mydiv.append (MyVideo); } And {$ ('# myfileplayer'). Attr ("src", theUrl); } Var video = document.getElementById ('myfileplayer'); Video.addEventListener ('click', function () {video.play ();}, false); }   

I'm not sure what to debug here. Any ideas?

Thanks to @Consu, she said why would I also need a click event listener? Good thing, I do not. I remove it and all strange behaviors have ended. DoNav (theUrl) {// only add players if it does not exist yet ($ ('$ myfileplayer') length == 0) {var mydiv = $ ("# Player "); Var myvideo = $ ("Video id = 'myfileplayer' src = '" + theUrl + "' width = '320' height = '240' control> gt; & lt; / video & gt;"); Mydiv.append (MyVideo); } And {$ ('# myfileplayer'). Attr ("src", theUrl); }}

Comments