Just_audio: IOS: No Sound

Created on 18 Apr 2020  ยท  26Comments  ยท  Source: ryanheise/just_audio

Describe the bug
I'm trying this in one of my application, works fine in IOS simulator but doesn't work on actual iPhone

 void initState() {
    super.initState();
    _player = AudioPlayer();
    _player.setUrl(
        "https://s3.amazonaws.com/scifri-episodes/scifri20181123-episode.mp3");
  }

and in button click  _player.play();

StreamBuilder works perfectly, but just no sound, I'm missing something here?

IMG_2348

3 testing bug

Most helpful comment

@ryanheise ๐ŸŽ‰
problem solved โœ…

thanks!

All 26 comments

To help me investigate the bug, I need you to fill in all sections of the bug template unless otherwise stated.

Some of my ios users faced with same issue:
audio playing (they see seek bar updates) but there are no sounds.

devices: iphone se, iphone 6plus.

library version 0.1.8

I am facing the same problem, I noticed that in my case the issue is the iOS silent mode. When the silent mode is active (activated through the hardware switch on iPhones), also the audio player is silent.

@chrisjue Thanks for the information, that sounds like a likely theory.

@chrisjue , @pro100svitlo , @pankajadhyapak , can you each tell me your use cases? Is your app just playing audio, are you using this in conjunction with other plugins that may for example record audio, play text to speech, or play in the background? It will be tricky to come up with a solution that works within a larger ecosystem of Flutter audio plugins that might make different assumptions about this and may interfere with each other, but I'll think on it.

In my case, its pretty simple: play audio file (with only just_audio) during screen is opened.
No other plugins are used.
Interesting that problem faced only by some users, not by all of them...

I just pinged a few of my users who face this issue.
This bug happens when device in silent mode as @chrisjue mentioned above.

@ryanheise any ideas how to fix that?

@pro100svitlo yes, I'm working on a solution now.

@ryanheise any ETA? ๐Ÿ™

just checked this library.
It works fine there, might be helpful to you ๐Ÿ˜‰

i have switched to audioplayers as of now, but really liked this library and covered all of my use cases.

ETA probably 1 hour.

@ryanheise waiting to check it ๐Ÿ˜‰

I've just added an extra method to configure the iOS audio session category. There are 6 categories to choose from:

enum IosCategory {
  ambient,
  soloAmbient,
  playback,
  record,
  playAndRecord,
  multiRoute,
}

If you have a media app, Apple recommends that you set it to playback. You can call this method during your app's initialisation:

AudioPlayer.setIosCategory(IosCategory.playback);

If you use other audio plugins that internally override this category, I would recommend contacting the author of that plugin and asking them to add a similar method to their plugins so that you are able to set a universal category across all of the different audio plugins that you use.

I don't know if the above fixes your issue, but please let me know how it goes!

@ryanheise how I can get that method?

This is currently available for testing in git master. You can temporarily update your pubspec as follows:

  just_audio:
    git:
      url: https://github.com/ryanheise/just_audio.git

@ryanheise ๐ŸŽ‰
problem solved โœ…

thanks!

Glad to hear :-)

I'll update the README and then publish.

Not sure, it might be related or no.

Why player stopped on ios when the screen is turned off?
It also happen within new fix.

Do you have any ideas?

I have written another plugin called audio_service which is designed to wrap around your existing audio code to allow it to run in the background as well as provide play/pause controls on the lock screen and control center. Normally, apps cannot play audio in the background, and so that plugin will help you to enable that feature.

@ryanheise thanks, will take a look.

I came from android world and there is a bit different meaning of the background: it still possible to play audio when the screen is off ๐Ÿ˜„

audio_service handles audio both when your app is in the background and also when the screen is off. But maybe if you're targeting only iOS and not Android, you might be able to implement a cheaper solution where you just implement the iOS configuration file changes mentioned in the audio_service README without actually using the audio_service plugin. But if you want to be able to control what appears on the lockscreen after turning the screen off, or what appears in the control center, (e.g. the "now playing" info and the play/pause button), you'd need to actually use the full audio_service plugin.

This is currently available for testing in git master. You can temporarily update your pubspec as follows:

  just_audio:
    git:
      url: https://github.com/ryanheise/just_audio.git

I wish i saw this on the readme. Ive been trying to get this working

@pankajadhyapak can you confirm that calling AudioPlayer.setIosCategory(IosCategory.playback); works for your scenario? If so, I'll close this issue.

@iansamz This change was released to pub.dev 10 days ago so you shouldn't need to test git master (also note as per my comments on #100 that not all "works on emulator not working on device" issues are the same, and so #74 and #100 are not the same. What's more important is the nature of what's not working. I think there are several issues currently open where it works on the simulator and not on a device but in each case, the thing that's not working is different. In your case, you haven't described what specifically is not working, but if none of the issues match your issue, I would advise you to open a new issue providing all details necessary to investigate).

AudioPlayer.setIosCategory(IosCategory.playback);solved the problem for me.
Thank you!

Works for me as well, thanks @ryanheise

Awesome, thanks for confirming. I'll close this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hesham91fci picture hesham91fci  ยท  12Comments

smkhalsa picture smkhalsa  ยท  6Comments

snaeji picture snaeji  ยท  10Comments

slimyTextBox picture slimyTextBox  ยท  3Comments

ryanheise picture ryanheise  ยท  6Comments