[BUG] .getInfo() --> Crash
Describe the bug
When there are no media playing but you call .getInfo() the app crashes even with try/catch blocks. Returning null would make much more sense.
Expected behavior
The app should never crash. An error should be catchable.
Platform
Just installed the module and only tested it on Android Emulator.
Additional context
Hey @sayem314
Opened a PR that should address your issue: https://github.com/johnsonsu/react-native-sound-player/pull/122
I haven't had the time to test it on ios, but on android it works as expected:
import React, { useState, useEffect } from 'react';
import { Button, View, Text } from 'react-native';
import { default as SoundPlayer } from 'react-native-sound-player'
const App = () => {
const [isPlaying, setIsPlaying] = useState(false);
useEffect(() => {
SoundPlayer
.getInfo()
.then(a => console.log("yeay", a))
.catch(b => console.error("ney", b));
})
useEffect(() => {
SoundPlayer.loadUrl("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3")
return () => SoundPlayer.stop();
}, []);
useEffect(() => {
if (isPlaying) {
SoundPlayer.play();
} else {
SoundPlayer.pause();
}
}, [isPlaying]);
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Home Screen</Text>
<Button
title={isPlaying ? "stop" : "play"}
onPress={() => setIsPlaying((isPlaying) => !isPlaying)}
/>
</View>
);
};
export default App;
results in
LOG Running "SoundDemo" with {"rootTag":1}
ERROR ney [Error: Media player is not instantiated!]
LOG yeay {"currentTime": 0, "duration": 0}
LOG yeay {"currentTime": 0, "duration": 0}
LOG yeay {"currentTime": 0, "duration": 0}
Thanks, @PupoSDC for PR. I will test this soon on iOS and update you.
On iOS build is failing. Here is a snippet of the log.
2021-04-17T12:34:09.3263030Z Compiling RNSoundPlayer.m
2021-04-17T12:34:09.3265290Z ❌ xxxxxx/node_modules/react-native-sound-player/ios/RNSoundPlayer.m:119:51: too few arguments to block call, expected 3, have 1
2021-04-17T12:34:09.3266200Z
2021-04-17T12:34:09.3266770Z reject("Media player is not instantiated!");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2021-04-17T12:34:09.3269880Z Compiling RNSoundPlayer-dummy.m
2021-04-17T12:34:09.3271400Z Building librar libreact-native-music-control.a
2021-04-17T12:34:09.3272780Z Compiling RNSoundPlayer.m
2021-04-17T12:34:09.3274600Z ▸Building library libreact-native-music-control.a
2021-04-17T12:34:09.3276060Z ▸Compiling RNSoundPlayer-dummy.m
2021-04-17T12:34:09.3277410Z ▸Compiling RNCMaskedViewManager.m
@johnsonsu we just bumped to the newest version and we are getting a very suspicious error:

Could it be because of these changes?
@PupoSDC I have opened a new issue. Sorry I investigated the issue yesterday and didn't saw that you posted that in the meantime. The issue and the proposed fix is here https://github.com/johnsonsu/react-native-sound-player/issues/125. Hopefully someone can check my fix and implement that if it makes sense.