Reputation: 57
How to upload video that I record using my mobile. I manage to upload the video path to Firebase but when I want to use it in my view (html file), it does not work. Here is my code:
.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
My html file
<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>
Upvotes: 2
Views: 889
Reputation: 57
.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
Upvotes: 0
Reputation: 32614
It's hard to tell without running the app myself, but I do see an issue with your record
function.
Don't initialize the $firebaseArray
inside of the record
function, do it when the controller initializes:
.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
};
})
The $firebaseArray
is in sync with the server, so it only needs to be created once.
As for your display issue...
You need to change the src
attribute in <source>
to ng-src
, and use curlys {{ }}
to interpolate:
<video controls>
<source ng-src="{{video.videosrc}}" type="video/mp4">
</video>
For more information on HTML attrs vs directives, see this answer.
Upvotes: 1