question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not working on Android | number of channels is -1

See original GitHub issue

Sounds are working on iOS using the below code but not working on Android. I have notification.wav file in the android/app/src/main/res/raw directory. Help please.

const s = new Sound('notification.wav', Sound.MAIN_BUNDLE, (e) => {
      if (e) {
        console.log('error', e);
        return;
      }
      console.log('sound: duration in seconds: ' + s.getDuration() + 'number of channels: ' + s.getNumberOfChannels());
      s.play(() => s.release());
    });

On log I am getting this but no sound played. And the number of channels is -1

sound: duration in seconds: 0.542number of channels: -1

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:33 (7 by maintainers)

github_iconTop GitHub Comments

18reactions
DavitVoskcommented, Aug 17, 2017

solved… just put “music.play()” out of constructor error part, like this.

         // Load the sound file
         const music = new Sound('nargiz_vdvoyom.mp3', Sound.MAIN_BUNDLE, (error) => {
		if (error) {
			console.log('failed to load the sound', error);
			return;
		}
		// loaded successfully, play			
		music.play((success) => {
			if (success) {
				console.log('successfully finished playing');
			} else {
				console.log('playback failed due to audio decoding errors');
			}
		});
	});
2reactions
gvenkcommented, Sep 2, 2017

new Sound() uses android.media.MediaPlayer.prepareAsync(). So new Sound() returns immediately and it could have been not prepared completely. You could try to add a timeout, but it’s most save to start playing from the onError callback, I think. (and the name onError is a bit confusing)

This must be added to the documentation. I’ll submit a PR next week.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create and Manage Notification Channels - Android Developers
Starting in Android 8.0 (API level 26), all notifications must be assigned to a channel. For each channel, you can set the visual...
Read more >
android - Setup notification Channel, currently not working
1 Answer 1 ... You need to add setChannel(notificationChannel) in the notification Builder, like this: NotificationCompat.Builder builder = new ...
Read more >
Troubleshoot sign-in problems on mobile devices, smart TVs ...
Learn how to fix issues signing in to your YouTube channel on your mobile ... Account to your mobile device using the instructions...
Read more >
Working With Android Notification Channels - Dan Lew Codes
Google has introduced notification channels to Android Oreo. ... You want to hit that Goldilocks range - not too many channels, not too...
Read more >
Top 9 Ways to Fix Notifications Not Working on YouTube
If you aren't getting notifications only from a few channels, check those channels' notification settings. Step 1: Open the YouTube app and tap ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found