i need to get the value of a video and need to change in to new value... for that i used this function:
var video = $('#task2ResultVideo').get(0);
console.log($(video).attr('poster')); // i am getting this
$(video).attr('src',function(num,val){
console.log(num,val) // i am not getting this..
})
HTML:
<video id="task2ResultVideo" autobuffer poster="img/task2-results-host-poster.jpg">
<source src="Video/webm/Task_2.4a_Host_treated.webm" type="video/webm" />
<source src="Video/ogv/Task_2.4a_Host_treated.theora.ogv" type="video/ogg" />
<source src="Video/MP4/Task_2.4a_Host_treated.mp4" type="video/mp4" />
</video>
But i am not able to get the values. what is wrong with my code? in case if i get the value how can i change the src?
any suggestion please?
your video tag has not any source attribute so you will never get it. Instead get src attribute of its inner source tags
$('video').find('Source:first').attr('src');
this will get the value of src attribute of first source tag inside video tag
Try this,
Live Demo
$('video source').each(function(num,val){
console.log($(this).attr('src')); // i am not getting this..
$(this).attr('src', 'newSourceValue')
});
Based on the comments by OP, changing the src filename
Live Demo
$('video source').each(function(num,val){
console.log($(this).attr('src')); // i am not getting this..
strSrc = $(this).attr('src');
strPath = strSrc.substring(0, strSrc.lastIndexOf('/'));
strExtenion = strSrc.substring(strSrc.lastIndexOf('.'));
$(this).attr('src', strPath + "/" + "newFileName" + strExtenion );
});
var video = $('#task2ResultVideo');
video.find('source').each(function() {
console.log($(this).attr('src'));
});
// if you want to get array of the src
var arr = video.find('source').map(function() {
return $(this).attr('src');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With