@ayden-fc2/riffle-bridge-web 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## 1. tweaks和RiffleBridge用法总览
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
本文档为当前Web应用提供Bridge使用指导,以连接外层native应用。分为必选的tweaks和可选的RiffleBridge两个API。
|
|
6
6
|
|
|
7
7
|
**安装依赖:**
|
|
8
8
|
```bash
|
|
@@ -167,7 +167,7 @@ const tilt = bridge.utils.getTiltDirection(x, y);
|
|
|
167
167
|
单例模式实现,主要用于不需要用户交互就直接播放的背景音乐等,点击音效等仍由web应用本身实现
|
|
168
168
|
|
|
169
169
|
```
|
|
170
|
-
// 播放,支持传入 local://xxx 或 file://xxx
|
|
170
|
+
// 播放,支持传入 local://xxx 或 file://xxx 的native本地路径,或 https://xxx 的url网址
|
|
171
171
|
await bridge.audio.playOnline({ uri: playUri });
|
|
172
172
|
|
|
173
173
|
// 播放并循环(适用于背景音乐)
|
|
@@ -208,6 +208,7 @@ console.log('时长:', result.durationMillis / 1000, '秒');
|
|
|
208
208
|
|
|
209
209
|
// 保存录音(以aydens-voice为例,实际可以替换为web应用的独特键,或者result.uri的独特文件名)
|
|
210
210
|
if (result?.uri) {
|
|
211
|
+
// 保存文件到native应用并记录map
|
|
211
212
|
await bridge.fileStorage.addCustomFileMapping('local://recording/aydens-voice', result.uri);
|
|
212
213
|
}
|
|
213
214
|
|
|
@@ -241,7 +242,9 @@ document.body.style.background = 'transparent';
|
|
|
241
242
|
document.documentElement.style.background = 'transparent';
|
|
242
243
|
document.getElementById('root')!.style.background = 'transparent';
|
|
243
244
|
|
|
244
|
-
// 拍照
|
|
245
|
+
// 拍照
|
|
246
|
+
// ⚠️ 拍照后不要直接渲染,参考下方**拍照/相册**的代码,先调用readAsBase64转码再渲染!
|
|
247
|
+
// ⚠️ 拍照后如果需要保存,也参考下方**拍照/相册**的代码调用native的文件存储模块保存并记录map
|
|
245
248
|
const photo = await bridge.camera.takePhoto();
|
|
246
249
|
|
|
247
250
|
// 切换摄像头
|
|
@@ -289,13 +292,14 @@ await bridge.camera.setFilter('none');
|
|
|
289
292
|
// 1. 拍照(以aydens-demo-photo为例,实际web应用使用picked.uri文件名或组特的key)
|
|
290
293
|
const photo = await bridge.fileStorage.takePhoto();
|
|
291
294
|
if (!photo?.cancelled) {
|
|
292
|
-
//
|
|
295
|
+
// 保存文件到native应用并记录map
|
|
293
296
|
await bridge.fileStorage.addCustomFileMapping('local://photos/aydens-demo-photo', photo.uri);
|
|
294
297
|
}
|
|
295
298
|
|
|
296
299
|
// 2. 或从相册选择(以aydens-photo为例,实际web应用使用picked.uri文件名或组特的key)
|
|
297
300
|
const picked = await bridge.fileStorage.pickFromGallery();
|
|
298
301
|
if (!picked?.cancelled) {
|
|
302
|
+
// 保存文件到native应用并记录map
|
|
299
303
|
await bridge.fileStorage.addCustomFileMapping('local://photos/aydens-demo-photo', picked.uri);
|
|
300
304
|
}
|
|
301
305
|
|
|
@@ -345,6 +349,11 @@ console.log(result.cached ? '使用缓存' : '已下载', result.uri);
|
|
|
345
349
|
const base64 = await bridge.fileStorage.readAsBase64(url);
|
|
346
350
|
```
|
|
347
351
|
|
|
352
|
+
**读取资源并解码base64,从native传入web**
|
|
353
|
+
```
|
|
354
|
+
// uri为mapRecord记录值
|
|
355
|
+
const base64 = await bridge.fileStorage.readAsBase64(mapRecord);
|
|
356
|
+
```
|
|
348
357
|
|
|
349
358
|
|
|
350
359
|
### 3.6 设备信息模块
|