Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] .getInfo() --> Crash #121

Open
sayem314 opened this issue Apr 10, 2021 · 5 comments
Open

[BUG] .getInfo() --> Crash #121

sayem314 opened this issue Apr 10, 2021 · 5 comments

Comments

@sayem314
Copy link

sayem314 commented Apr 10, 2021

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

@PupoSDC
Copy link
Contributor

PupoSDC commented Apr 14, 2021

Hey @sayem314

Opened a PR that should address your issue:
#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}

@sayem314
Copy link
Author

Thanks, @PupoSDC for PR. I will test this soon on iOS and update you.

@sayem314
Copy link
Author

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

@PupoSDC
Copy link
Contributor

PupoSDC commented Jun 9, 2021

@johnsonsu we just bumped to the newest version and we are getting a very suspicious error:

image

Could it be because of these changes?

@agapiospanos
Copy link

@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 #125.
Hopefully someone can check my fix and implement that if it makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants