From b1f57a42c32f90e2f0df4a2dc16f823627d6ea4f Mon Sep 17 00:00:00 2001
From: fanqingbiao
Date: Fri, 23 Feb 2024 14:36:15 +0800
Subject: [PATCH 1/2] =?UTF-8?q?[Issues:=20#I92Y4J]=20=E6=B7=BB=E5=8A=A0rea?=
=?UTF-8?q?ct-native-sound=20=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
1224/react-native-sound.md | 337 +++++++++++++++++++++++++++++++++++++
1 file changed, 337 insertions(+)
create mode 100644 1224/react-native-sound.md
diff --git a/1224/react-native-sound.md b/1224/react-native-sound.md
new file mode 100644
index 00000000..62cf3dfc
--- /dev/null
+++ b/1224/react-native-sound.md
@@ -0,0 +1,337 @@
+> 模板版本:v0.1.3
+
+
+
react-native-sound
+
+
+
+
+
+
+
+
+
+
+
+
+> [!TIP] [Github 地址](https://github.com/react-native-oh-library/react-native-sound)
+
+## 安装与使用
+
+请到三方库的 Releases 发布地址查看配套的版本信息:[<@react-native-oh-library/react-native-sound> Releases](https://github.com/react-native-oh-library/react-native-sound/releases),并下载适用版本的 tgz 包。
+
+进入到工程目录并输入以下命令:
+
+>[!TIP] # 处替换为 tgz 包的路径
+
+
+
+#### npm
+
+```bash
+npm install @react-native-oh-tpl/react-native-sound@file:#
+```
+
+#### yarn
+
+```bash
+yarn add @react-native-oh-tpl/react-native-sound@file:#
+```
+
+
+
+下面的代码展示了这个库的基本使用场景:
+
+>[!WARNING] 使用时 import 的库名不变。
+
+```tsx
+import React, { useState } from 'react';
+import type {PropsWithChildren} from 'react';
+import {
+ SafeAreaView,
+ ScrollView,
+ StatusBar,
+ StyleSheet,
+ Text,
+ useColorScheme,
+ View,
+ Button
+} from 'react-native';
+
+import {
+ Colors,
+ DebugInstructions,
+ Header,
+ LearnMoreLinks,
+ ReloadInstructions,
+} from 'react-native/Libraries/NewAppScreen';
+
+import Sound from 'react-native-sound';
+
+type SectionProps = PropsWithChildren<{
+ title: string;
+ func: ()=> void;
+}>;
+
+type SliderSectionProps = PropsWithChildren<{
+ duration:number;
+ value: number;
+ func: ()=> void;
+}>;
+
+function Section({title,func}: SectionProps): JSX.Element {
+ const isDarkMode = useColorScheme() === 'dark';
+ return (
+
+
+
+ );
+}
+
+function SoundDemo(): JSX.Element {
+ const isDarkMode = useColorScheme() === 'dark';
+ const backgroundStyle = {
+ backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
+ };
+
+ const navigationOptions = (props: { navigation: { state: { params: { title: any; }; }; }; }) => ({
+ title:props.navigation.state.params.title,}
+ );
+
+let sound=new Sound();
+
+ const onPlay=()=>{
+ sound.play();
+ }
+
+ return (
+
+
+
+
+
+
+
+
+
+
+ );
+}
+
+const styles = StyleSheet.create({
+ sectionContainer: {
+ marginTop: 12,
+ paddingHorizontal: 24,
+ },
+ sectionTitle: {
+ fontSize: 24,
+ fontWeight: '600',
+ },
+ sectionDescription: {
+ marginTop: 8,
+ fontSize: 18,
+ fontWeight: '400',
+ },
+ highlight: {
+ fontWeight: '700',
+ },
+});
+
+export default SoundDemo;
+
+```
+
+## Link
+
+目前鸿蒙暂不支持 AutoLink,所以 Link 步骤需要手动配置。
+
+首先需要使用 DevEco Studio 打开项目里的鸿蒙工程 `harmony`
+
+### 引入原生端代码
+
+目前有两种方法:
+
+1. 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法);
+2. 直接链接源码。
+
+方法一:通过 har 包引入
+
+> [!TIP] har 包位于三方库安装路径的 `harmony` 文件夹下。
+
+打开 `entry/oh-package.json5`,添加以下依赖
+
+```json
+"dependencies": {
+ "rnoh": "file:../rnoh",
+ "rnoh-sound": "file:../../node_modules/@react-native-oh-tpl/react-native-sound/harmony/sound.har"
+ }
+```
+
+点击右上角的 `sync` 按钮
+
+或者在终端执行:
+
+```bash
+cd entry
+ohpm install
+```
+
+方法二:直接链接源码
+
+> [!TIP] 源码位于三方库安装路径的 `harmony` 文件夹下。
+
+打开 `entry/oh-package.json5`,添加以下依赖
+
+```json
+"dependencies": {
+ "rnoh": "file:../rnoh",
+ "rnoh-sound": "file:../../node_modules/@react-native-oh-tpl/react-native-sound/harmony/sound"
+ }
+```
+
+打开终端,执行:
+
+```bash
+cd entry
+ohpm install --no-link
+```
+
+### 配置 CMakeLists 和引入 SoundPackge
+
+打开 `entry/src/main/cpp/CMakeLists.txt`,添加:
+
+```diff
+txtproject(rnapp)
+cmake_minimum_required(VERSION 3.4.1)
+set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
+set(OH_MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
+set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp")
+
+add_subdirectory("${RNOH_CPP_DIR}" ./rn)
+
+# RNOH_BEGIN: add_package_subdirectories
+add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package)
++ add_subdirectory("${OH_MODULE_DIR}/rnoh-sound/src/main/cpp" ./sound)
+# RNOH_END: add_package_subdirectories
+
+add_library(rnoh_app SHARED
+ "./PackageProvider.cpp"
+ "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
+)
+
+target_link_libraries(rnoh_app PUBLIC rnoh)
+
+# RNOH_BEGIN: link_packages
+target_link_libraries(rnoh_app PUBLIC rnoh_sample_package)
++ target_link_libraries(rnoh_app PUBLIC rnoh_sound)
+# RNOH_END: link_packages
+```
+
+打开 `entry/src/main/cpp/PackageProvider.cpp`,添加:
+
+```diff
+#include "RNOH/PackageProvider.h"
+#include "SamplePackage.h"
++ #include "SoundPackage.h"
+
+using namespace rnoh;
+
+std::vector> PackageProvider::getPackages(Package::Context ctx) {
+ return {
+ std::make_shared(ctx),
++ std::make_shared(ctx),
+ };
+}
+```
+
+### 在 ArkTs 侧引入 SoundPackage
+
+打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加:
+
+```diff
+...
++ import { SoundPackage } from 'rnoh-sound/ts';
+
+export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
+ return [
+ new SamplePackage(ctx),
++ new SoundPackage(ctx)
+ ];
+}
+```
+
+### 运行
+
+点击右上角的 `sync` 按钮
+
+或者在终端执行:
+
+```bash
+cd entry
+ohpm install
+```
+
+然后编译、运行即可。
+
+## 约束与限制
+
+### 兼容性
+
+要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。
+
+请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:[<@react-native-oh-library/react-native-sound> Releases](https://github.com/react-native-oh-library/react-native-sound/releases)
+
+## 静态方法
+
+> [!tip] "Platform"列表示该属性在原三方库上支持的平台。
+
+> [!tip] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
+
+详情请见[react-native-sound](https://github.com/react-native-oh-library/react-native-sound)
+
+| Name | Description | Type | Required | Platform | HarmonyOS Support |
+| --------- | -------------------------------- | ------ | -------- | ----------- | ----------------- |
+| setActive | Set the device activation status | string | No | IOS/Android | yes |
+
+## API
+
+> [!tip] "Platform"列表示该属性在原三方库上支持的平台。
+
+> [!tip] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
+
+详情请见[react-native-sound](https://github.com/react-native-oh-library/react-native-sound)
+
+| Name | Description | Type | Required | Platform | HarmonyOS Support |
+| -------------- | ---------------------------------------- | ------ | -------- | ----------- | ----------------- |
+| setActive | Set the device activation status. | string | No | IOS/Android | yes |
+| play | Start playing audio. | string | No | IOS/Android | yes |
+| pause | Pause audio playback. | string | No | IOS/Android | yes |
+| stop | Stop playing audio. | string | No | IOS/Android | yes |
+| reset | Reset Audio Status. | string | No | Android | yes |
+| release | Releasing audio resources. | string | No | IOS/Android | yes |
+| getVolume | Obtains the audio volume. | string | No | IOS/Android | yes |
+| setVolume | Setting the Relative Audio Volume. | string | No | IOS/Android | yes |
+| getCurrentTime | Obtains the current playback time point. | string | No | IOS/Android | yes |
+| setCurrentTime | Sets the playback time point. | string | No | IOS/Android | yes |
+| getSpeed | Obtains the playback speed. | string | No | IOS/Android | yes |
+| setSpeed | Setting the Playback Speed | string | No | IOS/Android | yes |
+| isPlaying | Whether the audio is being played | string | No | IOS/Android | yes |
+
+## 其他
+
+## 开源协议
+
+本项目基于 [The MIT License (MIT)](https://github.com/itinance/react-native-fs/blob/master/LICENSE) ,请自由地享受和参与开源。
\ No newline at end of file
--
Gitee
From 6d516b9425291fc6288596311007666b9650fb09 Mon Sep 17 00:00:00 2001
From: fanqingbiao
Date: Fri, 23 Feb 2024 15:17:07 +0800
Subject: [PATCH 2/2] =?UTF-8?q?[Issues:=20#I92Y4J]=20=E6=B7=BB=E5=8A=A0rea?=
=?UTF-8?q?ct-native-sound=20=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
1224/react-native-sound.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/1224/react-native-sound.md b/1224/react-native-sound.md
index 62cf3dfc..33e76029 100644
--- a/1224/react-native-sound.md
+++ b/1224/react-native-sound.md
@@ -4,16 +4,17 @@
react-native-sound
-
+
-
+
+
> [!TIP] [Github 地址](https://github.com/react-native-oh-library/react-native-sound)
## 安装与使用
@@ -316,7 +317,6 @@ ohpm install
| Name | Description | Type | Required | Platform | HarmonyOS Support |
| -------------- | ---------------------------------------- | ------ | -------- | ----------- | ----------------- |
-| setActive | Set the device activation status. | string | No | IOS/Android | yes |
| play | Start playing audio. | string | No | IOS/Android | yes |
| pause | Pause audio playback. | string | No | IOS/Android | yes |
| stop | Stop playing audio. | string | No | IOS/Android | yes |
--
Gitee