Open cgruca opened 2 years ago
@cgruca Where you are able to solve this problem?
nope, i just never release it
On Tue, May 24, 2022, 5:53 PM Richard Heng @.***> wrote:
@cgruca https://github.com/cgruca Where you are able to solve this problem?
— Reply to this email directly, view it on GitHub https://github.com/zmxv/react-native-sound/issues/785#issuecomment-1136173203, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJQJIEFRARDXZW5H5VHIUWTVLUCOZANCNFSM5QOJJNRQ . You are receiving this because you were mentioned.Message ID: @.***>
I figured out the same thing, never releasing works. Thanks for confirming!
Initializing them outside the component and releasing them on component un-mount will not work. you have to initialize them during component mount.
import { useEffect } from 'react';
import { Button } from 'react-native';
export const Sound = require('react-native-sound');
Sound.setCategory('Playback');
let mySound;
export const MyComp = () => {
useEffect(() => {
mySound = new Sound('mysound.mp3', Sound.MAIN_BUNDLE);
return () => {
mySound.stop();
mySound.release();
};
}, []);
return (
<Button
title={'Play'}
onPress={() => {
mySound.play();
}}
/>
);
};
:beetle: Description
I want to play some music when user loads into the app and stays on a specific screen. I can get the track to play at the start however, once they leave the screen and come back to it later, the sound doesn't play anymore. Any help would be appreciated, thanks.
:beetle: What have you tried? Changing tracks, different methods of playing audio etc.
Is your issue with...
Are you using...
react-native run-android
)Which versions are you using?
Does the problem occur on...
If your problem is happening on a device, which device?