Comments (6)
Your code looks correct. If playback is not resuming when the interruption ends, I'm guessing "options" is not equal to AVAudioSessionInterruptionOptionShouldResume.
from learning-av-foundation.
options always is AVAudioSessionInterruptionOptionShouldResume
from learning-av-foundation.
something wrong happen in playTime
from learning-av-foundation.
you can have a try to run
- (void)handleInterruption:(NSNotification *)notification {
NSDictionary *info = notification.userInfo;
AVAudioSessionInterruptionType type = [info[AVAudioSessionInterruptionTypeKey] unsignedIntegerValue];
if (type == AVAudioSessionInterruptionTypeBegan) {
//AVAudioSessionInterruptionTypeBegan
[self stop];
if ([self.delegate respondsToSelector:@selector(playbackStopped)]) {
[self.delegate playbackStopped];
}
} else {
//AVAudioSessionInterruptionTypeEnd
AVAudioSessionInterruptionOptions options = [info[AVAudioSessionInterruptionOptionKey] unsignedIntegerValue];
if (options == AVAudioSessionInterruptionOptionShouldResume) {
[self play];
if (self.delegate) {
[self.delegate playbackBegan];
}
}
NSLog(@"%lu",(unsigned long)options);
}
}
from learning-av-foundation.
It appears Apple must have changed some behavior (at least in iOS 10.3 beta, which is what I'm running). Previously, calling play on an AVAudioPlayer would always reactivate the audio session. That doesn't appear to be the case. The fix is it manually reactivate your audio session before calling play (e.g. [[AVAudioSession sharedInstance] setActive:YES error:nil];).
from learning-av-foundation.
Oh cool
I used this code [[AVAudioSession sharedInstance] setActive:YES error:&error];
it works
/**
音频被打断 通知事件
@param notification 音频信息
*/
- (void)handleInterruption:(NSNotification *)notification {
NSDictionary *info = notification.userInfo;
AVAudioSessionInterruptionType type = [info[AVAudioSessionInterruptionTypeKey] unsignedIntegerValue];
if (type == AVAudioSessionInterruptionTypeBegan) {
//AVAudioSessionInterruptionTypeBegan
[self stop];
if ([self.delegate respondsToSelector:@selector(playbackStopped)]) {
[self.delegate playbackStopped];
}
} else {
//AVAudioSessionInterruptionTypeEnd
AVAudioSessionInterruptionOptions options = [info[AVAudioSessionInterruptionOptionKey] unsignedIntegerValue];
if (options == AVAudioSessionInterruptionOptionShouldResume) {
NSError *error = nil;
[[AVAudioSession sharedInstance] setActive:YES error:&error];
[self play];
if (self.delegate) {
[self.delegate playbackBegan];
}
if (error) { NSLog(@"Active error:%@",error); }
}
NSLog(@"%lu",(unsigned long)options);
}
}
Very thanks , your book wrote very good and I've ever read like this
from learning-av-foundation.
Related Issues (14)
- Hi, is there a Swift 2/iOS9 vesion on the way? HOT 1
- Chapter 2 Code Error HOT 1
- I want to make time lapse video,but when reduce fps ,it seems done not work.
- chapter 4 为什么要 2.0 * duration.timescale 这是什么意思?
- AudioLooper_Starter info.plist already includes background modes
- chapter 11 freeze,can't play the AVMutableComposition! HOT 2
- chapter11 选区过渡模式不能播放
- KameraWriter_Final HOT 1
- KameraWriter_Final
- KameraWriter_Final
- KameraWriter A/V gets out of sync when switching cameras.
- how to switch camera recording session AVfoundation?
- ZoomKamera_Starter launches to black screen, Error: (null) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from learning-av-foundation.