如何将 Angular promise 与 webrtc (RecordRTC) 结合使用
How use Angular promise with webrtc (RecordRTC)?
对不起我的英语。我正在构建一个使用网络摄像头录制视频的 AngularJS 应用程序(使用 1.2.0 RC2)。我使用RecordRTC来录制视频流。我得到例子。当我使用一个流时,一切正常。但我无法理解,如何在我的控制器中使用这些功能并承诺。
function startRecord(time,text,id){
var deferred = $q.defer();
navigator.getMedia = ( navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia);
navigator.getMedia(
{
audio: true,
video: video_constraints
}, function(stream) {
preview.src = window.URL.createObjectURL(stream);
preview.play();
recordAudio = RecordRTC(stream, {});
recordVideo = RecordRTC(stream, {
type: 'video'
});
recordAudio.startRecording();
recordVideo.startRecording();
$timeout(function() {
saveRecord(id).then(function(data){
if(data.status===200){
deferred.resolve();
$log.info("resolve");
}else{
deferred.reject();
$log.info("reject");
}
})
}, time*1000);
$scope.$apply(function(){
$timeout(function() {
addtext(text);
}, 100);
})
});
return deferred.promise;
}
var fileName;
function saveRecord(id) {
fileName = Math.round(Math.random() * 99999999) + 99999999;
recordAudio.stopRecording();
$scope.save(recordAudio.getBlob(), 'audio', fileName + '.wav',id);
recordVideo.stopRecording();
var save_promise = $scope.save(recordVideo.getBlob(), 'video', fileName + '.webm',id);
return save_promise;
};
$scope.save = function(blob,fileType,fileName,id) {
var save_promise= $http({
method: 'PUT',
url: "/api/videos/"+id,
headers: { 'Content-Type': false },
transformRequest: function (data) {
var formData = new FormData();
formData.append(fileType, fileName);
formData.append(fileType + '-blob', blob,fileName);
return formData;
},
data: { model: fileName, files: '' }
});
return save_promise;
};
我可以创建手动链接承诺
var main = $q.defer();
main.promise
.then(function(questions){
startRecord(questions[0].time,questions[0].text,1)
.then(function(){
startRecord(questions[1].time,questions[1].text,2)
.then(function(){
startRecord(questions[2].time,questions[2].text,3)
})
})
});
主要解决(问题);
但是我从我的 api 中得到的数组问题,它可以是不同的长度。
var questions = [
{id:1,time:10,text:'who are you?'},
{id:2,time:15,text:'where are do you live?'},
{id:3,time:15,text:'why do you live?'},
]
我尝试了不同的变体,但我的 JS 水平非常低。
我找到了适合我的情况的例子。而且所有的工作。
var temp = $q.when({});
var questions = [
{id:1,time:10,text:'who are you?'},
{id:2,time:15,text:'where are do you live?'},
{id:3,time:15,text:'why do you live?'},
]
questions.forEach(function(value) {
temp = temp.then(
function(){
return startRecord(value.time,value.text,value.id);
}
);
}
相关文章:
- javascript结合了数组和字典
- 将Firebase与Electron结合使用
- 结合jQuery和jetpack无限滚动
- 将Angular js与taglib结合使用
- 将图像上传ajax与表单提交ajax相结合
- 将语句与jquery相结合,并使用媒体查询来实现返回页首按钮
- 将broccoliJS与当前使用requireJS的模块化主干应用程序结合使用,我想完全放弃requireJS
- jQuery结合了2个绑定函数(类型错误:a是未定义的)
- 媒体查询与Javascript相结合
- 将Ionic与智能卡(Java卡)结合使用
- 有可能将SYSTEMJS与REQUIREJS结合起来吗
- 将Browserify与Angular JS结合使用--将服务传递到控制器中
- 结合jQuery和普通JS
- 为什么可以'我将谷歌地图getCurrentPosition与地点搜索API相结合
- 如何将纹理打包器与纯javascript结合使用
- 将TypeAhead与jQuery和Bootstrap 2.1结合使用
- javascript结合了公共和私有窗口.onload
- 使用RecordRTC录制的WebRTC视频在IE和Safari中显示错误
- 如何将grunt autoprefixer和grunt sass结合使用
- 如何将 Angular promise 与 webrtc (RecordRTC) 结合使用