0

I need to run a video file for this iam using video element. The anomaly which iam seeing right now is that if iam setting the src programmatically then the file is not playing. While the same path if iam directly giving in src then the video is playing.

The Video resides in Videos folder of solution, so i dont think there is any access issues.

Below code directly assigns the src for video - Playing the file.

  function ShowModalPopup() {
    //$find("mpe").show();
    //return false;
    var param1 = new Date();
    var month = param1.getMonth() + 1;
    var day = param1.getDate();
    var param2 = (('' + day).length < 2 ? '0' : '') + day + '/' + (('' + month).length < 2 ? '0' : '') + month + '/' + param1.getFullYear() + ' ' + param1.getHours() + ':' + param1.getMinutes() + ':' + param1.getSeconds();
    $("#<%= hdnStartDateTime.ClientID %>").val(param2);
    var url = $get("<%=lnkVideoLink.ClientID %>").value;
    alert(url);
    //$get("video").src = url;
    $('[id*="MyVdo"]').attr('src', '../../MS_RIT_Training_Videos/REITIworkatTest.mp4');//type='video/mp4'
    //$('[id*="MyVdo"]')[0].play();
    $find("mpe").show();
    return false;
}

Below code programmatically assigning src - Not Playing the video

function ShowModalPopup() {
    //$find("mpe").show();
    //return false;
    var param1 = new Date();
    var month = param1.getMonth() + 1;
    var day = param1.getDate();
    var param2 = (('' + day).length < 2 ? '0' : '') + day + '/' + (('' + month).length < 2 ? '0' : '') + month + '/' + param1.getFullYear() + ' ' + param1.getHours() + ':' + param1.getMinutes() + ':' + param1.getSeconds();
    $("#<%= hdnStartDateTime.ClientID %>").val(param2);
    var url = $get("<%=lnkVideoLink.ClientID %>").value;
    alert(url);
    //$get("video").src = url;
    // $('[id*="MyVdo"]').attr('src', '../../MS_RIT_Training_Videos/REITIworkatTest.mp4');//type='video/mp4'
    $('[id*="MyVdo"]').attr('src', url);//type='video/mp4'
    //$('[id*="MyVdo"]')[0].play();
    $find("mpe").show();
    return false;
}

For Kenneth :

enter image description here

Alert:

enter image description here

2
  • In generall your code looks ok. Check the values of url again. I'm actually pretty sure the problem is in there, if the first function runs without any problem. Commented Jun 27, 2016 at 11:46
  • Implementing Kenneth code is playing the video now, but before that I get this error. I need to hit continue only then the video plays. Commented Jun 27, 2016 at 12:09

1 Answer 1

1

Are you sure the URLs are the same (hardcoded and the one you get from the element)?

also you can try to load the video programmatically after you set it

$('[id*="MyVdo"]')[0].load();
Sign up to request clarification or add additional context in comments.

8 Comments

Another question is not an answer. Post it as a comment!
An error is being shown on Runtime " Object doesn't support property or method 'load'". But the video is playing now on Continue.
if you execute $('[id*="MyVdo"]')[0] in developer tools or alert it. What element shows? It should be the video element
Please see the error snapshot. I have edited the question.
Can you do alert( $('[id*="MyVdo"]')[0]) before the load line and post that so i can see?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.