AVCaptureSession startRunning is unmuting device - ios

My application has various sound effects for buttons and other actions, if the device is muted/silenced they don't make sounds as expected. However, one of the screens does video recording, and if that screen is navigated to it enables all of the sound effects everywhere in the app. By commenting out some things I determined that it was the startRunning function that does this - I'm not sure if this is just normal behavior because starting the camera enables related things, like audio, or if there's something weird going on that I can change.

If you're doing video recording you're most likely using the AVAudioSessionCategoryPlayAndRecord category. This category will always ignore the mute switch on the side of the device, by design. See here for definitions of all AVAudioSession categories. In short, there's no way to respect the mute switch when using this audio category. So maybe when you switch away from that screen, you should set the audio session category to something else like AVAudioSessionCategoryAmbient if that will not affect your app.

Related

MPMediaItem and AVPlayerItem playback sequence in background

I'm having an issue with playing sequences of different kinds of items in a background.
In an app I'm working on we've introduced playlists which contain both content provided by the app and Apple Music content.
For that use AVPlayer and MPMusicPlayerController respectively. We observe one player or the other (depending what content is now playing) and if the other kind of content comes next, we release the old player (if we can - MPMusicPlayerController is a singleton, so best we can do is stop it) and load item to another player.
The problem starts when the app leaves foreground. Once MPMusicPlayerController takes over it doesn't want to give up control, so if any AVPlayer content comes after MPMusicPlayerController content, the music stops.
One workaround that I've tried is playing with .mixWithOthers options when I set the category on AVAudioSession, however this creates new category of problems - I'm loosing lockscreen controls, therefore I'm also loosing airplay. One dirty trick that I've tried was setting .mixWithOthers 3 seconds before MPMediaItem ends, and then disabling it back once AVPlayer starts. Beside the fact that there're probably many different things that can go wrong here, MPMediaPlayerController still doesn't want to give me back the control over lockscreen controls.
Is there any way this could ever work on iOS 13?

AVAudioRecorder and AirPlay Mirrioring

When I have an AVAudioRecorder Session active - (when I'm recording audio) I can't activate AirPlay mirroring on the device. Airplay mirroring just deactivates while the app is running and switches it back on when the app exits. This post seems to suggest there is no way around this.
My thoughts are to try:
using a lower level recording framework
or outputting a separate window to external display, rather than mirroring (I've tried this, it doesn't work).
Is there another way around this, or do you know whether either of these methods are known to work?
Using AudioQueue to record (like Apple's Sample Code Speak Here) rather than the AVRecorder works. A bit more work to implement, but recording continues on or off Airplay mirroring.

AVComposition breaks on Airplay

I have a video composition which I'd like to play over Airplay (without mirroring). The app works as expected when using normal Airplay mirroring, but I'd like to get the speed, reliability, and resolution bump you get from using Airplay video instead.
The problem is that when I set
player.usesAirPlayVideoWhileAirPlayScreenIsActive = YES;
...the player goes blank.
Notes:
Since I don't create separate windows for each display, they are both trying to use the same AVPlayer.
My AVVideoComposition contains different files and adds opacity ramps between them.
This unanswered question suggests that the problem is more likely due to the fact that I'm playing an AVComposition than the use of a shared player: AVComposition doesn't play via Airplay Video
Two questions:
Do I have to get rid of the player on the iPad?
Can an AVVideoComposition ever be played over AirPlay?
I can't make comments so I had to post this as an answer although it might not fully respond to the questions.
I had similar issue and at the end I found out that when AVPlayer plays AVComposition it simply doesn't display anything on the external display. That's why I had to do it myself by listening to UIScreen connection notifications.
I have to say that all worked pretty perfect. I'm checking first if there are more than one screen and if there are I simply move the AVPlayer on that screen while displaying a simple message on the device's screen that content is played on... plus the name of AirPlay device. This way I can put whatever I want on the external display and is not very complicated. Same thing is when I receive UIScreenDidConnectNotification.
That was fine until I noticed that the composition plays really choppy on the the external display. Even if it consists of only one video without any complex edits or overlays. Same video plays perfectly if I save it to the Camera Roll or if I use MPMoviePlayerController.
I've tried many things like lowering resolutions, lowering renderScale and so on but with no success.
One thing bothers me more is how actually Apple do this in iMovie - if you have AirPlay enabled and you play a project (note it's still not rendered so it must use a composition in order to display it) right after tapping play button it opens a player that plays content really smoothly on the external monitor. If you however activate AirPlay from the player it closes and start rendering the project. After that it plays it I thing by using MPMoviePlayerController.
I'm still trying to find a solution and will post back if I have any success.
So for the two questions:
I don't see why you have to get rid.
Yes it can be played but with different technique and obviously issues.
in the app .plist create a new item called:
required background modes
add a new array element called:
App plays audio or streams audio/video using AirPlay
Not sure if you have already tried this, but you don't mention it in your post.
Cheers!

IOS 5 No audio when playing a video with Silent mode on with a buzztouch app

I have done several apps with buzztouch for Iphone and Ipads, here is a free one as an example :
http://itunes.apple.com/us/app/lr-basics-free-edition/id497563707?mt=8
I do not know code very much, I have very little basics that is why I designed my app using Buzztouch, which by the way is amazing !
The only one problem that I have is that the default behavior when you play a video (which was most of my apps are doing, playing tutorials) and if the silent mode is on either on Ipad or Iphone, there is no audio, even thought the volume slider is active, given the impressions to users that there is a bug, and I got some bad reviews due to that, I have also people writing me about it. I Then tell them all they have to do is to turn off the silent mode and they the audio is back, works everytime, but in the meantime I get complaits !
So here is my questions, is there a simple way I can located in the Buzztouch generated code a property that can easely be changed so that when a video is played, audio stays, despiste the silent mode being active.
I actually checked 4 or 5 other Iphones similar applications including the default youtube apple app, the default is that the audio plays even if the silent mode is turn on, giving my customer the impression that my app is bugged.
I'm not a programmer so please but as simple as possible in your answer.
Tku so much for the help.
Serge
What you are describing is the default behavior in iOS - when the ring/silent switch is in silent mode all audio from your app will be suppressed.
I don't know about implementing this from BuzzTouch, but here is a native solution I used to get around this for one of my apps that plays video:
MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL:myVidURL];
... set up player ...
// prevent mute switch from switching off audio from movie player
NSError *_error = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &_error];
[self presentMoviePlayerViewControllerAnimated:mpvc];
You will also need to include the AVFoundation framework for this to work.
Here's the link where I first found this tip:
http://www.24100.net/2011/05/ignore-ringtone-mute-switch-during-mpmovieplayer-video-playback-ios/
Right from documentation - iOS has 6 audio session categories out of that 3 affects the behavior of Slient switch:
AVAudioSessionCategoryAmbient or the equivalent kAudioSessionCategory_AmbientSound— Using this category, your audio is silenced by the Ring/Silent switch and when the screen locks. Used when we want our app audio with built-in app audio
AVAudioSessionCategorySoloAmbient or the equivalent kAudioSessionCategory_SoloAmbientSound—Use this category for an application whose audio you want silenced when the user switches the Ring/Silent switch to the “silent” position and when the screen locks. This is the default category
AVAudioSessionCategoryPlayback or the equivalent kAudioSessionCategory_MediaPlayback—Use this category for an application whose audio playback is of primary importance. Your audio plays even with the screen locked and with the Ring/Silent switch set to silent.
Hint: Upload the audio file to your buzztouch account files. This is the only way Buzztouch will recognize the audio. next, add the audio file to your xcode bttouch sound folder and add all references. You should be fine!

How to start playing a sound while iPod's screen is turned off?

I need to play a custom sound synthesized using AudioUnit on an iPod.
This sound shall be played after up to one hour of playing music from a playlist on the iPod (it is played using MPMusicPlayerController).
The issue is that everything works fine if the screen in on, however my custom sound doesn't play if the screen is off.
If the sound is already playing when the screen is turned off it keeps playing well. So I assume I am using the correct audio session category.
Could you give me any hint?
According to Apple's developer library:
AVAudioSessionCategoryPlayback or the equivalent
kAudioSessionCategory_MediaPlayback—Use this category for an
application whose audio playback is of primary importance. Your audio
plays even with the screen locked and with the Ring/Silent switch set
to silent.
(Also, check this table.)
It seems that setting the audio session category to AVAudioSessionCategoryPlayback or kAudioSessionCategory_MediaPlayback would automatically fix your problem.

Resources