Skip to content

Commit a38ea51

Browse files
authored
Support volume prop (49) (#953)
1 parent 0c95e38 commit a38ea51

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

example/src/AudioPlayerExample.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ export default function AudioPlayerExample() {
2525
isLooping
2626
/>
2727
</Section>
28+
<Section style={{}} title="Adjust volume">
29+
<AudioPlayer
30+
source={require("./assets/loop.wav")}
31+
playsInBackground
32+
interruptionMode="stop"
33+
volume={0.3}
34+
/>
35+
</Section>
2836
<Section style={{}} title="Custom styling">
2937
<AudioPlayer
3038
style={{

packages/core/src/components/MediaPlayer/AudioPlayer/AudioPlayerCommon.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface HeadlessAudioPlayerProps extends MediaPlayerProps {
99
playsInSilentModeIOS?: boolean;
1010
playThroughEarpieceAndroid?: boolean;
1111
isLooping?: boolean;
12+
volume?: number;
1213
}
1314

1415
export interface AudioPlayerInterfaceProps {

packages/core/src/components/MediaPlayer/AudioPlayer/HeadlessAudioPlayer.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const HeadlessAudioPlayer = React.forwardRef<
3232
onPlaybackStatusUpdate: onPlaybackStatusUpdateProp,
3333
onPlaybackFinish,
3434
isLooping = false,
35+
volume = 1.0,
3536
},
3637
ref
3738
) => {
@@ -47,6 +48,12 @@ const HeadlessAudioPlayer = React.forwardRef<
4748
}
4849
}, [currentSound, isLooping]);
4950

51+
React.useEffect(() => {
52+
if (currentSound && typeof currentSound?.setVolumeAsync === "function") {
53+
currentSound.setVolumeAsync(volume);
54+
}
55+
}, [currentSound, volume]);
56+
5057
const updateAudioMode = React.useCallback(async () => {
5158
try {
5259
await Audio.setAudioModeAsync({

0 commit comments

Comments
 (0)