Git Product home page Git Product logo

Comments (3)

xiangyuecn avatar xiangyuecn commented on July 19, 2024

app都支持静默授权,app适配一下就可以了,只要app有系统录音权限就可以了

README里面有写,直接参考就可以了

Recorder/README.md

Lines 317 to 364 in fe968d1

## 【附】Android App - WebView中录音示例
在Android App WebView中使用本库来录音,需要在App源码中实现以下两步分:
1.`AndroidManifest.xml`声明需要用到的两个权限
``` xml
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
```
2. `WebChromeClient`中实现`onPermissionRequest`网页授权请求
``` java
@Override
public void onPermissionRequest(PermissionRequest request) {
//需判断request.getResources()中包含了PermissionRequest.RESOURCE_AUDIO_CAPTURE才进行权限处理,否则不认识的请求直接deny()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//录音是敏感权限,必须app先有录音权限后,网页才会有录音权限,伪代码:
App的系统录音权限请求()
.用户已授权(()->{
//直接静默授权,或者再弹个确认对话框让用户确认是否允许此网页录音后grant|deny
request.grant(request.getResources());
})
.用户拒绝授权(()->{
request.deny();
})
}
}
```
> 注:如果应用的`腾讯X5内核`,除了上面两个权限外,还必须提供`android.permission.CAMERA`权限。另外无法重写此`onPermissionRequest`方法,默认他会自己弹框询问(如果点了拒绝就很惨了),可以通过调用`webView.setWebChromeClientExtension`来重写X5的`IX5WebChromeClientExtension.onPermissionRequest`方法来进行权限处理,参考此篇[X5集成文章](https://www.cnblogs.com/xiangyuecn/p/13450916.html)最后面的网页权限处理代码。
如果不出意外,App内显示的网页就能正常录音了。
[app-support-sample/demo_android](https://github.com/xiangyuecn/Recorder/tree/master/app-support-sample/demo_android)目录中提供了Android测试源码(如果不想自己打包可以用打包好的apk来测试,文件名为`app-debug.apk.zip`,自行去掉.zip后缀)。
> 排查 [#46](https://github.com/xiangyuecn/Recorder/issues/46) `Android WebView`内长按录音不能收到`touchend`问题时,发现touch事件会被打断,反复折腾,最终发现是每次检测权限都会调用`Activity.requestPermissions`,而`requestPermissions`会造成WebView打断touch事件,进而产生H5、AppNative原生录都会产生此问题;最后老实把精简掉的`checkSelfPermission`加上检测一下是否已授权,就没有此问题了,囧。
[](?)
## 【附】iOS App - WebView中录音示例
在iOS App WebView中使用本库来录音,需要在App源码 `Info.plist` 中声明使用麦克风 `NSMicrophoneUsageDescription`,无需其他处理,WebView会自己处理好录音权限;注意:iOS App需要在项目Background Modes中勾选Audio才能在后台保持录音,不然App切到后台后立马会停止录音。
iOS 14.3+以上版本才支持WebView中进行H5录音;iOS 15+提供了静默授权支持,参考[WKUIDelegate](https://developer.apple.com/documentation/webkit/wkuidelegate)中的 `Requesting Permissions` -> `requestMediaCapturePermissionFor`,默认未实现,会导致WebView每次打开后第一次录音时、或长时间无操作再打开录音时均会弹出录音权限对话框。
iOS 11.0-14.2:纯粹的H5录音在iOS WebView中是不支持的,需要有Native层的支持,具体参考RecordApp中的[app-support-sample/demo_ios](https://github.com/xiangyuecn/Recorder/tree/master/app-support-sample/demo_ios),含iOS App源码。

from recorder.

tangtangyue avatar tangtangyue commented on July 19, 2024

ios每次都要重新授权 这个呢

from recorder.

xiangyuecn avatar xiangyuecn commented on July 19, 2024

iOS 14.3+以上版本才支持WebView中进行H5录音;iOS 15+提供了静默授权支持,参考WKUIDelegate中的 Requesting Permissions -> requestMediaCapturePermissionFor,默认未实现,会导致WebView每次打开后第一次录音时、或长时间无操作再打开录音时均会弹出录音权限对话框。

from recorder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.