I have a social media feed where users can post videos. I'd like to add a spinner while the video is buffering using AngularJS. This is the HTML part:
<div class="media-list-item col-xs-12" ng-repeat="media in ::videos">
<div class="embed-responsive embed-responsive-16by9">
<video controls oncontextmenu="return false;"
class="embed-responsive-item" frameborder="0" allowfullscreen preload="auto"
id="{{media.Id}}">
<source ng-src="{{::media.Url | trustAsResourceUrl}}" />
</video>
<i class="fa fa-spinner fa-pulse videoLoader" ng-show="media.loading" aria-hidden="true"></i>
</div>
</div>
This is my script:
for (var i = 0; i < scope.videos.length; i++) {
var video = scope.videos[i];
video.loading = false;
var videoElement = angular.element(document.getElementById(video.Id))[0];
videoElement.onplaying = function () {
video.loading = false;
scope.$apply();
};
videoElement.onwaiting = function () {
video.loading = true;
scope.$apply();
};
}
So I'm loading the videos from media, and set a 'loading' param to trigger the ng-show for each separate media (video), so when the video is 'onwaiting' (buffering) it should show the spinner, when it's 'onplaying' hide it. It works perfectly whenever I have only one video at the specific post, but whenever there are multiple videos in one post, the spinner only displayed on the last video. Any help appreciated.