I am trying to use HTML5 video tag with knockout.js, here is my code sample:
function AppViewModel() {
this.courseUrl= ("http//www.google.com");
this.vidUrl= ("/video/myvid.mp4");
};
var vm = new AppViewModel();
ko.applyBindings(vm);
Here is my html code:
<video id="my_video" width="1000" height="500" autoplay>
<source data-bind="attr: { src : vidUrl }">
</video>
<a data-bind="attr: { href: courseUrl }">Visit google</a>
As you can see from my code I am using same kind of code for calling a href and src of video. My href line works fine whereas src doesn't load the specified video (or any video) and it doesn't give any error.
Please let me know if I am not doing anything correctly.
TEMP SOLUTION:
For now, I am using normal js code to load video, this code is inside knockout's viewmodel function. This way I will have access to data coming through knockout variables. I haven't tested this thoroughly, but its working for now. My code now changes as follow:
function AppViewModel() {
this.courseUrl= ("http//www.google.com");
var video =document.getElementById('my_video');
video.src = "/video/myvid.mp4";
};
and html code is as follow:
<video id="my_video" width="640" height="480" autoplay>
</video>