Skip to content

Commit 107480b

Browse files
author
ZhangMeng
committed
fix:兼容file://开头的音频路径
1 parent 0bba6bd commit 107480b

File tree

4 files changed

+14
-41
lines changed

4 files changed

+14
-41
lines changed

README.md

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,17 @@
1-
![banner](/banner.png)
1+
# react-native-audio-toolkit
22

3-
[![npm version](https://badge.fury.io/js/%40react-native-community%2Faudio-toolkit.svg)](https://badge.fury.io/js/%40react-native-community%2Faudio-toolkit)
3+
本项目基于 [react-native-audio-toolkit](https://github.com/react-native-audio-toolkit/react-native-audio-toolkit)
44

5-
This is a cross-platform (Android and iOS) audio library for React Native.
6-
Both audio playback and recording is supported. In addition to basic
7-
functionality, many useful features are implemented such as seeking,
8-
looping and streaming audio files over the network.
5+
## 文档地址 / Documentation URL
96

10-
An example how to use this library is included in the [ExampleApp](/ExampleApp)
11-
directory. The demo showcases most of the functionality that is available, with
12-
documentation under [docs](/docs). In the simplest case, playing media is as
13-
easy as:
7+
[中文 / Chinese](https://gitee.com/react-native-oh-library/usage-docs/blob/master/zh-cn/react-native-audio-toolkit.md)
148

15-
```js
16-
new Player('filename.mp4').play();
17-
```
9+
## Codegen
1810

19-
and recording media to filename.mp4 similarly
20-
```js
21-
new Recorder(‘filename.mp4’).record();
22-
```
11+
该库已接入 codegen,具体请查阅文档。
2312

24-
How to get this stuff running?
25-
------------------------------
13+
The library has been integrated with codegen. Please refer to the documentation for details.
2614

27-
* For a quick test drive, check out the [demo application](/ExampleApp)
28-
* [Include the library](/docs/SETUP.md) in your project
15+
## 请悉知 / Acknowledgements
2916

30-
Documentation
31-
-------------
32-
33-
* Find the API documentation [here](/docs/API.md)
34-
* Examples on playback from various [media sources](/docs/SOURCES.md)
35-
* Notes on [developing the library itself](/docs/DEVELOPING.md)
36-
* Rough [state diagram](/docs/state_diagram.svg) of the [Player](src/Player.js)
37-
* View the [changelog](/CHANGELOG.md)
38-
39-
License
40-
-------
41-
42-
All JavaScript, Android and iOS code licensed under MIT license, see LICENSE
43-
file. Some of the files are from React Native templates and are licensed
44-
accordingly.
17+
本项目基于 [The MIT License (MIT)](hhttps://github.com/react-native-audio-toolkit/react-native-audio-toolkit/blob/master/LICENSE) ,请自由地享受和参与开源。

harmony/audio_toolkit/src/main/ets/RNCAudioPlayerTurboModule.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ enum StateChange {
4545

4646
export class RCTAudioPlayerTurboModule extends TurboModule {
4747
private readonly SANDBOX_START = '/data/storage';
48-
private readonly FILE_MANAGER_START = 'file://docs';
48+
private readonly FILE_MANAGER_START = 'file://';
49+
private readonly HTTP_START = 'http';
4950
private readonly FD_PATH = 'fd://';
5051
private playerMap: Map<number, media.AVPlayer> = new Map()
5152
private playConfigMap: Map<number, PlayConfig> = new Map()
@@ -242,7 +243,7 @@ export class RCTAudioPlayerTurboModule extends TurboModule {
242243
try {
243244
const avPlayer: media.AVPlayer = await media.createAVPlayer()
244245
this.setAVPlayerCallback(avPlayer, playerId)
245-
if (pathStr.startsWith('http')) {
246+
if (pathStr.startsWith(this.HTTP_START)) {
246247
avPlayer.url = pathStr
247248
} else {
248249
let fdPath = this.FD_PATH
@@ -367,7 +368,7 @@ export class RCTAudioPlayerTurboModule extends TurboModule {
367368
}
368369

369370
async seek(playerId: number, position: number, callback: () => void) {
370-
logger.info(`seekbar:${position}`)
371+
logger.debug(`seekbar:${position}`)
371372
if (!this.checkPlayer(playerId, callback)) {
372373
return
373374
}

src/Player.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class Player extends EventEmitter {
9595
}
9696

9797
_handleEvent(event, data) {
98-
//console.error('event: ' + event + ', data: ' + JSON.stringify(data));
98+
//console.log('event: ' + event + ', data: ' + JSON.stringify(data));
9999
switch (event) {
100100
case 'progress':
101101
// TODO

src/Recorder.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ class Recorder extends EventEmitter {
6868
}
6969

7070
prepare(callback = noop) {
71-
//harmony 选择文件切到后台,不能再次打开文件路径选择器
7271
if (Platform.OS !== 'harmony') {
7372
this._updateState(null, MediaStates.PREPARING);
7473
// Prepare recorder

0 commit comments

Comments
 (0)