Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
youniaogu committed Oct 7, 2023
1 parent 98c5103 commit f819b31
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/hooks/useVolumeUpDown.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useRef, useState } from 'react';
import { AppStateStatus, Platform } from 'react-native';
import { useFocusEffect } from '@react-navigation/native';
import { AppStateStatus } from 'react-native';
import { VolumeManager } from 'react-native-volume-manager';
import { useAppState } from './useAppState';
import { Volume } from '~/utils';
Expand All @@ -11,7 +11,10 @@ export const useVolumeUpDown = (callback: (type: Volume) => void) => {
const [initVolume, setInitVolume] = useState<number>();

const init = useCallback(() => {
VolumeManager.enable(true);
if (Platform.OS === 'ios') {
VolumeManager.enable(true);
}

VolumeManager.getVolume().then((volume) => {
let prev = typeof volume === 'number' ? volume : volume.volume;

Expand Down Expand Up @@ -58,15 +61,17 @@ export const useVolumeUpDown = (callback: (type: Volume) => void) => {
}, [initVolume, callback]);
const enabledAudioSession = useCallback(
(status: AppStateStatus) => {
if (status === 'active') {
if (audioSessionIsInactiveRef.current) {
VolumeManager.setActive(true);
audioSessionIsInactiveRef.current = false;
init();
if (Platform.OS === 'ios') {
if (status === 'active') {
if (audioSessionIsInactiveRef.current) {
VolumeManager.setActive(true);
audioSessionIsInactiveRef.current = false;
init();
}
} else {
VolumeManager.setActive(false);
audioSessionIsInactiveRef.current = true;
}
} else {
VolumeManager.setActive(false);
audioSessionIsInactiveRef.current = true;
}
},
[init]
Expand Down

0 comments on commit f819b31

Please sign in to comment.