Reputation: 133
Downloaded the Xcode 7 beta which allows users to test their apps on their own iOS devices. My app is supposed to stream music from a server.
On the simulator, my app works fine - it plays in the app, as well as when I quit the app.
On my device, the app does NOT play music when it enters the background. I already did the thing with changing the capabilities of the target and checking the "audio and airplay" boxes in Background Modes.
Code for the stream:
stream = MPMoviePlayerController(contentURL: NSURL(string: "http://45.33.72.76:8000/stream/6/")!)
stream.view.frame = CGRect(x: 0, y: 0, width: 0, height: 0)
stream.view.sizeToFit()
stream.movieSourceType = MPMovieSourceType.Streaming
self.view.addSubview(stream.view)
stream.fullscreen = true
stream.prepareToPlay()
stream.play()
stream.controlStyle = MPMovieControlStyle.Embedded
stream.allowsAirPlay = true
let session = AVAudioSession.sharedInstance()
do {
try session.setActive(true)
} catch {
print("ERROR")
}
Any ideas?
Upvotes: 2
Views: 473
Reputation: 535304
The problem is that there's a bug in the simulator: it does not simulate background modes correctly. You have not correctly configured your app for background production of sound, but the simulator fails to simulate this fact. Running on the device reveals the problem.
Upvotes: 3