简体   繁体   English

Safari和录制音频 - HTML媒体捕获/ getUserMedia()

[英]Safari and Recording Audio — HTML Media Capture / getUserMedia()

It looks like getUserMedia() is now the way to go for capturing audio recordings from a user. 看起来getUserMedia()现在是从用户那里捕获录音的方法。

But that leaves out Safari and iOS Safari. 但是这样就省去了Safari和iOS Safari。

Originally I had at least planned to included iOS Safari by taking advantage of the HTML Media Capture spec. 最初我至少计划通过利用HTML Media Capture规范来包含iOS Safari。 From everything I've read, this is suppose to work. 从我读过的所有内容来看,这都是可行的。 But from my tests, iOS will only offer the photo/video options. 但是从我的测试来看,iOS只会提供照片/视频选项。 I've tried the following syntaxes with no luck: 我尝试了以下语法,没有运气:

<input type="file" accept="audio/*;capture=microphone" />
<input type="file" accept="audio/*" capture="microphone">
<input type="file" accept="audio/*" />

Capturing an image works as expected, though, allowing the user to use the camera: 但是,捕获图像可以按预期工作,允许用户使用相机:

<input type="file" accept="image/*" />

What do I need to change in order to get iOS Safari to work with HTML Media Capture when needing access to the microphone? 在需要访问麦克风时,我需要更改以使iOS Safari与HTML Media Capture配合使用?

And are there any other options available for both Safari and iOS Safari other than what I'm already attempting to do? 除了我已经尝试过的操作之外,Safari和iOS Safari还有其他选项吗?

Safari on iOS 6+ supports the HTML Media Capture spec but only for videos and photos: iOS 6+上的Safari支持HTML Media Capture规范,但仅适用于视频和照片:

  • <input type="file" accept="image/*" />
  • <input type="file" accept="video/*" />

It does not support audio only capture so the following will not produce the expected outcome: 它不支持仅音频捕获,因此以下内容不会产生预期结果:

  • <input type="file" accept="audio/*" />

Android supports all 3 (video, audio, image). Android支持所有3(视频,音频,图像)。

Thus support across Android and iOS is as follows: 因此,跨Android和iOS的支持如下:

在此输入图像描述

With Safari on iOS 10.3 the capture boolean attribute is also supported. 使用iOS 10.3上的Safari,还支持capture布尔属性。 It indicates capture directly from the webcam is preferred. 它表示直接从网络摄像头捕获是首选。 When used, the option to choose an existing video or image will not be offered on Safari on iOS 10.3+: 使用时,iOS 10.3+上的Safari不会提供选择现有视频或图像的选项:

  • <input type="file" accept="image/*" capture />

I've written more on the HTML Media Capture topic at https://addpipe.com/blog/correct-syntax-html-media-capture/ 我在https://addpipe.com/blog/correct-syntax-html-media-capture/上写了更多关于HTML媒体捕获主题的文章

UPDATE: New in Safari 11.0 (iOS 11) – Camera and microphone access. 更新:Safari 11.0(iOS 11)中的新功能 - 摄像头和麦克风访问。 Added support for the Media Capture API. 添加了对Media Capture API的支持。 Added ability for websites to access camera and microphone streams from a user's device (user permission is required.) 增加了网站从用户设备访问摄像头和麦克风流的功能(需要用户权限。)

https://developer.apple.com/library/archive/releasenotes/General/WhatsNewInSafari/Articles/Safari_11_0.html https://developer.apple.com/library/archive/releasenotes/General/WhatsNewInSafari/Articles/Safari_11_0.html

Safari still doesn't support getUserMedia properly. Safari仍然不能正确支持getUserMedia It fails on this: 它失败了:

imgCapture = new ImageCapture(stream.getVideoTracks()[0]);

This works in Chrome but Safari has no idea what ImageCapture() is. 这适用于Chrome,但Safari不知道ImageCapture()是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM