Can I use experimental WebKit features in my iOS app?

时光毁灭记忆、已成空白 提交于 2020-06-16 18:03:56

问题


I am developing an iOS app with react-native. I wanted to use MediaRecorder which is still in 'experimental' phase. I turned it on in advanced Safari settings but when I try to use it in my app:

var mediaRecorder = new MediaRecorder(stream)

I get this error:

ReferenceError: Can't find variable: MediaRecorder

This feature works well in safari, but I can't get it to work in my app. Is there a way to turn it on in Xcode/real-native settings?

EDIT:

Here is the larger section of my code. I use react-native-webrtc that provides mediaDevices component. I do capture the stream, the problem I have is with MediaRecorder. I know that MediaRecorder works in safari browser, the question I have is if it can be used in a mobile iOS app and if so, how to enable it.

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);

回答1:


The MediaRecorder constructor syntax is

var mediaRecorder = new MediaRecorder(stream[, options]);

as in

navigator.mediaDevices.getUserMedia(constraints).then(function(stream) {
    var mediaRecorder = new MediaRecorder(stream);
}

When running only the following line in the Safari 13 console with Experimental MediaRecorder activated:

var mediaRecorder = new MediaRecorder(stream)

I get the following (expected) output:

ReferenceError: Can't find variable: stream


来源:https://stackoverflow.com/questions/62205865/can-i-use-experimental-webkit-features-in-my-ios-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!