angularjs - 如何在 angularjs 中自动播放视频?

标签 angularjs cordova ionic-framework

嗨,我有一个网址列表,其中一个是视频链接,我需要在特定时间显示每个网址 30 秒,我使用 $time out 函数执行此操作,除了播放视频之外,一切正常。

下面给出的 Controller 代码

.controller('PlaylistCtrl', ['$scope', '$stateParams','$ionicPopup','$http','$interval','$sce','$templateCache','$ionicHistory','$timeout','Base64','$ionicPlatform',function($scope, $stateParams,$ionicPopup,$http,$interval,$sce,$templateCache,$ionicHistory,$timeout,Base64,$ionicPlatform) {
    var sequencecount=[];
    sequencecount=0;
    var hostname='http://url.com/';
   var seqlist= JSON.parse(window.localStorage['slist'] || '{}');
    var time=[];
    //playvideo('test');
    playslide(sequencecount);
    function playslide(sequence){
        alert(sequence);
        var data=seqlist[sequence];
        var mediaurl=data['Url'];
        var url=hostname+data['Url']+'='+'?Date='+(new Date()).getTime();
        if(mediaurl.indexOf('media')==-1){
             playslideimage(url);
        }
         else{
             playvideo(url);
         }
        sequencecount++;
        $timeout(function() {
            var data=seqlist[sequencecount];
            time=data['time'];
            playslide(sequencecount);
            alert(time);
        }, time*1000);


    }
    function playslideimage(url){
     window.cache.clear( $scope.frameurl );
     window.cache.clear( $scope.videourl );
     $scope.vid=false;
     $scope.fram=true;
     $scope.videohight=0;
     $scope.iframeHeight = window.innerHeight;
     $scope.frameurl = $sce.trustAsResourceUrl(url);
    }
    function playvideo(url){
        window.cache.clear( $scope.frameurl );
     window.cache.clear( $scope.videourl );

     $scope.vid=true;
     $scope.fram=false;
     $scope.iframeHeight = 0;
     $scope.videohight=window.innerHeight;;
     $scope.videourl= $sce.trustAsResourceUrl('http://.mp4?autoplay');
        var video = document.getElementById('video');
        video.play();

    }



}])

这个 id 是 html

<body>
    <div>
        <video id="video" autobuffer height="{{videohight}}" width="100%">
          <source src="{{videourl}}" type="video/mp4">
        </video>
    </div>
       <iframe id="myFrame" width="100%" data-ng-src="{{frameurl}}" height={{iframeHeight}}></iframe>
</body>

最佳答案

指令可用于此目的,如下所示,

  <Vid auto="true"/>
  <Vid auto="false"/>

  .directive("Vid",function(){
     return {
           restrict : 'E',
           scope :{
             auto :'@'
            }
           link:function(scope,ele,attrs) {
               var ele = angular.element(ele)[0];
              if(scope.auto)
                      ele.autoplay = true; // or ele.play();
              else 
                     ele.autoplay = false;
           }
       }
   })

关于angularjs - 如何在 angularjs 中自动播放视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31025061/

相关文章:

javascript - 如何从 angularjs Controller 返回 html 中的值

javascript - 如何从具有隔离范围的指令中公开行为?

javascript - 手机间隙 : insert query sqlite when login success

javascript - 事件数组未显示在 ionic 日历上

ios - 在 XCode : specified item could not be found in the keychain 中签署应用程序

javascript - 当某些 promise 失败时如何继续 $q.all()

javascript - $setValidity 未实时更新 $valid 标志

android - 使用 HTML5 应用程序访问移动相机

ios - 登录Facebook出现com.facebook.sdk错误2

node.js - Socket.io + NodeJS IONIC CORS 问题