问题描述:

I know there is a lots of similar questions,

but all of them are so many years older and i wanted to update the question to see if there is any changes for this functionality in the android os

this is the code that im trying

i am trying to get the duration of a video from an android device and i get NaN or 0 i found a solution to get the duration when the video is playing and that works but i can't do video.play() it's not allowed on the android devices.

Is there any way to get the video duration with javascript in the browser from android ?

<!DOCTYPE html>

<html>

<body>

<button onclick="myFunction()" type="button">Get video length</button><br>

<video id="myVideo" width="320" height="176" controls>

<source src="http://www.w3schools.com/tags/mov_bbb.mp4" type="video/mp4">

<source src="http://www.w3schools.com/tags/mov_bbb.ogg" type="video/ogg">

Your browser does not support HTML5 video.

</video>

<script>

var vid = document.getElementById("myVideo");

function myFunction() {

alert(vid.duration);

}

</script>

<p>Video courtesy of <a href="http://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>

</body>

</html>

相关阅读:
Top