首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >视频:无法动态添加视频

视频:无法动态添加视频
EN

Stack Overflow用户
提问于 2016-05-04 06:35:04
回答 2查看 766关注 0票数 2

我正在使用Ionic开发一个应用程序,并允许用户上传视频。因此,为了播放视频,我集成了Videogular库。

控制器代码

代码语言:javascript
复制
$scope.videoAPI = null;

   $scope.config = {
       playsInline: false,
       preload: "auto",
       autoHide: false,
       autoHideTime: 3000,
       autoPlay: true,
       sources: [],
       theme: "lib/videogular-themes-default/videogular.css",
       plugins: {
           poster: "http://www.videogular.com/assets/images/videogular.png"
       }
   };

   $scope.onPlayerReady = function(api) {
       console.log('onPlayerReady : : ', api);
       $scope.videoAPI = api;
   }


   $scope.uploadVideo = function() {
       if (!deviceType) {
           $('#fileSelect').val('').click();
       } else {
           console.info('Uploading Video..');
           MediaService.browseVideo().then(function(uploadResponse) {
               console.info('video uploadResponse : : ', uploadResponse);
               var response = JSON.parse(uploadResponse.response);
               var videoUrl = response.url.video[0].location;

               //Here I'm Dyncamically setting the URL of my video
               $scope.config.sources.push({
                   src: $sce.trustAsResourceUrl(videoUrl),
                   type: 'video/mp4'
               });
               console.info('Video Uploaded..');
           }).catch(function(error) {
               console.warn('Error while fetching video ', error);
               $scope.showAlert('Video Upload', error);
           });
       }
   };

在上传视频时,$scope.config.sources正在进行适当的更新。但是当我检查DOM时,我没有得到there..Here是屏幕截图的视频

那我该怎么做才能让这件事成功呢?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-05-11 07:00:22

最终解决了it..The问题,我把这个对象推到$scope.config.sources

先于

代码语言:javascript
复制
$scope.config.sources.push({
     src: $sce.trustAsResourceUrl(videoUrl),
     type: 'video/mp4'
 });

代码语言:javascript
复制
$scope.config.sources =[{
    src: $sce.trustAsResourceUrl(videoUrl),
    type: 'video/mp4'
}];

我认为视频并不是deep watch $scope.config对象。因此,我必须每次都重新初始化source对象,而不是插入到source对象中。

票数 0
EN

Stack Overflow用户

发布于 2016-05-07 13:08:38

如果您的MediaService运行在角的摘要周期之外(例如,如果这个承诺来自于jQuery),那么您可能需要执行$scope.$apply()来更新DOM。

代码语言:javascript
复制
$scope.uploadVideo = function() {
   if (!deviceType) {
       $('#fileSelect').val('').click();
   } else {
       console.info('Uploading Video..');
       MediaService.browseVideo().then(function(uploadResponse) {
           console.info('video uploadResponse : : ', uploadResponse);
           var response = JSON.parse(uploadResponse.response);
           var videoUrl = response.url.video[0].location;

           //Here I'm Dyncamically setting the URL of my video
           $scope.config.sources.push({
               src: $sce.trustAsResourceUrl(videoUrl),
               type: 'video/mp4'
           });
           console.info('Video Uploaded..');

           // Trigger digest cycle
           $scope.$apply();

       }).catch(function(error) {
           console.warn('Error while fetching video ', error);
           $scope.showAlert('Video Upload', error);
       });
   }
};
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37020171

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档