Force update of html5 video source in angular js project - angularjs

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>

Related

Background video not being displayed in React-Laravel App (API)

I am creating an app using React and Laravel. I want to apply a bg video in my app and also have the code ready. The webpack mix is running successfully. All the components are being displayed except for the video.
I have provided the code snippet below.
import Video from "../../../videos/HomeVideo.mp4";
<HeroContainer id="home">
<HeroBg>
<VideoBg autoPlay loop muted src={Video} type="video/mp4" />
</HeroBg>
<HeroContent>
<HeroP>
Sign up today and receive a 10% discount on your next
service.
</HeroP>
</HeroContent>
</HeroContainer>
Everything is running fine, just the video is not being displayed
Please remove muted from your code.
<VideoBg autoPlay loop src={Video} type="video/mp4" />
Also, try to use a built-in video tag of react.
<video loop autoPlay>
<source
src={Video}
/>
Try to use this snippet to show up your video.
</video>

AngularJS - HTML5 video is loading multiple times

I have an AngularJS app that presents some sequential videos and if I go to another URL (by using another HTML reference, href) the old controller stays active and both videos still playing. This happens for each new page with the same controller that I've openned, creating multiple video instances.
The controller receives a video SRC and sets it using ng-src.
EDIT
I am getting video element by ID:
var video = document.getElementById("video");
And setting correspondent source when controller is initialized:
if (video) {
video.src = Modernizr.video.ogg ? $scope.mainVideoUrlogv :
Modernizr.video.webm ? $scope.mainVideoUrlwebm :
$scope.mainVideoUrlmp;
$scope.playVideo();
}
HTML
<video id="video" ng-mouseup="pauseOrPlayVideo()">
<source ng-src="{{mainVideoUrlwebm}}" type="video/webm">
<source ng-src="{{mainVideoUrlogv}}" type="video/ogv">
<source ng-src="{{mainVideoUrlmp}}" type="video/mp4">
</video>
The solution was to remove the video Element from the page.
var video = document.getElementById("video");
Mozila documentation about ChildNode.remove() helped to perform remove action.
video.remove(); //javascript way
However, I've realized that it does not work on IE, as you can notice in the last reference.
The solution was to perform this action in jQuery.
$('video').remove(); //jQuery way
It works in the browsers that I have tested, namely Chrome, Firefox Dev Edition and IE9, IE10.

Youtube video is not looping

I am using youtube embed code to show a video. But the loop option is not working.
How can I make that work?
here is the code I am using
<iframe frameborder="0" height="100%" width="100%"
src="https://www.youtube.com/embed/ejoIgFsmqxA?autoplay=1&controls=0&showinfo=0&autohide=1&loop=1"> </iframe>
If you check Youtube docs you will see that the loop parameter has some limitations:
Note: This parameter has limited support in the AS3 player and in IFrame embeds, which could load either the AS3 or HTML5 player. Currently, the loop parameter only works in the AS3 player when used in conjunction with the playlist parameter. To loop a single video, set the loop parameter value to 1 and set the playlist parameter value to the same video ID already specified in the Player API URL [...]
So, it seems that it could work (not tested) if you add &playlist=ejoIgFsmqxA at the end of the iframe src like this:
<iframe frameborder="0" height="100%" width="100%"
src="https://www.youtube.com/embed/ejoIgFsmqxA?autoplay=1&controls=0&showinfo=0&autohide=1&loop=1&playlist=ejoIgFsmqxA"></iframe>

AngularJS wrong scope value

I have a html5-tag using the scope to set the src:
<video style="max-height:100%; max-width:100%" controls>
<source src="/files/{{item.path}}" type="video/mp4"/>
</video>
If I load this template I get this error:
GET http://localhost:8070/files/%7B%7Bitem.path%7D%7D 404 (Not Found)
Btw. this is not the correct value of item.path. If I set the path manually it works:
<source src="/files/./5315dfea66469e28166e85c6/5315dfea66469e28166e85c6_20143414248143.mp4" type="video/mp4"/>
How can I make this work?
This is an open issue with Angular:
https://github.com/angular/angular.js/issues/1352
ng-src is appropriate here. however, it is confirmed to not work in all browsers and is suspected to be a bug in the browser rather than with Angular.
There is a possible workaround here: HTML5 video element request stay pending forever (on chrome)

AngularJS videogular not responsive

I am using angularjs and I read that videoangular is automatically responsive with vg-responsive='true'.
But using this code:
<videogular vg-responsive='true'>
<video class='videoPlayer' controls preload='none' vg-responsive='true'>
<source src='http://www.videogular.com/assets/videos/videogular.mp4' type='video/mp4'>
</video>
</videogular>
the video on the browser is not responsive.
Any idea?
Thank you.
Have you tried with a $scope variable like config.responsive instead of true directly?
I don't remember now, but maybe you can't set a value directly to vg-responsive.
UPDATE
You must specify a theme, this is a required parameter. This worked for me:
<videogular vg-theme="config.theme.url" vg-responsive="true">...</videogular>
You could take a look to the Videogular's reference for more info:
https://github.com/2fdevs/videogular/wiki/Videogular-reference

Resources