Open ralph-bergmann opened 6 years ago
Wow, is it true? Because background playing is a critical for my application.
yes, the mediaplayer.prepare
method blocks the ui thread, if you have a hugh file the prepare methods needs a couple of seconds.
I managed to solve the issue with the background mode with this code and with the plist configuration UIBackgroundModes
do { try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, with: .mixWithOthers) try AVAudioSession.sharedInstance().setActive(true) } catch { print(error) }
@ficiverson I'm about to start a Flutter project and playing audio in the background is a core requirement. Can you please confirm that you were able to handle it with your workaround?
@omarrida For me its working on a radiostation app (only iOS version tested). Now I can listen to streaming music on background but I dont know if it works with local files because I dont have that requirement
The way to fix that is
AVAudioSession
category to playback mode, I proposed a fix waiting to be merged : pull request #43 UIBackgroundModes
in your .plist files.
The way to fix that is
- Set
AVAudioSession
category to playback mode, I proposed a fix waiting to be merged : pull request Audio output for speakers now supported on iOS #43- Add ausio in
UIBackgroundModes
in your.plist files.
I done: 1.AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback)
<array>
<string>audio</string>
It still can't play in the background.
The way to fix that is
- Set
AVAudioSession
category to playback mode, I proposed a fix waiting to be merged : pull request Audio output for speakers now supported on iOS #43- Add ausio in
UIBackgroundModes
in your.plist files.
ERROR: CANNOT PLAY MUSIC IN BACKGROUND. Message from code: "Error Domain=NSOSStatusErrorDomain Code=2003329396 "(null)""
The way to fix that is
- Set
AVAudioSession
category to playback mode, I proposed a fix waiting to be merged : pull request Audio output for speakers now supported on iOS #43- Add ausio in
UIBackgroundModes
in your.plist files.
I done: 1.AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback) 2. UIBackgroundModes audio
It still can't play in the background.
fixed it, it work well try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback, options: AVAudioSession.CategoryOptions.mixWithOthers) NSLog("Playback OK") try AVAudioSession.sharedInstance().setActive(true) NSLog("Session is Active") } catch { NSLog("ERROR: CANNOT PLAY MUSIC IN BACKGROUND. Message from code: \"(error)\"") }
I tried the example app on a real iPhone device. When I switch the phone off audio stops playing. When I switch it on again it continue playing.
Do you have any hints?
I added
audio
to theUIBackgroundModes
in theexample/ios/Runner/Info.plist
but it doesn't fixed the issue.