我正在使用react-native 开发一个iOS 应用程序。我想使用仍处于“实验”阶段的 MediaRecorder。我在 Safari 高级设置中打开了它,但是当我尝试在我的应用程序中使用它时:
var mediaRecorder = new MediaRecorder(stream)
我收到此错误:
ReferenceError: Can't find variable: MediaRecorder
这个功能在 safari 中运行良好,但我无法让它在我的应用程序中运行。有没有办法在 Xcode/real-native 设置中打开它?
EDIT:
这是我的代码的较大部分。我用反应本机 webrtc https://github.com/react-native-webrtc/react-native-webrtc提供mediaDevices
成分。我确实捕获了流,我遇到的问题是 MediaRecorder。我知道 MediaRecorder 在 safari 浏览器中工作,我的问题是它是否可以在移动 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);