Skip to content

Commit 4279da8

Browse files
author
stefan666
committed
code update
1 parent 4740e4e commit 4279da8

12 files changed

+84
-118
lines changed

harmony/sound.har

-785 Bytes
Binary file not shown.

harmony/sound/BuildProfile.ets

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,3 @@
1-
/**
2-
* MIT License
3-
*
4-
* Copyright (C) 2024 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-
261
export default class BuildProfile {
272
static readonly HAR_VERSION = '1.0.0';
283
static readonly BUILD_MODE_NAME = 'debug';

harmony/sound/build-profile.json5

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
{
2-
"apiType": "stageMode",
3-
"buildOption": {
4-
},
5-
"buildOptionSet": [
6-
{
7-
"name": "release",
8-
"arkOptions": {
9-
"obfuscation": {
10-
"ruleOptions": {
11-
"enable": true,
12-
"files": [
13-
"./obfuscation-rules.txt"
14-
]
15-
},
16-
"consumerFiles": [
17-
"./consumer-rules.txt"
18-
]
19-
}
20-
},
2+
"apiType": "stageMode",
3+
"buildOption": {
214
},
22-
],
23-
"targets": [
24-
{
25-
"name": "default"
26-
}
27-
]
5+
"buildOptionSet": [
6+
{
7+
"name": "release",
8+
"arkOptions": {
9+
"obfuscation": {
10+
"ruleOptions": {
11+
"enable": true,
12+
"files": [
13+
"./obfuscation-rules.txt"
14+
]
15+
},
16+
"consumerFiles": [
17+
"./consumer-rules.txt"
18+
]
19+
}
20+
},
21+
},
22+
],
23+
"targets": [
24+
{
25+
"name": "default"
26+
}
27+
]
2828
}

harmony/sound/hvigorfile.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
/**
2-
* MIT License
3-
*
4-
* Copyright (C) 2024 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-
251
import { harTasks } from '@ohos/hvigor-ohos-plugin';
262

273
export default {

harmony/sound/index.ets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
23-
*/
23+
*/

harmony/sound/oh-package-lock.json5

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

harmony/sound/oh-package.json5

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
{
2-
"name": "rnoh-sound",
3-
"version": "0.11.2-1.0.0",
4-
"description": "Please describe the basic information.",
5-
"main": "Index.ets",
6-
"author": "",
7-
"license": "Apache-2.0",
8-
"dependencies": {
9-
"rnoh": "file:../rnoh"
10-
},
11-
"devDependencies": {
12-
"rnoh": "file:../rnoh"
13-
},
14-
}
2+
"name": "sound",
3+
"version": "1.0.0",
4+
"description": "Please describe the basic information.",
5+
"main": "Index.ets",
6+
"author": "",
7+
"license": "Apache-2.0",
8+
"dependencies": {
9+
"rnoh": "file:../rnoh"
10+
}
11+
}

harmony/sound/src/main/cpp/SoundTurboModule.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ static jsi::Value __hostFunction_NativeSoundTurboModuleSpecJSI_getDuration(jsi::
139139
return static_cast<ArkTSTurboModule &>(turboModule).call(rt, "getDuration", args, count);
140140
}
141141

142+
static jsi::Value __hostFunction_NativeSoundTurboModuleSpecJSI_prepare(jsi::Runtime &rt,
143+
react::TurboModule &turboModule,
144+
const jsi::Value *args, size_t count) {
145+
return static_cast<ArkTSTurboModule &>(turboModule).call(rt, "prepare", args, count);
146+
}
147+
142148
NativeSoundTurboModuleSpecJSI::NativeSoundTurboModuleSpecJSI(const ArkTSTurboModule::Context ctx,
143149
const std::string name)
144150
: ArkTSTurboModule(ctx, name) {
@@ -159,5 +165,5 @@ NativeSoundTurboModuleSpecJSI::NativeSoundTurboModuleSpecJSI(const ArkTSTurboMod
159165
methodMap_["getNumberOfLoops"] = MethodMetadata{0, __hostFunction_NativeSoundTurboModuleSpecJSI_getNumberOfLoops};
160166
methodMap_["setNumberOfLoops"] = MethodMetadata{1, __hostFunction_NativeSoundTurboModuleSpecJSI_setNumberOfLoops};
161167
methodMap_["getDuration"] = MethodMetadata{0, __hostFunction_NativeSoundTurboModuleSpecJSI_getDuration};
162-
168+
methodMap_["prepare"] = MethodMetadata{1, __hostFunction_NativeSoundTurboModuleSpecJSI_prepare};
163169
}

harmony/sound/src/main/ets/AVPlayerController.ets

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ const TAG: string = "[RNOH] Sound"
3333
let avPlayer: media.AVPlayer;
3434

3535
export class AVPlayerController {
36-
private volume: number = 1.00;
36+
37+
private volume: number = 1.00;
3738
private speed: number = 1;
3839
private isLoaded: boolean = false;
3940
public isPlaying: boolean = false;
@@ -60,11 +61,6 @@ export class AVPlayerController {
6061
// 创建状态机变化回调函数
6162
this.setAVPlayerCallback();
6263
// 通过UIAbilityContext的resourceManager成员的getRawFd接口获取媒体资源播放地址
63-
// 返回类型为{fd,offset,length},fd为HAP包fd地址,offset为媒体资源偏移量,length为播放长度
64-
let context = getContext(this) as common.UIAbilityContext;
65-
let fileDescriptor = await context.resourceManager.getRawFd('whoosh.mp3');
66-
// 为fdSrc赋值触发initialized状态机上报
67-
avPlayer.fdSrc = fileDescriptor;
6864

6965
//设置默认音量
7066
avPlayer.setVolume(1.00);
@@ -73,6 +69,15 @@ export class AVPlayerController {
7369

7470
}
7571

72+
async setFileDescriptor(fileName: string) {
73+
let context = getContext(this) as common.UIAbilityContext;
74+
// let fileDescriptor = await context.resourceManager.getRawFd('whoosh.mp3');
75+
console.log('setFileDescriptor: ', fileName)
76+
let fileDescriptor = await context.resourceManager.getRawFd(fileName);
77+
// 为fdSrc赋值触发initialized状态机上报
78+
avPlayer.fdSrc = fileDescriptor;
79+
}
80+
7681
// 注册avplayer回调函数
7782
setAVPlayerCallback() {
7883
// 状态机变化回调函数
@@ -84,10 +89,10 @@ export class AVPlayerController {
8489
* 以下代码是为了 调用reset后 无法继续播放
8590
* 在Idle 状态设置 url9+ 或 fdSrc9+属性,AVPlayer会进入initialized状态
8691
*/
87-
let context = getContext(this) as common.UIAbilityContext;
88-
let fileDescriptor = await context.resourceManager.getRawFd('whoosh.mp3');
92+
// let context = getContext(this) as common.UIAbilityContext;
93+
//let fileDescriptor = await context.resourceManager.getRawFd('whoosh.mp3');
8994
// 为fdSrc赋值触发initialized状态机上报
90-
avPlayer.fdSrc = fileDescriptor;
95+
// avPlayer.fdSrc = fileDescriptor;
9196

9297
avPlayer.prepare();
9398

harmony/sound/src/main/ets/SoundTurboModule.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ const TAG: string = "[RNOH] Sound"
3131
export class SoundTurboModule extends TurboModule {
3232
controller: AVPlayerController = new AVPlayerController()
3333

34+
prepare(filename: string) {
35+
this.controller.setFileDescriptor(filename)
36+
}
37+
3438
constructor(protected ctx: TurboModuleContext) {
3539
super(ctx);
3640
Logger.info(TAG, '[RNOH]:SoundTurboModule constructor');
3741
}
3842

43+
3944
setActive(active: boolean): void {
4045
this.controller.setActive(active)
4146
}
@@ -71,6 +76,8 @@ export class SoundTurboModule extends TurboModule {
7176
this.controller.reset();
7277
}
7378

79+
80+
7481
release(): void {
7582
Logger.info(TAG, 'sound : '+ 'release success');
7683
this.controller.release();

0 commit comments

Comments
 (0)