Skip to content

Commit 5c73e6c

Browse files
committed
feat: v0.1.5 support silent mode
1 parent a083825 commit 5c73e6c

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

demo/play-in-silent.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: 5.Play in silent
3+
order: 5
4+
---
5+
6+
```jsx
7+
import React, { Component } from 'react';
8+
import ReactDOM from 'react-dom';
9+
import ReactAudioSpectrum from 'react-audio-spectrum';
10+
11+
function App() {
12+
return (
13+
<div>
14+
<audio id="audio-element5"
15+
src="https://reader.guru/medias/How-Long-Will-I-Love-You.mp3"
16+
autoPlay
17+
crossOrigin='anonymous'
18+
controls
19+
>
20+
</audio>
21+
<ReactAudioSpectrum
22+
silent
23+
id="audio-canvas5"
24+
audioId={'audio-element5'}
25+
/>
26+
</div>
27+
);
28+
}
29+
30+
ReactDOM.render((
31+
<App />
32+
), mountNode);
33+
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-audio-spectrum",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"description": "a component for displaying audio spectrum",
55
"files": [
66
"demo/",

src/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type ComponentProps = {
1919
meterColor?: string | ColorItem[],
2020
meterCount?: number,
2121
gap?: number,
22+
silent?: boolean,
2223
};
2324

2425
enum PLAY_STATUS {
@@ -39,6 +40,7 @@ export default function ReactAudioSpectrum(props: ComponentProps) {
3940
],
4041
gap=10,
4142
meterCount=160, meterWidth=2,
43+
silent=false
4244
} = props;
4345
const _audioEleRef = useRef<HTMLElement>()
4446
const _audioCanvasRef = useRef<HTMLCanvasElement>()
@@ -85,7 +87,9 @@ export default function ReactAudioSpectrum(props: ComponentProps) {
8587
// @ts-ignore
8688
_mediaEleSourceRef.current = _audioContextRef.current.createMediaElementSource(audioEle)
8789
_mediaEleSourceRef.current.connect(_audioAnalyserRef.current)
88-
_mediaEleSourceRef.current.connect(_audioContextRef.current.destination);
90+
if (!silent) {
91+
_mediaEleSourceRef.current.connect(_audioContextRef.current.destination);
92+
}
8993
}
9094
}
9195

0 commit comments

Comments
 (0)