avaudiosession

iOS AVAudioSession interruption notification not working as expected

这一生的挚爱 提交于 2019-11-29 05:35:34
I want to know when my AVAudioRecorder is inaccessible (e.g when music starts playing). As audioRecorderEndInterruption will be deprecated with iOS 9 I am focusing on AVAudioSession 's interruption notification (but neither is working as expected). The issue is that the interruption notification is never called if the app was and remains in the foreground when the interruption occurs. E.g: The user starts and stops playing music without moving the application into the background. To detect any interruptions I am using: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector

AVAudioSessionDelegate called at endInterruption, but beginInterruption not called

耗尽温柔 提交于 2019-11-29 03:31:40
问题 I'm setting up an AVAudioSession when the app launches and setting the delegate to the appDelegate. Everything seems to be working (playback, etc) except that beginInterruption on the delegate is not being called when the phone receives a call. When the call ends endInterruption is being called though. The only thought I have is that the audio player code I'm using used to be based on AVAudioPlayer, but is now using AVPlayer. The callbacks for the AVAudioPlayer delegate for handling

AVAudioPlayer on Lock Screen

跟風遠走 提交于 2019-11-29 03:28:14
问题 I've implemented an audio player using AVAudioPlayer (not AVPlayer ). I'm able to handle the remote control events with the following method. It works quite alright so far, however I see two more subtypes for these events: UIEventSubtypeRemoteControlEndSeekingForward and UIEventSubtypeRemoteControlEndSeekingBackward . - (void)remoteControlReceivedWithEvent:(UIEvent *)event { //if it is a remote control event handle it correctly if (event.type == UIEventTypeRemoteControl) { if (event.subtype =

iOS 9 How to Detect Silent Mode?

廉价感情. 提交于 2019-11-29 02:02:17
As AudioSessionInitialize and AudioSessionGetProperty are deprecated, I am getting the wrong return values: CFStringRef state = nil; UInt32 propertySize = sizeof(CFStringRef); AudioSessionInitialize(NULL, NULL, NULL, NULL); OSStatus status = AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state); [[AVAudioSession sharedInstance] setActive:YES error:nil]; if (status == kAudioSessionNoError) { return CFStringGetLength(state) == 0; // YES = silent } return NO; From this code (I found it here ), I get the same incorrect result no matter what state is actually device on.

iOS8 AVAudioSession setActive error

余生颓废 提交于 2019-11-29 01:27:44
问题 I'm testing my app in XCode 6 and find an issue with AVAudioSession in iOS8. When I call [[AVAudioSession sharedInstance] setActive:NO error:nil]; I get the following error message: AVAudioSession.mm:623: -[AVAudioSession setActive:withOptions:error:]: Deactivating an audio session that has running I/O. All I/O should be stopped or paused prior to deactivating the audio session. In AVAudioSession.h, it says Note that this method will throw an exception in apps linked on or after iOS 8 if the

Audio Player play in background and should work based off of hardware mute switch

北战南征 提交于 2019-11-28 21:54:24
I want to play audio file in the foreground, background and it should work with mute switch i.e. if mute switch is on, then it should not play, if mute switch is off should play audio. **I'm developing an SIP call application. App should play sound/ringtone when user receives a call. It should play if app is in background/foreground, it should mute/unmute if hardware mute switch is ON/OFF. For this I used AVPlyaer with below code. AVAudioSession *session = [AVAudioSession sharedInstance]; [session setCategory:AVAudioSessionCategoryPlayback error:&error]; [session setActive:YES error:nil];

iOS - AVAudioPlayer doesn't continue to next song while in background

北城以北 提交于 2019-11-28 21:39:29
So I have an app that plays a bunch of songs while the user can flip through a comic book. I use AVAudioPlayer and I have it set up to play the songs in a set order. So when one song finishes, the next one will play. This works flawlessly when the app is open. The problem occurs when the app is in the background. I set up the app to play in the background, and that works fine. So when the user presses the home screen the music continues to play. The problem occurs when the song ends, it is suppose to play the next song like it does when the app is open. Instead nothing happens. According to

List available output audio target AVAudioSession

China☆狼群 提交于 2019-11-28 21:10:51
I need to list the audio outputs available to an iOS application. My question is similar to this one: How to list available audio output route on iOS i tried this code: NSError *setCategoryError = nil; BOOL success = [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &setCategoryError]; NSError *activationError = nil; [[AVAudioSession sharedInstance] setActive: YES error: &activationError]; … NSLog(@"session.currentRoute.outputs count %d", [[[[AVAudioSession sharedInstance] currentRoute] outputs ] count]); for (AVAudioSessionPortDescription *portDesc in [[

Change lock screen background audio controls text?

随声附和 提交于 2019-11-28 20:00:48
问题 I have an iOS app that streams background audio using AVAudioSession. It is working correctly, but I am curious, is there any way to change the text on the lock screen audio controls? Right now it simply displays the name of my app, but I would like to change it to the name of the track. Additionally, the multi-tasking bar has no text under the controls- is there a way to add the track name there, as the iPod app does? 回答1: iOS 5 now supports setting the track title as well as an album art

AVAudioSession setCategory Swift 4.2 iOS 12 - Play Sound on Silent

旧街凉风 提交于 2019-11-28 17:22:46
问题 To play sound even on Silent mode I use to use below method. But how it's not working. // Works on Swift 3 do { try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback) } catch { print(error) } How to get it work in 4.2 / iOS 12? In newer version we need to set mode and options. try AVAudioSession.sharedInstance().setCategory( <#T##category:AVAudioSession.Category##AVAudioSession.Category#>, mode: <#T##AVAudioSession.Mode#>, options: <#T##AVAudioSession.CategoryOptions#