I have the following code which loads a local video on an Android device and places it in a HTML5 Video src tag:
Javascript code:
var path = 'file:///data/data/com.myapp.app/files/';
var src = path+'Intro.mp4';
var video = $("#introVideo");
video.find("source").attr("src", src);
HTML code:
<video id="introVideo" width="100%" poster="poster.jpg"controls>
<source src="" type="video/mp4">
</video>
This doesn't work on Android device. However, if i don't use the javascript code above and just use the video path like the following, everything works fine:
This works:
<video id="introVideo" width="100%" poster="poster.jpg"controls>
<source src="file:///data/data/com.myapp.app/files/Intro.mp4" type="video/mp4">
</video>
When i alert(src);
I get the exact URL which is:
file:///data/data/com.myapp.app/files/Intro.mp4
Which means the video exist locally and there is an issue with my Javascript code above. But i don't understand what the issue is!
Can someone please advice on this issue?
Thanks in advance.
EDIT:
This is how the code above is trigerred:
$(document).on('click','.backit', function(e){
var path = 'file:///data/data/com.myapp.app/files/';
var src = path+'Intro.mp4';
var video = $("#introVideo");
video.find("source").attr("src", src);
});
EDIT:
Further investigation, I found out that the Video's src tag is being set correctly when i use my javascript code above, However, the video doesn't play when i set its src tag dynamically which is very strange.