我可以在我的 iOS 应用程序中使用实验性 WebKit 功能吗? [英] Can I use experimental WebKit features in my iOS app?

查看:102
本文介绍了我可以在我的 iOS 应用程序中使用实验性 WebKit 功能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 react-native 开发 iOS 应用.我想使用仍处于实验"阶段的 MediaRecorder.我在高级 Safari 设置中打开了它,但是当我尝试在我的应用中使用它时:

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)

我收到此错误:

ReferenceError: Can't find variable: MediaRecorder

此功能在 safari 中运行良好,但我无法在我的应用中使用它.有没有办法在 Xcode/真实本机设置中打开它?

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?

这是我的代码的较大部分.我使用 react-native-webrtc 提供 mediaDevices 组件.我确实捕获了流,我遇到的问题是 MediaRecorder.我知道 MediaRecorder 可以在 safari 浏览器中使用,我的问题是它是否可以在移动 iOS 应用程序中使用,如果可以,如何启用它.

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

推荐答案

MediaRecorder 构造函数语法是

The MediaRecorder constructor syntax is

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

就像在

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

在 Safari 13 控制台中仅运行以下行并激活实验 MediaRecorder 时:

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

这篇关于我可以在我的 iOS 应用程序中使用实验性 WebKit 功能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆