Starting audio in locked screen mode not working - swift

I am working on a timer App with alerts. When the screen is locked I would like to have my alerts/Text To Speech keeping to work. It works for some time between 30 to 60 sec and then alerts stops working but the timer is continuing to work as when I unlock the phone the timer progressed and works. I went through many posts and I didn't find a solution. It looks like new audio cannot be fired in lock down mode (some posts said new audio sounds cannot be triggered in lock down but continuity of audio is working). I finally found this post -> AVFoundation playing audio in background/on lock screen in Swift
so I added following lines in my code:
// to authorize background music in parallel
try? AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.ambient)
try? AVAudioSession.sharedInstance().setActive(true)
// to play audio in background, lock screen mode
try? AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback)
and in info.plist I have this entry:
The result is that short audio sounds are working (I trigger them every 30 sec) only if I lock the screen during an audio, if I do it between two sounds it stops. I spent many days on searching solutions but nothing works, can someone please help here?
Spending again some hours to search further on this topic and what I found: -> https://developer.apple.com/forums/thread/77937
seems really a problem for many people but I don't understand why we don't find any solution as I saw many apps with this feature working, if you see any good answer please tell me.

As no one had an answer I contacted Apple Developer Technical Support and the response was a bit surprising but there is no "clean way" to do it, here the answer I got:
"To continue playing audio from the background, continuously play audio in the background (mostly this will be silent, except for when you have a new “alert”)"
I tested it with a silent.wav file of 60 sec that I fire every 55 sec and it works!

Related

How to avoid suspension of iOS app on background transition?

I know that iOS normally suspends the app on going to background. And there are ways to continue execution mentioned here.
But I found an app Saavn, which continues to download even after going to background.
Although it's a music app, but for audio service to run on background an audio must be playing. And it continues downloading even if no audio is playing.
This also can't be done through beginBackgroundTaskWithExpirationHandler:, as it only allows completion of a single fixed-length task. But in this app it continues to download infinitely till the whole playlist is downloaded.
And I also don't think it would be UIBackgroundModes = fetch because it downloads very large playlists with hundreds of songs(which are definately not samll fetches).
So, is there any other way to continue background execution(without violating apple's policies), NOT mentioned in Apple's developer's reference?
Please refer this documentation, it explains different scenarios https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

RemoteIO and Recording AAC on iOS 6

Is anyone using RemoteIO for recording AAC audio on iOS 6? I've noticed that when I'm doing this, it kills the media server on interruption and my interruption callbacks are never called on iOS 6.0.
Also, because the media server goes down, it makes recovering a bit difficult.
Is anyone else seeing this or worked around it?
Problem solved. Use the software codec:
// specify codec
UInt32 codec = kAppleSoftwareAudioCodecManufacturer;
int codecSize = sizeof(codec);
status = ExtAudioFileSetProperty(recorderState.audioFile,
kExtAudioFileProperty_CodecManufacturer,
codecSize,
&codec);
Before I was using kAppleHardwareAudioCodecManufacturer... evidently the hardware codec can't handle interruptions. Hope others find this useful!
I am having a similar problem. I am trying to record AAC audio using remoteio, for pretty much all the same reasons you described here:
http://lists.apple.com/archives/coreaudio-api/2012/Oct/msg00135.html
My current problem isn't even with interuptions. If I dispose of my audio unit and set my audio session to inactive on being moved to the background, I still have the media server get killed when I try to reactivate my session when the app reloads.
My basic flow that is dying is this:
- set up an active audio session for recording
- setup an audio unit & and file in preparation for the user pressing the 'record' button
- user backgrounds the app, in order to tear down everything I dispose of my audio unit and deactivate my session, but I don't clean up my extaudiofile at this point
- I open voice memos, and then immediately close it
- reopen my app and hit record.
- when I try and set the session to active, mediaserverd dies. Switching to the software codec didn't fix it!
If you have learned any more about this craziness I would love to hear what you figured out.
Thanks.

record Audio on iOS, and auto save audio every minute

I want to record audio on iOS, and auto save audio every minute.
the main purpose is not losing the audio after 1 hour record on crash.
There is a lot of code to post here to show you how to record the audio, but there are many examples on GitHub. Here are a couple.
To autosave recordings, I would suggest adding a notification timer. Here is an example.
I hope this helps get you started.
Sounds like audio queues are your best friends are. Read through the doc, it is pretty lucid.

AVPlayer restart sync issue

Hi all
Im working with AVPlayer app to run on an iPad and just getting my head around it. Currently stuck with an issue that i cant seem to get the avplayer to restart a currently playing file safely. The video doesnt need to be finished for a call for the command to restart is called.
[player[currentPage] seekToTime:startTime toleranceBefore:startTime toleranceAfter:startTime];
[player[currentPage] play];
is what im using at the moment and it works majority of the time but sometimes the video seems to go out of sync with the sound . that is to say the sound restarts fine but the video seems to be paused and doesnt restart until the sound catches back up with it.
Anyone have experience with this or can point me in the right direction to research it myself. I have gone through the avplayer class files on the apple dev site and have been unlucky with searching for similar problems.
Thanks for any help
G
Check out my answer for this question:
iOS Multiple AVPlayer objects results in loss of audio/video sync

Pause/Resume Pandora from iPhone application

I'm writing an application that occasionally records the user's voice. During recording, I would like the application to pause whatever music happens to be playing (pandora, ipod, etc) and when recording is finished, I want it to resume that music for the user.
Using MPMusicPlayerController's pause/play methods works with the iPod music. In fact, 'pause' will pause Pandora without trouble also; however, 'play' resumes the iPod instead of Pandora.
Pointers to relevant documentation are appreciated.
I stopped researching, but I don't believe there is a way to do this.