在离子框架中将视频上传到Firebase uing ngCordova($ cordovaCapture)

时间:2015-12-20 11:44:55

标签: angularjs ionic firebase angularfire ngcordova

如何上传我使用移动设备录制的视频。我设法将视频路径上传到Firebase,但是当我想在我的视图(html文件)中使用它时,它不起作用。这是我的代码:

.controller("HomeCtrl", function($scope, $firebaseArray, $cordovaCamera, $location, $cordovaCapture){
  var fb = new Firebase("https://myURL.firebaseio.com/videos");
  $scope.videos;
  $scope.record = function(){
      fb = new Firebase("https://myURL.firebaseio.com/videos");
      $scope.videos = $firebaseArray(fb);
      var options = { limit: 1, duration: 15 };
      $cordovaCapture.captureVideo(options).then(
          function(videoData) {
              var i, path, len;
              var pathtogo;
              var pathtogostring;
              for (i = 0, len = videoData.length; i < len; i += 1) {
                  path = videoData[i].fullPath;
                  pathtogo = path.toString();
                  pathtogostring = pathtogo.substr(6);  
                  alert("Path of the video is = " + path.toString());                                      

                  obj = {
                      videoP: path,
                      videosrc: pathtogostring
                  }
                  $scope.videos.$add(obj);
                }
          },
          function(err) {
          }
      );
  }//end record
 })//end controller 

我的html文件

  <div ng-repeat="video in videos" class="card">

    <div class="item item-text-wrap">
        {{video.videoP}}
    </div>

    <div class="item item-text-wrap">
        {{video.videosrc}}
    </div>

    <video controls>
        <source src="video.videosrc" type="video/mp4">
    </video>
</div>

2 个答案:

答案 0 :(得分:1)

如果不自行运行应用程序很难说,但我确实发现了record功能存在问题。

不要初始化$firebaseArray函数内部的record,在控制器初始化时执行此操作:

.controller("HomeCtrl", function($scope, $firebaseArray, $cordovaCamera, $location, $cordovaCapture){
  var fb = new Firebase("https://myURL.firebaseio.com/videos");
  $scope.videos = $firebaseArray(fb);
  $scope.record = function record() {
     // ... your record code here 
  };
})

$firebaseArray与服务器同步,因此只需创建一次。

至于您的显示问题......

您需要将src中的<source>属性更改为ng-src,并使用大写{{ }}进行插值:

<video controls>
    <source ng-src="{{video.videosrc}}" type="video/mp4">
</video>

For more information on HTML attrs vs directives, see this answer.

答案 1 :(得分:0)

.controller("HomeCtrl", function($scope, $firebaseArray, $location, $cordovaCapture){
var fb = new Firebase("https://myURL.firebaseio.com/videos");
$scope.videos;
$scope.record = function(){
    fb = new Firebase("https://myURL.firebaseio.com/videos");
  $scope.videos = $firebaseArray(fb);
  var options = { limit: 1, duration: 15 };
  $cordovaCapture.captureVideo(options).then(
      function(videoData) {
          var i, path, len;
          var pathtogo;
          var pathtogostring;
          for (i = 0, len = videoData.length; i < len; i += 1) {
              path = videoData[i].fullPath;
              pathtogo = path.toString();


              obj = {
                    videosrc: pathtogo 
              }
              $scope.videos.$add(obj);
            }
      },
      function(err) {
      }
  );
}//end record
 })//end controlle