@react-native-ohos/react-native-audio-recorder-player 3.7.0-rc.2 → 3.7.1-beta.1

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 CHANGED
@@ -1,14 +1,753 @@
1
- # @react-native-ohos/react-native-audio-recorder-player
1
+ > 模板版本:v0.2.2
2
2
 
3
- This project is based on [react-native-audio-recorder-player@3.6.13](https://github.com/hyochan/react-native-audio-recorder-player/tree/3.6.13)
3
+ <p align="center">
4
+ <h1 align="center"> <code>react-native-audio-recorder-player</code> </h1>
5
+ </p>
6
+ <p align="center">
7
+ <a href="https://github.com/hyochan/react-native-audio-recorder-player">
8
+ <img src="https://img.shields.io/badge/platforms-android%20|%20ios%20|%20harmony%20-lightgrey.svg" alt="Supported platforms" />
9
+ </a>
10
+ <a href="https://github.com/hyochan/react-native-audio-recorder-player/blob/main/LICENSE">
11
+ <img src="https://img.shields.io/badge/license-MIT-green.svg" alt="License" />
12
+ </a>
13
+ </p>
4
14
 
5
- ## Documentation
15
+ > [!TIP] [Github 地址](https://github.com/react-native-oh-library/react-native-audio-recorder-player)
6
16
 
7
- - [中文](https://gitee.com/react-native-oh-library/usage-docs/blob/master/zh-cn/react-native-audio-recorder-player.md)
17
+ ## 安装与使用
8
18
 
9
- - [English](https://gitee.com/react-native-oh-library/usage-docs/blob/master/en/react-native-audio-recorder-player.md)
19
+ 请到三方库的 Releases 发布地址查看配套的版本信息:
10
20
 
11
- ## License
21
+ | 三方库版本 | 发布信息 | 支持RN版本 |
22
+ | ---------- | ------------------------------------------------------------ | ---------- |
23
+ | <= 3.6.10-0.0.2@deprecated | [@react-native-oh-tpl/react-native-audio-recorder-player Releases(deprecated)](https://github.com/react-native-oh-library/react-native-audio-recorder-player/releases) | 0.72 |
24
+ | 3.6.11 | [@react-native-ohos/react-native-audio-recorder-player Releases](https://gitcode.com/openharmony-sig/rntpc_react-native-audio-recorder-player/releases) | 0.72 |
25
+ | 3.7.0 | [@react-native-ohos/react-native-audio-recorder-player Releases](https://gitcode.com/openharmony-sig/rntpc_react-native-audio-recorder-player/releases) | 0.77 |
12
26
 
13
- This library is licensed under [The MIT License (MIT)](https://github.com/hyochan/react-native-audio-recorder-player/blob/main/LICENSE)
27
+ 对于未发布到npm的旧版本,请参考[安装指南](/tgz-usage.md)安装tgz包。
14
28
 
29
+ 进入到工程目录并输入以下命令:
30
+
31
+ #### **npm**
32
+
33
+ ```bash
34
+ npm install @react-native-ohos/react-native-audio-recorder-player
35
+ ```
36
+
37
+ #### **yarn**
38
+
39
+ ```bash
40
+ yarn add @react-native-ohos/react-native-audio-recorder-player
41
+ ```
42
+
43
+ 下面的代码展示了这个库的基本使用场景:
44
+
45
+ > [!WARNING] 使用时 import 的库名不变。
46
+
47
+ ```js
48
+ import AudioRecorderPlayer, {
49
+ AVEncoderAudioQualityIOSType,
50
+ AVEncodingOption,
51
+ AudioEncoderAndroidType,
52
+ AudioSourceAndroidType,
53
+ OutputFormatAndroidType,
54
+ AudioMimeHarmonyType,
55
+ AudioFormatHarmonyType,
56
+ AudioSourceHarmonyType,
57
+ AudioSet
58
+ } from 'react-native-audio-recorder-player'; import type {
59
+ PlayBackType,
60
+ RecordBackType,
61
+ } from 'react-native-audio-recorder-player';
62
+
63
+ import {
64
+ Dimensions,
65
+ Platform,
66
+ ActivityIndicator,
67
+ Image,
68
+ SafeAreaView,
69
+ StyleSheet,
70
+ Text,
71
+ TouchableOpacity,
72
+ View,
73
+ } from 'react-native';
74
+ import React, { Component } from 'react';
75
+
76
+ import type { ReactElement, ReactNode } from 'react';
77
+
78
+ const stylesButton: any = StyleSheet.create({
79
+ btn: {
80
+ backgroundColor: 'transparent',
81
+ alignSelf: 'center',
82
+ borderRadius: 4,
83
+ borderWidth: 2,
84
+ width: 320,
85
+ height: 52,
86
+ borderColor: 'white',
87
+
88
+ alignItems: 'center',
89
+ justifyContent: 'center',
90
+ },
91
+ btnDisabled: {
92
+ backgroundColor: 'rgb(243,243,243)',
93
+ alignSelf: 'center',
94
+ borderRadius: 4,
95
+ borderWidth: 2,
96
+ width: 320,
97
+ height: 52,
98
+ borderColor: '#333',
99
+
100
+ alignItems: 'center',
101
+ justifyContent: 'center',
102
+ },
103
+ txt: {
104
+ fontSize: 14,
105
+ color: 'white',
106
+ },
107
+ imgLeft: {
108
+ width: 24,
109
+ height: 24,
110
+ position: 'absolute',
111
+ left: 16,
112
+ },
113
+ });
114
+
115
+ interface ItemProps {
116
+ children?: ReactNode;
117
+ isLoading?: boolean;
118
+ isDisabled?: boolean;
119
+ onPress?: () => void;
120
+ style?: any;
121
+ disabledStyle?: any;
122
+ textStyle?: any;
123
+ imgLeftSrc?: any;
124
+ imgLeftStyle?: any;
125
+ indicatorColor?: string;
126
+ activeOpacity?: number;
127
+ }
128
+
129
+ class Button extends Component<ItemProps, any> {
130
+ private static defaultProps: Partial<ItemProps> = {
131
+ isLoading: false,
132
+ isDisabled: false,
133
+ style: stylesButton.btn,
134
+ textStyle: stylesButton.txt,
135
+ imgLeftStyle: stylesButton.imgLeft,
136
+ indicatorColor: 'white',
137
+ activeOpacity: 0.5,
138
+ };
139
+
140
+ constructor(props: ItemProps) {
141
+ super(props);
142
+ this.state = {};
143
+ }
144
+
145
+ public render(): ReactElement {
146
+ if (this.props.isDisabled) {
147
+ return (
148
+ <View style={this.props.disabledStyle}>
149
+ <Text style={this.props.textStyle}>{this.props.children}</Text>
150
+ </View>
151
+ );
152
+ }
153
+
154
+ if (this.props.isLoading) {
155
+ return (
156
+ <View style={this.props.style}>
157
+ <ActivityIndicator size="small" color={this.props.indicatorColor} />
158
+ </View>
159
+ );
160
+ }
161
+
162
+ return (
163
+ <TouchableOpacity
164
+ activeOpacity={this.props.activeOpacity}
165
+ onPress={this.props.onPress}>
166
+ <View style={this.props.style}>
167
+ {this.props.imgLeftSrc ? (
168
+ <Image
169
+ style={this.props.imgLeftStyle}
170
+ source={this.props.imgLeftSrc}
171
+ />
172
+ ) : null}
173
+ <Text style={this.props.textStyle}>{this.props.children}</Text>
174
+ </View>
175
+ </TouchableOpacity>
176
+ );
177
+ }
178
+ }
179
+
180
+ const styles: any = StyleSheet.create({
181
+ container: {
182
+ flex: 1,
183
+ backgroundColor: '#455A64',
184
+ flexDirection: 'column',
185
+ alignItems: 'center',
186
+ height: Dimensions.get('screen').height
187
+ },
188
+ titleTxt: {
189
+ marginTop: 100,
190
+ color: 'white',
191
+ fontSize: 28,
192
+ },
193
+ viewRecorder: {
194
+ marginTop: 40,
195
+ width: '100%',
196
+ alignItems: 'center',
197
+ },
198
+ recordBtnWrapper: {
199
+ flexDirection: 'row',
200
+ },
201
+ viewPlayer: {
202
+ marginTop: 60,
203
+ alignSelf: 'stretch',
204
+ alignItems: 'center',
205
+ },
206
+ viewBarWrapper: {
207
+ marginTop: 28,
208
+ marginHorizontal: 28,
209
+ alignSelf: 'stretch',
210
+ },
211
+ viewBar: {
212
+ backgroundColor: '#ccc',
213
+ height: 4,
214
+ alignSelf: 'stretch',
215
+ },
216
+ viewBarPlay: {
217
+ backgroundColor: 'white',
218
+ height: 4,
219
+ width: 0,
220
+ },
221
+ playStatusTxt: {
222
+ marginTop: 8,
223
+ color: '#ccc',
224
+ },
225
+ playBtnWrapper: {
226
+ flexDirection: 'row',
227
+ marginTop: 40,
228
+ },
229
+ btn: {
230
+ borderColor: 'white',
231
+ borderWidth: 1,
232
+ },
233
+ txt: {
234
+ color: 'white',
235
+ fontSize: 14,
236
+ marginHorizontal: 8,
237
+ marginVertical: 4,
238
+ },
239
+ txtRecordCounter: {
240
+ marginTop: 32,
241
+ color: 'white',
242
+ fontSize: 20,
243
+ textAlignVertical: 'center',
244
+ fontWeight: '200',
245
+ fontFamily: 'Helvetica Neue',
246
+ letterSpacing: 3,
247
+ width: 300
248
+ },
249
+ txtCounter: {
250
+ marginTop: 12,
251
+ color: 'white',
252
+ fontSize: 20,
253
+ textAlignVertical: 'center',
254
+ fontWeight: '200',
255
+ fontFamily: 'Helvetica Neue',
256
+ letterSpacing: 3,
257
+ width: 300
258
+ },
259
+ });
260
+
261
+ interface State {
262
+ isLoggingIn: boolean;
263
+ recordSecs: number;
264
+ recordTime: string;
265
+ currentPositionSec: number;
266
+ currentDurationSec: number;
267
+ playTime: string;
268
+ duration: string;
269
+ }
270
+
271
+ const screenWidth = Dimensions.get('screen').width;
272
+
273
+ class Page extends Component<any, State> {
274
+ private audioRecorderPlayer
275
+
276
+ constructor(props: any) {
277
+ super(props);
278
+ this.state = {
279
+ isLoggingIn: false,
280
+ recordSecs: 0,
281
+ recordTime: '00:00:00',
282
+ currentPositionSec: 0,
283
+ currentDurationSec: 0,
284
+ playTime: '00:00:00',
285
+ duration: '00:00:00',
286
+ };
287
+
288
+ this.audioRecorderPlayer = new AudioRecorderPlayer()
289
+ this.audioRecorderPlayer.setSubscriptionDuration(0.5); // optional. Default is 0.5
290
+ }
291
+
292
+ public render(): ReactElement {
293
+ let playWidth =
294
+ (this.state.currentPositionSec / this.state.currentDurationSec) *
295
+ (screenWidth - 56);
296
+
297
+ if (!playWidth) {
298
+ playWidth = 0;
299
+ }
300
+
301
+ return (
302
+ <SafeAreaView style={styles.container}>
303
+ <Text style={styles.titleTxt}>Audio Recorder Player</Text>
304
+ <Text style={styles.txtRecordCounter}>{this.state.recordTime}</Text>
305
+ <View style={styles.viewRecorder}>
306
+ <View style={styles.recordBtnWrapper}>
307
+ <Button
308
+ style={styles.btn}
309
+ onPress={this.onStartRecord}
310
+ textStyle={styles.txt}>
311
+ startRecord
312
+ </Button>
313
+ <Button
314
+ style={[
315
+ styles.btn,
316
+ {
317
+ marginLeft: 12,
318
+ },
319
+ ]}
320
+ onPress={this.onPauseRecord}
321
+ textStyle={styles.txt}>
322
+ Pause
323
+ </Button>
324
+ <Button
325
+ style={[
326
+ styles.btn,
327
+ {
328
+ marginLeft: 12,
329
+ },
330
+ ]}
331
+ onPress={this.onResumeRecord}
332
+ textStyle={styles.txt}>
333
+ Resume
334
+ </Button>
335
+ <Button
336
+ style={[styles.btn, { marginLeft: 12 }]}
337
+ onPress={this.onStopRecord}
338
+ textStyle={styles.txt}>
339
+ Stop
340
+ </Button>
341
+ </View>
342
+ </View>
343
+ <View style={styles.viewPlayer}>
344
+ <TouchableOpacity
345
+ style={styles.viewBarWrapper}
346
+ onPress={this.onStatusPress}>
347
+ <View style={styles.viewBar}>
348
+ <View style={[styles.viewBarPlay, { width: playWidth }]} />
349
+ </View>
350
+ </TouchableOpacity>
351
+ <Text style={styles.txtCounter}>
352
+ {this.state.playTime} / {this.state.duration}
353
+ </Text>
354
+ <View style={styles.playBtnWrapper}>
355
+ <Button
356
+ style={styles.btn}
357
+ onPress={this.onStartPlay}
358
+ textStyle={styles.txt}>
359
+ Play
360
+ </Button>
361
+ <Button
362
+ style={[
363
+ styles.btn,
364
+ {
365
+ marginLeft: 12,
366
+ },
367
+ ]}
368
+ onPress={this.onPausePlay}
369
+ textStyle={styles.txt}>
370
+ Pause
371
+ </Button>
372
+ <Button
373
+ style={[
374
+ styles.btn,
375
+ {
376
+ marginLeft: 12,
377
+ },
378
+ ]}
379
+ onPress={this.onResumePlay}
380
+ textStyle={styles.txt}>
381
+ Resume
382
+ </Button>
383
+ <Button
384
+ style={[
385
+ styles.btn,
386
+ {
387
+ marginLeft: 12,
388
+ },
389
+ ]}
390
+ onPress={this.onStopPlay}
391
+ textStyle={styles.txt}>
392
+ Stop
393
+ </Button>
394
+ </View>
395
+ </View>
396
+ </SafeAreaView>
397
+ );
398
+ }
399
+
400
+ private onStatusPress = (e: any): void => {
401
+ const touchX = e.nativeEvent.locationX;
402
+ console.log(`touchX: ${touchX}`);
403
+
404
+ const playWidth =
405
+ (this.state.currentPositionSec / this.state.currentDurationSec) *
406
+ (screenWidth - 56);
407
+ console.log(`currentPlayWidth: ${playWidth}`);
408
+
409
+ const currentPosition = Math.round(this.state.currentPositionSec);
410
+
411
+ if (playWidth && playWidth < touchX) {
412
+ const addSecs = Math.round(currentPosition + 1000);
413
+ this.audioRecorderPlayer.seekToPlayer(addSecs);
414
+ console.log(`addSecs: ${addSecs}`);
415
+ } else {
416
+ const subSecs = Math.round(currentPosition - 1000);
417
+ this.audioRecorderPlayer.seekToPlayer(subSecs);
418
+ console.log(`subSecs: ${subSecs}`);
419
+ }
420
+ };
421
+
422
+ private onStartRecord = async (): Promise<void> => {
423
+
424
+ const audioSet: AudioSet = {
425
+ AudioEncoderAndroid: AudioEncoderAndroidType.AAC,
426
+ AudioSourceAndroid: AudioSourceAndroidType.MIC,
427
+ AVEncoderAudioQualityKeyIOS: AVEncoderAudioQualityIOSType.high,
428
+ AVNumberOfChannelsKeyIOS: 2,
429
+ AVFormatIDKeyIOS: AVEncodingOption.aac,
430
+ OutputFormatAndroid: OutputFormatAndroidType.AAC_ADTS,
431
+ AudioSourceHarmony: AudioSourceHarmonyType.MIC,
432
+ AudioMimeHarmony: AudioMimeHarmonyType.AUDIO_AAC,
433
+ AudioFileFormatHarmony: AudioFormatHarmonyType.MPEG_4A,
434
+ AudioEncodingBitRateHarmony: 3200,
435
+ AudioSamplingRateHarmony: 44100,
436
+ AudioChannelsHarmony: 2,
437
+ };
438
+
439
+ console.log('audioSet', audioSet);
440
+
441
+ const uri = await this.audioRecorderPlayer.startRecorder(
442
+ 'audio.m4a',
443
+ audioSet,
444
+ );
445
+
446
+ this.audioRecorderPlayer.addRecordBackListener((e: RecordBackType) => {
447
+ console.log('record-back', e);
448
+ this.setState({
449
+ recordSecs: e.currentPosition,
450
+ recordTime: this.audioRecorderPlayer.mmssss(
451
+ Math.floor(e.currentPosition),
452
+ ),
453
+ });
454
+ });
455
+
456
+ console.log(`uri: ${uri}`);
457
+ };
458
+
459
+ private onPauseRecord = async (): Promise<void> => {
460
+ try {
461
+ const r = await this.audioRecorderPlayer.pauseRecorder();
462
+ console.log(r);
463
+ } catch (err) {
464
+ console.log('pauseRecord', err);
465
+ }
466
+ };
467
+
468
+ private onResumeRecord = async (): Promise<void> => {
469
+ await this.audioRecorderPlayer.resumeRecorder();
470
+ };
471
+
472
+ private onStopRecord = async (): Promise<void> => {
473
+ const result = await this.audioRecorderPlayer.stopRecorder();
474
+ this.audioRecorderPlayer.removeRecordBackListener();
475
+ this.setState({
476
+ recordSecs: 0,
477
+ });
478
+ console.log(result, '>>>>>>>stopRecorder');
479
+ };
480
+
481
+ private onStartPlay = async (): Promise<void> => {
482
+ console.log('onStartPlay');
483
+
484
+ try {
485
+ const msg = await this.audioRecorderPlayer.startPlayer('https://sis-sample-audio.obs.cn-north-1.myhuaweicloud.com/16k16bit.mp3', { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20100101 Firefox/21.0' });
486
+ const volume = await this.audioRecorderPlayer.setVolume(1);
487
+ this.audioRecorderPlayer.addPlayBackListener((e: PlayBackType) => {
488
+ console.log('playBackListener', e);
489
+ this.setState({
490
+ currentPositionSec: e.currentPosition,
491
+ currentDurationSec: e.duration,
492
+ playTime: this.audioRecorderPlayer.mmssss(e.currentPosition),
493
+ duration: this.audioRecorderPlayer.mmssss(Math.floor(e.duration)),
494
+ });
495
+ });
496
+
497
+ } catch (err) {
498
+ console.log('startPlayer error', err);
499
+ }
500
+ };
501
+
502
+ private onPausePlay = async (): Promise<void> => {
503
+ await this.audioRecorderPlayer.pausePlayer();
504
+ };
505
+
506
+ private onResumePlay = async (): Promise<void> => {
507
+ await this.audioRecorderPlayer.resumePlayer();
508
+ };
509
+
510
+ private onStopPlay = async (): Promise<void> => {
511
+ console.log('onStopPlay');
512
+ this.audioRecorderPlayer.stopPlayer();
513
+ this.audioRecorderPlayer.removePlayBackListener();
514
+ };
515
+ }
516
+
517
+ export default Page;
518
+
519
+ ```
520
+
521
+ ## Link
522
+
523
+ | | 是否支持autolink | RN框架版本 |
524
+ |--------------------------------------|-----------------|------------|
525
+ | ~3.7.0 | No | 0.77 |
526
+ | ~3.6.11 | Yes | 0.72 |
527
+ | <= 3.6.10-0.0.2@deprecated | No | 0.72 |
528
+
529
+ 使用AutoLink的工程需要根据该文档配置,Autolink框架指导文档:https://gitcode.com/openharmony-sig/ohos_react_native/blob/master/docs/zh-cn/Autolinking.md
530
+
531
+ 如您使用的版本支持 Autolink,并且工程已接入 Autolink,可跳过ManualLink配置。
532
+ <details>
533
+ <summary>ManualLink: 此步骤为手动配置原生依赖项的指导</summary>
534
+
535
+ 首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 `harmony`。
536
+
537
+ ### 在工程根目录的 `oh-package.json5` 添加 overrides 字段
538
+
539
+ ```json
540
+ {
541
+ ...
542
+ "overrides": {
543
+ "@rnoh/react-native-openharmony" : "./react_native_openharmony"
544
+ }
545
+ }
546
+ ```
547
+
548
+ ### 引入原生端代码
549
+
550
+ 目前有两种方法:
551
+
552
+ 1. 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法);
553
+ 2. 直接链接源码。
554
+
555
+ 方法一:通过 har 包引入(推荐)
556
+
557
+ > [!TIP] har 包位于三方库安装路径的 `harmony` 文件夹下。
558
+
559
+ 打开 `entry/oh-package.json5`,添加以下依赖
560
+
561
+ ```json
562
+ "dependencies": {
563
+ "@rnoh/react-native-openharmony": "file:../react_native_openharmony",
564
+
565
+ "@react-native-ohos/react-native-audio-recorder-player": "file:../../node_modules/@react-native-ohos/react-native-audio-recorder-player/harmony/audio_recorder_player.har"
566
+ }
567
+ ```
568
+ 点击右上角的 `sync` 按钮
569
+
570
+ 或者在终端执行:
571
+
572
+ ```bash
573
+ cd entry
574
+ ohpm install
575
+ ```
576
+ 方法二:直接链接源码
577
+
578
+ > [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](/link-source-code.md)
579
+
580
+ ### 配置 CMakeLists 和引入 RNAudioRecorderPlayerPackage
581
+
582
+ > 若使用的是 <= 3.6.10-0.0.2 版本,请跳过本章。
583
+
584
+ 打开 `entry/src/main/cpp/CMakeLists.txt`,添加:
585
+
586
+ ```diff
587
+ project(rnapp)
588
+ cmake_minimum_required(VERSION 3.4.1)
589
+ set(CMAKE_SKIP_BUILD_RPATH TRUE)
590
+ set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
591
+ set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules")
592
+ + set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
593
+ set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp")
594
+ set(LOG_VERBOSITY_LEVEL 1)
595
+ set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments")
596
+ set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie")
597
+ set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use
598
+ add_compile_definitions(WITH_HITRACE_SYSTRACE)
599
+
600
+ add_subdirectory("${RNOH_CPP_DIR}" ./rn)
601
+
602
+ # RNOH_BEGIN: manual_package_linking_1
603
+ add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package)
604
+ + add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-audio-recorder-player/src/main/cpp" ./audio_recorder_player)
605
+
606
+ # RNOH_END: manual_package_linking_1
607
+
608
+ file(GLOB GENERATED_CPP_FILES "./generated/*.cpp")
609
+
610
+ add_library(rnoh_app SHARED
611
+ ${GENERATED_CPP_FILES}
612
+ "./PackageProvider.cpp"
613
+ "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
614
+ )
615
+ target_link_libraries(rnoh_app PUBLIC rnoh)
616
+
617
+ # RNOH_BEGIN: manual_package_linking_2
618
+ target_link_libraries(rnoh_app PUBLIC rnoh_sample_package)
619
+ + target_link_libraries(rnoh_app PUBLIC rnoh_audio_recorder_player)
620
+ # RNOH_END: manual_package_linking_2
621
+ ```
622
+ 打开 `entry/src/main/cpp/PackageProvider.cpp`,添加:
623
+
624
+ ```diff
625
+ #include "RNOH/PackageProvider.h"
626
+ #include "generated/RNOHGeneratedPackage.h"
627
+ #include "SamplePackage.h"
628
+ + #include "RNAudioRecorderPlayerPackage.h"
629
+
630
+ using namespace rnoh;
631
+
632
+ std::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Context ctx) {
633
+ return {
634
+ std::make_shared<RNOHGeneratedPackage>(ctx),
635
+ std::make_shared<SamplePackage>(ctx),
636
+ + std::make_shared<RNAudioRecorderPlayerPackage>(ctx)
637
+ };
638
+ }
639
+ ```
640
+
641
+ ### 在 ArkTs 侧引入 RNAudioRecorderPlayerPackage
642
+
643
+ 打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加:
644
+
645
+ ```diff
646
+ + import {RNAudioRecorderPlayerPackage} from '@react-native-ohos/react-native-audio-recorder-player/ts';
647
+
648
+ export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
649
+ return [
650
+ new SamplePackage(ctx),
651
+ + new RNAudioRecorderPlayerPackage(ctx)
652
+ ];
653
+ }
654
+ ```
655
+ </details>
656
+
657
+ ## 运行
658
+
659
+ 点击右上角的 `sync` 按钮
660
+
661
+ 或者在终端执行:
662
+
663
+ ```bash
664
+ cd entry
665
+ ohpm install
666
+ ```
667
+ 然后编译、运行即可。
668
+
669
+ ## 约束与限制
670
+
671
+ ### 兼容性
672
+
673
+ 要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。
674
+
675
+ 在以下版本验证通过:
676
+
677
+ 1. RNOH: 0.72.96; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112;
678
+ 2. RNOH: 0.72.33; SDK: HarmonyOS NEXT B1; IDE: DevEco Studio: 5.0.3.900; ROM: Next.0.0.71;
679
+ 3. RNOH: 0.77.18; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112;
680
+
681
+ ### 权限要求
682
+
683
+ #### 在 entry 目录下的module.json5中添加权限
684
+
685
+ 打开 `entry/src/main/module.json5`,添加:
686
+
687
+ ```diff
688
+ ...
689
+ "requestPermissions": [
690
+ + {"name": "ohos.permission.INTERNET"},//网络播放音频需添加
691
+ + {
692
+ + "name": "ohos.permission.MICROPHONE",
693
+ + "reason": "$string:Access_Create_Audio",
694
+ + "usedScene": {
695
+ + "abilities": [
696
+ + "EntryAbility"
697
+ + ],
698
+ + "when": "always"
699
+ + }
700
+ + },
701
+ ]
702
+ ]
703
+ ```
704
+ #### 在 entry 目录下添加申请权限的原因
705
+
706
+ 打开 `entry/src/main/resources/base/element/string.json`,添加:
707
+
708
+ ```diff
709
+ ...
710
+ {
711
+ "string": [
712
+ + {
713
+ + "name": "Access_Create_Audio",
714
+ + "value": "access create Audio"
715
+ + },
716
+ ]
717
+ }
718
+ ```
719
+ ## API
720
+
721
+ > [!TIP] "Platform"列表示该属性在原三方库上支持的平台。
722
+
723
+ > [!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
724
+
725
+ | Name | Description | Type | Required | Platform | HarmonyOS Support |
726
+ | ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- | -------- | ------------- | ----------------- |
727
+ | `mmss` | 将毫秒转换为 分:秒 格式字符串 | function(milliseconds:number): string | No | Android,iOS | yes |
728
+ | `mmssss` | 将毫秒转换为 分:秒:毫秒 格式字符串 | function(milliseconds:number): string | No | Android,iOS | yes |
729
+ | `setSubscriptionDuration` | 设置录音/播放器启动后的默认回调间隔,默认值0.5即500毫秒 | function(seconds:float):void | No | Android,iOS | yes |
730
+ | `addRecordBackListener` | 注册录音原生回调,回调数据包含当前录制时长、音量分贝(开启录音音量采集时返回) | function(callBack:(value:RecordBackType)=>void): void | No | Android,iOS | yes |
731
+ | `removeRecordBackListener` | 移除录音监听回调 | function(): void | No | Android,iOS | yes |
732
+ | `addPlayBackListener` | 注册播放器原生回调,回调数据包含音频总时长、当前播放进度 | function(callBack:(value: PlayBackType)=>void): void | No | Android,iOS | yes |
733
+ | `removePlayBackListener` | 移除播放监听回调 | function(): void | No | Android,iOS | yes |
734
+ | `startRecorder` | 开始录音;不传文件路径uri则音频保存至系统默认目录,audioSets中的AudioFileFormatHarmony可传参数包含AudioFormatHarmonyType.AAC、AudioFormatHarmonyType.MPEG_4、AudioFormatHarmonyType.MPEG_4A、AudioFormatHarmonyType.MP3、AudioFormatHarmonyType.WAV | function(uri?:string,audioSets?: AudioSet,meteringEnabled?: boolean): Promise< string > | No | Android,iOS | yes |
735
+ | `pauseRecorder` | 暂停录音 | function() : Promise< string > | No | Android,iOS | yes |
736
+ | `resumeRecorder` | 恢复录音 | function() : Promise< string > | No | Android,iOS | yes |
737
+ | `stopRecorder` | 停止录音 | function() : Promise< string > | No | Android,iOS | yes |
738
+ | `startPlayer` | 开始播放音频;不传参数则播放默认目录音频文件,支持传入网络请求头用于在线音频加载 | function(uri?:string,httpHeaders?:Record<string,string>) : Promise< string > | No | Android,iOS | yes |
739
+ | `stopPlayer` | 停止播放 | function() : Promise< string > | No | Android,iOS | yes |
740
+ | `pausePlayer` | 暂停播放 | function() : Promise< string > | No | Android,iOS | yes |
741
+ | `resumePlayer` | 恢复播放 | function() : Promise< string > | No | Android,iOS | yes |
742
+ | `seekToPlayer` | 跳转到指定毫秒播放位置 | function(milliseconds:number) : Promise< string > | No | Android,iOS | yes |
743
+ | `setVolume` | 设置播放器音量,默认1.0,取值范围 0.0 ~ 1.0 | function(volume:float) : Promise< string > | No | Android,iOS | yes |
744
+ | `setPlaybackSpeed`<sup>3.6.14+</sup> | 设置播放倍速<br/>鸿蒙适配后仅支持 0.125、0.25、0.5、0.75、1、1.25、1.5、1.75、2、3 倍速;其中3倍速仅支持API 13及以上版本 | function(playbackSpeed: number): Promise< string > | No | Android,iOS | partially |
745
+
746
+
747
+ ## 遗留问题
748
+
749
+ ## 其他
750
+
751
+ ## 开源协议
752
+
753
+ 本项目基于 [The MIT License (MIT)](https://github.com/hyochan/react-native-audio-recorder-player/blob/main/LICENSE) ,请自由地享受和参与开源。
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Use these variables when you tailor your ArkTS code. They must be of the const type.
3
3
  */
4
- export const HAR_VERSION = '3.6.14-rc.1';
4
+ export const HAR_VERSION = '3.6.14-beta.1';
5
5
  export const BUILD_MODE_NAME = 'debug';
6
6
  export const DEBUG = true;
7
7
  export const TARGET_NAME = 'default';
@@ -5,7 +5,7 @@
5
5
  "name": "@react-native-ohos/react-native-audio-recorder-player",
6
6
  "description": "",
7
7
  "main": "index.ets",
8
- "version": "3.7.0-rc.2",
8
+ "version": "3.7.1-beta.1",
9
9
  "dependencies": {
10
10
  "@rnoh/react-native-openharmony": "file:../../node_modules/@react-native-oh/react-native-harmony/harmony/react_native_openharmony.har"
11
11
  },
@@ -23,7 +23,7 @@
23
23
  */
24
24
  import { TurboModule, TurboModuleContext, } from '@rnoh/react-native-openharmony/ts';
25
25
  import { media } from '@kit.MediaKit';
26
- import { AudioSet } from '.';
26
+ import type { AudioSet } from '.';
27
27
  import Recorder from './recorder/Recorder';
28
28
  import { AVRecorderState, defaultBitrate, defaultChannels, defaultSampleRate, RecordBackName, } from './recorder/types';
29
29
  import AudioPlayer from './audioPlayer/AudioPlayer';
@@ -0,0 +1,210 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2023 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ export enum AudioSourceHarmonyType {
26
+ DEFAULT = 0,
27
+ MIC,
28
+ VOICE_RECOGNITION,
29
+ VOICE_COMMUNICATION = 7,
30
+ VOICE_MESSAGE = 10,
31
+ CAMCORDER = 12,
32
+ }
33
+
34
+ export enum AudioFormatHarmonyType {
35
+ MPEG_4 = 'mp4',
36
+ MPEG_4A = 'm4a',
37
+ MP3 = 'mp3',
38
+ WAV = 'wav',
39
+ AAC = 'aac',
40
+ }
41
+
42
+ export enum AudioMimeHarmonyType {
43
+ VIDEO_H263 = 'video/h263', // 表示视频/h263类型。
44
+ VIDEO_AVC = 'video/avc', // 表示视频/avc类型。
45
+ VIDEO_MPEG2 = 'video/mpeg2', // 表示视频/mpeg2类型。
46
+ VIDEO_MPEG4 = 'video/mp4v-es', // 表示视频/mpeg4类型。
47
+ VIDEO_VP8 = 'video/x-vnd.on2.vp8', // 表示视频/vp8类型。
48
+ VIDEO_HEVC = 'video/hevc', // 表示视频/H265类型。
49
+ AUDIO_AAC = 'audio/mp4a-latm', // 表示音频/mp4a-latm类型。
50
+
51
+ AUDIO_VORBIS = 'audio/vorbis', // 表示音频/vorbis类型。
52
+ AUDIO_FLAC = 'audio/flac', // 表示音频/flac类型。
53
+ AUDIO_MP3 = 'audio/mpeg', // 表示音频/mpeg类型。
54
+ AUDIO_G711MU = 'audio/g711mu', // 表示音频/G711-mulaw类型。
55
+ }
56
+
57
+ export enum AudioSourceAndroidType {
58
+ DEFAULT = 0,
59
+ MIC,
60
+ VOICE_UPLINK,
61
+ VOICE_DOWNLINK,
62
+ VOICE_CALL,
63
+ CAMCORDER,
64
+ VOICE_RECOGNITION,
65
+ VOICE_COMMUNICATION,
66
+ REMOTE_SUBMIX,
67
+ UNPROCESSED,
68
+ RADIO_TUNER = 1998,
69
+ HOTWORD,
70
+ }
71
+
72
+ export enum OutputFormatAndroidType {
73
+ DEFAULT = 0,
74
+ THREE_GPP,
75
+ MPEG_4,
76
+ AMR_NB,
77
+ AMR_WB,
78
+ AAC_ADIF,
79
+ AAC_ADTS,
80
+ OUTPUT_FORMAT_RTP_AVP,
81
+ MPEG_2_TS,
82
+ WEBM,
83
+ UNUSED,
84
+ OGG,
85
+ }
86
+
87
+ export enum AudioEncoderAndroidType {
88
+ DEFAULT = 0,
89
+ AMR_NB,
90
+ AMR_WB,
91
+ AAC,
92
+ HE_AAC,
93
+ AAC_ELD,
94
+ VORBIS,
95
+ OPUS,
96
+ }
97
+
98
+ export enum AVEncodingOption {
99
+ lpcm = 'lpcm',
100
+ ima4 = 'ima4',
101
+ aac = 'aac',
102
+ MAC3 = 'MAC3',
103
+ MAC6 = 'MAC6',
104
+ ulaw = 'ulaw',
105
+ alaw = 'alaw',
106
+ mp1 = 'mp1',
107
+ mp2 = 'mp2',
108
+ mp4 = 'mp4',
109
+ alac = 'alac',
110
+ amr = 'amr',
111
+ flac = 'flac',
112
+ opus = 'opus',
113
+ wav = 'wav',
114
+ }
115
+
116
+ type AVEncodingType =
117
+ | AVEncodingOption.lpcm
118
+ | AVEncodingOption.ima4
119
+ | AVEncodingOption.aac
120
+ | AVEncodingOption.MAC3
121
+ | AVEncodingOption.MAC6
122
+ | AVEncodingOption.ulaw
123
+ | AVEncodingOption.alaw
124
+ | AVEncodingOption.mp1
125
+ | AVEncodingOption.mp2
126
+ | AVEncodingOption.mp4
127
+ | AVEncodingOption.alac
128
+ | AVEncodingOption.amr
129
+ | AVEncodingOption.flac
130
+ | AVEncodingOption.opus
131
+ | AVEncodingOption.wav;
132
+
133
+ export enum AVModeIOSOption {
134
+ gamechat = 'gamechat',
135
+ measurement = 'measurement',
136
+ movieplayback = 'movieplayback',
137
+ spokenaudio = 'spokenaudio',
138
+ videochat = 'videochat',
139
+ videorecording = 'videorecording',
140
+ voicechat = 'voicechat',
141
+ voiceprompt = 'voiceprompt',
142
+ }
143
+
144
+ export type AVModeIOSType =
145
+ | AVModeIOSOption.gamechat
146
+ | AVModeIOSOption.measurement
147
+ | AVModeIOSOption.movieplayback
148
+ | AVModeIOSOption.spokenaudio
149
+ | AVModeIOSOption.videochat
150
+ | AVModeIOSOption.videorecording
151
+ | AVModeIOSOption.voicechat
152
+ | AVModeIOSOption.voiceprompt;
153
+
154
+ export enum AVEncoderAudioQualityIOSType {
155
+ min = 0,
156
+ low = 32,
157
+ medium = 64,
158
+ high = 96,
159
+ max = 127,
160
+ }
161
+
162
+ export enum AVLinearPCMBitDepthKeyIOSType {
163
+ 'bit8' = 8,
164
+ 'bit16' = 16,
165
+ 'bit24' = 24,
166
+ 'bit32' = 32,
167
+ }
168
+
169
+ export interface AudioSet {
170
+ AVSampleRateKeyIOS?: number;
171
+ AVFormatIDKeyIOS?: AVEncodingType;
172
+ AVModeIOS?: AVModeIOSType;
173
+ AVNumberOfChannelsKeyIOS?: number;
174
+ AVEncoderAudioQualityKeyIOS?: AVEncoderAudioQualityIOSType;
175
+ AudioSourceAndroid?: AudioSourceAndroidType;
176
+ AVLinearPCMBitDepthKeyIOS?: AVLinearPCMBitDepthKeyIOSType;
177
+ AVLinearPCMIsBigEndianKeyIOS?: boolean;
178
+ AVLinearPCMIsFloatKeyIOS?: boolean;
179
+ AVLinearPCMIsNonInterleavedIOS?: boolean;
180
+ AVEncoderBitRateKeyIOS?: number;
181
+ OutputFormatAndroid?: OutputFormatAndroidType;
182
+ AudioEncoderAndroid?: AudioEncoderAndroidType;
183
+ AudioEncodingBitRateAndroid?: number;
184
+ AudioSamplingRateAndroid?: number;
185
+ AudioChannelsAndroid?: number;
186
+ AudioSourceHarmony?: AudioSourceHarmonyType;
187
+ AudioMimeHarmony?: AudioMimeHarmonyType;
188
+ AudioFileFormatHarmony?: AudioFormatHarmonyType;
189
+ AudioEncodingBitRateHarmony?: number;
190
+ AudioSamplingRateHarmony?: number;
191
+ AudioChannelsHarmony?: number;
192
+ }
193
+
194
+ export type RecordBackType = {
195
+ isRecording?: boolean;
196
+ currentPosition: number;
197
+ currentMetering?: number;
198
+ };
199
+
200
+ export type PlayBackType = {
201
+ isMuted?: boolean;
202
+ currentPosition: number;
203
+ duration: number;
204
+ isFinished: boolean;
205
+ };
206
+
207
+ export enum harmonyEventName {
208
+ recordBack = 'rn-recordback',
209
+ playBack = 'rn-playback'
210
+ }
Binary file
package/index.ts CHANGED
@@ -29,7 +29,8 @@ export enum AudioFormatHarmonyType {
29
29
  MPEG_4 = 'mp4',
30
30
  MPEG_4A = 'm4a',
31
31
  MP3 = 'mp3',
32
- WAV = 'wav'
32
+ WAV = 'wav',
33
+ AAC = 'aac'
33
34
  }
34
35
 
35
36
  export enum AudioMimeHarmonyType {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-ohos/react-native-audio-recorder-player",
3
- "version": "3.7.0-rc.2",
3
+ "version": "3.7.1-beta.1",
4
4
  "description": "React Native Audio Recorder and Player.",
5
5
  "homepage": "https://gitcode.com/openharmony-sig/rntpc_react-native-audio-recorder-player",
6
6
  "main": "index.ts",
@@ -9,7 +9,8 @@
9
9
  "scripts": {
10
10
  "test": "echo \"Error: no test specified\" && exit 1",
11
11
  "build": "tsc && flowgen index.d.ts -o index.js.flow",
12
- "lint": "eslint -c .eslintrc.js 'index.ts'"
12
+ "lint": "eslint -c .eslintrc.js 'index.ts'",
13
+ "pack": "npm pack --ignore-scripts"
13
14
  },
14
15
  "harmony": {
15
16
  "alias": "react-native-audio-recorder-player"
@@ -31,8 +32,7 @@
31
32
  "src",
32
33
  "harmony",
33
34
  "index.ts",
34
- "index.d.ts",
35
- "RNAudioRecorderPlayer.podspec"
35
+ "index.d.ts"
36
36
  ],
37
37
  "author": "dooboolab",
38
38
  "license": "MIT",
@@ -57,3 +57,4 @@
57
57
  "typescript": "^4.9.4"
58
58
  }
59
59
  }
60
+
@@ -1,21 +0,0 @@
1
- require 'json'
2
-
3
- package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
-
5
- Pod::Spec.new do |s|
6
- s.name = "RNAudioRecorderPlayer"
7
- s.version = package['version']
8
- s.summary = package['description']
9
- s.license = package['license']
10
-
11
- s.authors = package['author']
12
- s.homepage = package['homepage']
13
- s.platform = :ios, "11.0"
14
- s.ios.deployment_target = "10.0"
15
-
16
- s.source = { :git => "https://github.com/hyochan/react-native-audio-recorder-player.git", :tag => "#{s.version}" }
17
- s.source_files = "ios/**/*.{h,c,cc,cpp,m,mm,swift}"
18
-
19
- s.dependency 'React-Core'
20
- end
21
-