I have a project where I've embedded an html5 video on a view.

I populate the source dynamically using $scope.

The initial video I populate the player with works fine.

At the end of the video, I try to change the src of the video to the next clip, until it ends.

My problem is that the video src does not update and just plays the initial clip.

Here's the html (pretty straight forward):

            <video style="width:100%; height:100%; padding:0;" class="embed-responsive embed-responsive-16by9" id="myVideo" controls>
                <source ng-src="{{currentVideo}}" type="video/mp4">
            </video>

Here's the code that implements the change from the controller:

        if (videoId.currentTime >= videoId.duration - 1) {
            // $state.go('unit_1');

               $scope.currentVideo = myObj.units[1].lessonUrl; //set video
               videoId.play();
        }

FYI - videoId is the var for the video. It works fine, as I can play(), pause(), get currentTime, etc.

So I know I'm controlling the player and that I'm successfully loading the initial video.

I'm assuming that when the $scope changes the new video URL would, but obviously I'm wrong.

Any ideas?

Thanks!

If you want to change the src on the video's <source> element, you need to call videoId.load(); before videoId.play(); Otherwise just change the src attribute directly on the video element itself - then a load will not required:

<video ng-src="{{currentVideo}}" style="width:100%; height:100%; padding:0;" class="embed-responsive embed-responsive-16by9" id="myVideo" controls>
</video>
  • unfortunately that does not refresh the view with the new source. It still plays the original video loaded to the source. – cnak2 Oct 28 '16 at 19:46
  • Do you have a sample of this code online? Does the src show that it has been updated? – TimHayes Oct 28 '16 at 19:50
  • Hi Tim, I don't, but will put a plunker together later tonight and add the link to this question. Thanks. – cnak2 Oct 29 '16 at 4:31
  • Make sure you append a new timestamp (e.g. '?20180122235700') to your URL to avoid cache issues, and then fire .load() on your video element after you have updated your URL, by pointing to your video id attribute, whether with JQuery if you use it along AngularJS, or JQLite. – Christian Bonato Jan 22 at 22:59

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.