I am using AVPlayer
for music playback. My problem is that after an incoming call, the player won't resume. How do I handle this when an incoming call comes?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
- Attempt to present UIAlertController on View Contr
AVAudioSession will send a notification when an interruption starts and ends. See Handling Audio Interruptions
In some cases my
AVPlayer
don't resume play even if I callplay()
. Only reload player helps me to resolve the problem:I have to wait for 2 seconds to make it work.
The whole func:
Starting from iOS 6 you must handle
AVAudioSessionInterruptionNotification
andAVAudioSessionMediaServicesWereResetNotification
, before this you had to use delegate methods.First you should call the AVAudioSession singleton and configure it for your desired use.
For example:
Then you should implement two methods, for the notifications which the AVAudioSession would call:
First one is for any interruption which would be called because of an incoming call, alarm clock, etc.
The second one if the media server resets for any reason, you should handle this notification to reconfigure audio or do any housekeeping. By the way the notification dictionary won't contain any object.
Here is an example for handling the playback interruption:
Notice that you should resume playback when the optional value is
AVAudioSessionInterruptionOptionShouldResume
And for the other notification you should take care of the following:
Regards.