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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android : Cannot Play Mp3 on Real Device's #664

Closed
5 tasks
bobbyrinaldy opened this issue Apr 1, 2020 · 3 comments
Closed
5 tasks

Android : Cannot Play Mp3 on Real Device's #664

bobbyrinaldy opened this issue Apr 1, 2020 · 3 comments
Labels

Comments

@bobbyrinaldy
Copy link

bobbyrinaldy commented Apr 1, 2020

馃 Description

Hello, im trying to play mp3 from physical device (Real Device). the code working for IOS but on ANDROID it says 'Resource not found : error code -1'

馃 What have you tried?

the file path is like this :
/storage/emulated/0/Download/bf7befd8a3abf8aa0bad9d359214fd22.mp3

i have try to add file:// like this :
file:///storage/emulated/0/Download/bf7befd8a3abf8aa0bad9d359214fd22.mp3
and
file://storage/emulated/0/Download/bf7befd8a3abf8aa0bad9d359214fd22.mp3

also, i have try to add content:// like this :
content:///storage/emulated/0/Download/bf7befd8a3abf8aa0bad9d359214fd22.mp3
and
content://storage/emulated/0/Download/bf7befd8a3abf8aa0bad9d359214fd22.mp3

but nothing work above.

馃 Please post your code:

play = async path => {
    let dirs = RNFetchBlob.fs.dirs;
    var pathFile = Platform.select({
      ios: dirs.DocumentDir,
      android: dirs.DownloadDir,
    });
    if (this.sound) {
      this.sound.play(this.playComplete);
      this.setState({playState: 'playing'});
    } else {
     //
      const filepath = pathFile + '/' + path.filename;

      this.sound = new Sound(filepath, null, error => {
        if (error) {
          console.log('failed to load the sound', error);
          Alert.alert('Notice', 'audio file error. (Error code : 1)');
          this.setState({playState: 'paused'});
        } else {
          this.setState({
            playState: 'playing',
            duration: this.sound.getDuration(),
          });
          this.sound.play(this.playComplete);
        }
      });
    }
  };

馃挕 Possible solution

Is your issue with...

  • iOS
  • [*] Android
  • Windows

Are you using...

  • [*] React Native CLI (e.g. react-native run-android)
  • Expo
  • Other: (please specify)

Which versions are you using?

  • React Native Sound : 0.11.0
  • React Native: 0.61.5
  • iOS: -
  • Android: 10
  • Windows: -

Does the problem occur on...

  • Simulator
  • [*] Device

If your problem is happening on a device, which device?

  • Device: Xiaomi Mi9T
@luigbren
Copy link

luigbren commented Apr 2, 2020

Hi.. Same problem in Samsung S9+ Device.. sound.mp3 cannot play

@luigbren
Copy link

luigbren commented Apr 2, 2020

my friends.. my solution was put the code into mountcomponent..

constructor(props) {
    super(props);
    this.state = {
     };
    sound = null
  }

componentDidMount =() => {
    this.sound = new Sound('mysound.mp3', Sound.MAIN_BUNDLE, (error) => {
      if (error) {
        console.log('failed to load the sound', error);
        return;
      }
    });
}

and then turn on when you want....
this.sound.play();

Note: Android: Save your sound clip files under the directory android/app/src/main/res/raw. Note that files in this directory must be lowercase and underscored (e.g. my_file_name.mp3) and that subdirectories are not supported by Android.

@ArunKumarVallal99
Copy link

my friends.. my solution was put the code into mountcomponent..

constructor(props) {
    super(props);
    this.state = {
     };
    sound = null
  }

componentDidMount =() => {
    this.sound = new Sound('mysound.mp3', Sound.MAIN_BUNDLE, (error) => {
      if (error) {
        console.log('failed to load the sound', error);
        return;
      }
    });
}

and then turn on when you want.... this.sound.play();

Note: Android: Save your sound clip files under the directory android/app/src/main/res/raw. Note that files in this directory must be lowercase and underscored (e.g. my_file_name.mp3) and that subdirectories are not supported by Android.

What if We need to access the Download Directory? Fetch from Director and play? Could please provide any solution for this scenario?

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

No branches or pull requests

3 participants