avaudiosession

Resuming execution of code after interruption while app is in background

*爱你&永不变心* 提交于 2019-12-06 05:31:06
问题 I have spent days researching on SO and other websites for the answer to this but without any luck. Essentially, the challenge I've set for myself is to create an alarm clock app for iOS that will sound no matter where the user may be (foreground or background). This I have already accomplished by using an AVAudioPlayer instance and starting to play an empty sound file when the user sets the alarm in order for the app to keep running in the background. When it is time for the alarm to go off

Cannot Control Volume of AVAudioPlayer via Hardware Buttons when AudioSessionActive is NO

巧了我就是萌 提交于 2019-12-06 00:45:40
I'm building a turn-by-turn navigation app that plays periodic, short clips of sound. Sound should play regardless of whether the screen is locked, should mix with other music playing, and should make other music duck when this audio plays. Apple discusses the turn-by-turn use case in detail in the "WWDC 2010 session 412 Audio Development for iPhone OS part 1" video at minute 29:20. The implementation works great, but there is one problem - when the app is running, pressing the hardware volume controls adjust the ringer volume, not the app volume. If you want to change the app volume, you must

How to play audio through built-in earpiece speaker

霸气de小男生 提交于 2019-12-05 23:52:27
I have seen some apps like WhatsApp has a feature to play audio clips only through earpiece(phone call speaker) when the user brings up the device near to ear. Otherwise its playing via normal built-in speaker. I am using MPMoviePlayer for playing audio clips. I did go through lots of similar questions and answers on the internet, and all the answers say to set the AudioSession Category to PlayAndRecord. Thats it. I did the same, but couldn't get the exact result that I want to get. // Audio Player self.audioSession = [AVAudioSession sharedInstance]; [audioSession setCategory

How to let my app audio to nicely interrupt iPhone audio while speaking

流过昼夜 提交于 2019-12-05 21:31:14
问题 My iOS 7 app vocalizes texts when necessary. What I'd like to do is enable the user to listen to his music or podcasts (or any other app using audio) while mine is running. The expected behavior is that others audio either mixe or duck when my app speaks, then the others audio resume his volume at the initial level right after. I have tried many ways to achieve this goal, but nothing is good enough, as I list the issues I face, after the code. My current implementation is based on creating a

How do I make AVCaptureSession and AVPlayer respect AVAudioSessionCategoryAmbient?

删除回忆录丶 提交于 2019-12-05 21:08:02
I'm making an app that records ( AVCaptureSession ) and plays ( AVPlayerLayer ) video. I'd like to be able to do this without pausing background audio from other apps and I'd like the playback to respect the mute switch. In the AppDelegate I have set AVAudioSessionCategoryAmbient , according to the docs this should: The category for an app in which sound playback is nonprimary—that is, your app can be used successfully with the sound turned off. This category is also appropriate for “play along” style apps, such as a virtual piano that a user plays while the Music app is playing. When you use

AVAudioSession never stopped

£可爱£侵袭症+ 提交于 2019-12-05 18:20:11
I'm trying to set my AVAudioSession to inactive to get back to normal state. My utterance function: class SSpeech : NSObject, AVSpeechSynthesizerDelegate { var group = DispatchGroup(); var queue = DispatchQueue(label: "co.xxxx.speech", attributes: []) class var sharedInstance: SSpeech { struct Static { static var instance: SSpeech? } if !(Static.instance != nil) { Static.instance = SSpeech() } return Static.instance! } required override init() { super.init(); self.speechsynt.delegate = self; } deinit { print("deinit SSpeech") } let audioSession = AVAudioSession.sharedInstance(); var speechsynt

AVAudioSession : microphone headphone as input and iphone speaker as output

末鹿安然 提交于 2019-12-05 17:52:43
With iOS10 there are more possibilities to manage AUdioSession, but i couldn't manage to keep the headphone microphone as input while audio is going out through the iphone speaker. The 'overrideOutputAudioPort' method below also override the input audio port as the iphone microphone let session = AVAudioSession.sharedInstance() do { try session.setCategory(AVAudioSessionCategoryPlayAndRecord) try! session.overrideOutputAudioPort(.speaker) } catch { } Is there any solution to keep the headphone as input? How I undeerstand this Apple documentation , this is not possible using AVAudioSession : If

app crashes after checking network reachability in iphone?

岁酱吖の 提交于 2019-12-05 13:56:56
i have a mpmovieplayercontroller to play online music and avaudiosession to play the same music at background, when the first time app launches without network access, normally i shows "no internet connection" , when i tried after connecting to internet and playing it shows the error *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'An AVPlayerItem cannot be associated with more than one instance of AVPlayer' my code is here static MPMoviePlayerController *player=nil; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self =

Resume background audio after AVAudioPlayer is paused

纵然是瞬间 提交于 2019-12-05 06:17:38
问题 I've developed an iPhone application that allows other apps to play audio in the background. To achieve this, I initialize my audio session like this: [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; At some point in my application I provide an audio player to play some files stored in CoreData with AVAudioPlayer. When the user hits the play button, the background audio should be paused. When the player has finished or is paused, the background audio

setPreferredHardwareSampleRate doesn't work

守給你的承諾、 提交于 2019-12-05 04:01:34
问题 I'm using the code that can be found here. I've tried to change sample rate using: [[AVAudioSession sharedInstance] setPreferredHardwareSampleRate:SAMPLE_RATE error:nil]; Inside the init function on SoundRecoder.m file. (SAMPLE_RATE is 16000.0) When I'm checking the file it seems that still the metadata says the sample rate is 44100, I've tried also to use (as suggested here): AudioSessionSetProperty ( kAudioSessionProperty_PreferredHardwareSampleRate ,sizeof(F64sampleRate) , &F64sampleRate )