我正在开发带有react-native的iOS应用。我想使用仍处于“实验”阶段的MediaRecorder。我在高级Safari设置中将其打开,但是当我尝试在我的应用中使用它时:
var mediaRecorder = new MediaRecorder(stream)
我收到此错误:
ReferenceError: Can't find variable: MediaRecorder
[此功能在Safari中很好用,但是我无法在我的应用中使用它。有没有办法在Xcode / real-native设置中将其打开?
编辑:
这里是我的代码的较大部分。我使用提供react-native-webrtc组件的mediaDevices
。我确实捕获了流,但我遇到的问题是MediaRecorder。我知道MediaRecorder可在野生动物园浏览器中工作,我的问题是,是否可以在移动iOS应用中使用它,如果可以,如何启用它。
import {
RTCPeerConnection,
RTCIceCandidate,
RTCSessionDescription,
RTCView,
MediaStream,
MediaStreamTrack,
mediaDevices,
registerGlobals
} from 'react-native-webrtc';
var mediaRecorder;
const pc_config = {
"iceServers": [
{
urls: 'stun:stun.l.google.com:19302'
}
]
}
var pc = new RTCPeerConnection(pc_config)
const success = (stream) => {
mediaRecorder = new MediaRecorder(stream) //this line throws the error
pc.addStream(stream)
}
const failure = (e) => {
console.log('getUserMedia Error: ', e)
}
const constraints = {
audio: true,
video: {
mandatory: {
minWidth: 200,
minHeight: 200*(16/9),
minFrameRate: 24
},
facingMode: "user"
}
}
mediaDevices.getUserMedia(constraints)
.then(success)
.catch(failure);
MediaRecorder构造函数的语法是
var mediaRecorder = new MediaRecorder(stream[, options]);
原样
navigator.mediaDevices.getUserMedia(constraints).then(function(stream) {
var mediaRecorder = new MediaRecorder(stream);
}
[在激活了实验性MediaRecorder的Safari 13控制台中仅运行以下行:
var mediaRecorder = new MediaRecorder(stream)
我得到以下(预期的)输出:
ReferenceError: Can't find variable: stream