youtube video is not playing from from html5 using ng-src directive

Scalaboy

I am creating an online course application and storing the video on YouTube. When a user clicks on courses then They should see the embedded YouTube videos. However It just creates the video frame and video doesn't play.

Here is my angular controller code. courses.client.controller.js

(function() {
'use strict';

angular
.module('courses')
.controller('CoursesController', CoursesController);

CoursesController.$inject = ['$scope', 'courseResolve',  'Authentication', '$sce'];

function CoursesController($scope, course, Authentication, $sce, $timeout) {
var vm = this;

vm.course = course;
vm.authentication = Authentication;

$scope.params = {
videoUrl: $sce.trustAsResourceUrl('https://youtube.com/embed/gZNm7L96pfY')
};
}
}());

Here is my html code. view-course.client.view.html. I have tried to two different approaches. Both Failed.

<section>
<div class="page-header">
  <h1 ng-bind="vm.course.title"></h1>
</div>
<small>
<em class="text-muted">
Posted on
<span ng-bind="vm.course.created | date:'mediumDate'"></span>
by
<span ng-if="vm.course.user" ng-bind="vm.course.user.displayName"></span>
<span ng-if="!vm.course.user">Deleted User</span>
</em>
</small>
<p class="lead" ng-bind="vm.course.content"></p>
<div>
  <video id="movie", ng-src="{{vm.course.courseLecture}}" width="500", height="300" controls>
  </video>
  <br><br><br>
  <video style="width:300px;height:240px" controls preload="none" >
     <source ng-src="{{params.videoUrl}}" type="video/mp4">
  </video>
  <br><br>
  <hr>
  <a ng-href="{{vm.course.courseLecture}}" target="_blank" >link1</a>
  <hr>
  <p class="lead" ng-bind="vm.course.courseLecture"></p>
</div>
</section>

Please let me know, where I am going wrong here.

Sajeetharan

Try adding this and instead of video control load it inside an iframe,

app.config(function($sceDelegateProvider) {
  $sceDelegateProvider.resourceUrlWhitelist([
    'self',
    'https://www.youtube.com/**'
  ]);
});

DEMO

var app = angular.module('myApp', []);
app.config(function($sceDelegateProvider) {
  $sceDelegateProvider.resourceUrlWhitelist([
    'self',
    'https://www.youtube.com/**'
  ]);
});

app.controller('videoController', ['$scope',
  function MyCtrl($scope) {

    $scope.product = {
      name: 'some name',
      description: 'some description',
      media: [{
        src: 'gZNm7L96pfY'
      }]
    };

    $scope.getIframeSrc = function(src) {
      return 'https://www.youtube.com/embed/' + src;
    };
  }
]);

 
<!DOCTYPE html>
<html ng-app="myApp">

<head>
  <script src="https://code.angularjs.org/1.2.1/angular.js"></script>
 
</head>

<body ng-controller="videoController">
  <div ng-repeat="media in product.media">
    <div class="thumbnail">
      
      
      <div class="video-container">
        <iframe width="100%" ng-src="{{getIframeSrc(media.src)}}" frameborder="0 " allowfullscreen></iframe>
      </div>
    </div>
  </div>
</body>

</html>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Detect if HTML5 Video element is playing

Playing HTML 5 video from Angular 2 Typescript

How can I resume playing audio from web source after pausing it using HTML5 and JavaScript?

How exit from iPhone Full Screen of HTML 5 VIdeo player when video is done playing?

Videos not playing in safari when using html5 video tag

HTML5 generating video from images

How do I change the playback speed of the currently playing YouTube video, with JavaScript and the HTML5 player?

playing html5 video from in memory source

Check if a HTML5 video is playing using jquery

Stop the video from playing

ng-src not working for youtube embed video

How to stop a youtube video from playing

How can I stop an embedded iframe youtube video from playing when a modal is closed?

Stop YouTube Video from Playing when FlexSlider Slide is out of view

Playing HLS file from a server with a HTML video tag

Playing video from youtube link without UIWebView

How to stop html5 video from playing when out of viewport?

How to avoid moving back in playing video by using video tag in HTML5

iOS - Playing a YouTube video in fullscreen from a table cell

Prevent an HTML5 video from playing when the play button is paused

Getting "Time Elapsed" of a playing video from the YouTube API in ActionScript 3.0

AngularJS - issue when embedding the Youtube video url from directive to script

HTML5 Video not auto playing when using ended function

Playing Video from RAM in Android

problems while playing video from s3 using AVplayer

How to tell when youtube video stops playing from the terminal? macOS

HTML5 video not playing only in chrome

HTML5 video not playing in android webview

From a list of YouTube videos rendered in a card stack, the 1st video starts playing in every card on swipe