AVCaptionSession and AVAudioSession cause AVPlayer pause to play - ios

I found, if stop running AVCaptureSession, and change AVAudioSession category right after -AVPlayer:play function may cause player pause to play.
Code
Her are a video show this bug
It should switch between Capture and Player, one at once. But some time, stop capture will cause player stop play.
I found this code run as I expected in iOS 9.3, but in iOS 11.3 this bug always show.

Related

AVPlayer seekToTime methods stopped working on iOS 9

I have been working on a Video Player which is streaming a video asset using HLS. Once I started debugging it on iOS 9, I noticed that the scrub feature stopped working properly. However, it still works on iOS 8 devices.
Looking more into the problem I narrowed that the issue must be in the seekToTime method calls.
The scrub flow is the following:
when scrub starts, the video is paused using AVPlayer pause instance method
when the scrub ends seek the time using AVPlayer seekToTime: instance method
After that play the video using AVPlayer play instance method
I tried some other options for changing the current playhead such as seekToTime:completionHandler:, but still the same result.
On iOS 9 release notes (https://developer.apple.com/library/prerelease/ios/releasenotes/General/RN-iOSSDK-9.0/), I saw that they made some changes to the AVFoundation, so I wonder if there are any known issues related to this with the iOS 9 release?
I just came across this issue and thanks to your link, I found the solution.
This is from the release note:
In iOS 9, these operations interrupt only when AVPlayer object’s
playback rate is changed to a non-zero value through the rate property
or play method.
which means we have to set
player.rate = 1
before calling seekToTime
do not use player.pause before seekToTime
player.rate has nothing to do with that issue

Why does SKVideoNode automatically starts playing video on iOS9?

When initialising a SKVideoNode with a video URL in iOS9 the behaviour changed to automatically starting the video as soon as the node is added, i.s.o. after the play method is called in previous versions of iOS.
doing the following inside the SKScene init
SKVideoNode* videoNode = [SKVideoNode videoNodeWithVideoFileNamed:#"sample.m4v"];
[self addChild:videoNode];
is enough to see the video playing, while previous iOS versions (more logically) required to also call
[videoNode play];
before the video starts playing.
Is this an intended change? A possible workaround I see is always immediately calling pause after initialising a video but it's a bit weird this behaviour changed.
(it feels like a bug to be honest)
(I also found the iOS9 simulator to have issues with SKVideoNodes playing at all, you have to test this on a device)

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.

Continue playing audio from html5 player when in iOS background mode

We built our music-oriented app in html5 and javascript with Sencha touch. For distribution we wrapped it in xcode with UIwebView. Everything runs fine except one thing that does not work: audio playing in multitask mode.
I know the general idea: add the UIBackgroundModes in info.plist.
Done. Now we can play the audio even in background mode.
Until we reach the end of the song. To start the next song we have to bring the app to foreground again or we can hit the play or 'next song' button on the iPhone audio controller.
After some research I found a promising workaround at: " Entering background on iOS4 to play audio " where the workaround is to edit AVAudioSessionCategoryPlayback and work with the UIBackgroundTaskIdentifier.
The problem for me is (just like in any other fix I found so far) that those solutions always assume that the audio is played either with AVaudioPlayer or MPMusicPlayerController. But in my case I user neither, our audio is played by our html5 player wrapped in UIwebView.
Anyone has any advice on how to continue playing the audio in iOS multitask mode when the audio player is a html5/javascript player?
My app plays audio via an <audio> tag in html hosted in UIWebView, and it supports background playing.
As you suggest, you need to have the 'App plays audio' background mode defined in your plist.
Try adding this to your applicationDidFinishLaunching: handler:
NSError *setCategoryError = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &setCategoryError];
Thanks, guys, but I ended up simply keeping the app busy in a loop when in background mode. This was enough to bridge the time when connecting to the next song on the playlist.
The code I used is similar to this one:
iPhone - Backgrounding to poll for events
You could try this, adding a function on the onend event.

avaudioplayer interferes with mpmovieplayer on ipad

my app plays video and audio. however, i have a problem where once i play an audio file using avaudioplayer, the video refuses to play. when i play the video first, everything is fine. but if the audio is played first, any time i try to play the video it simply pops up the video player but will not play the actual video (you can use the scroller to go to any point in the video, but no playback will happen). this issue does not come up on the iphone, nor on the ipad simulator. clearly there is some resource conflict here, probably related to the audio, and i'd welcome some input on how to address it.
issue solved: i had to call the 'stop' rather than 'pause' method on the avaudioplayer before video playback. this undoes the play preparation and releases the audio resource that had apparently prevented the video from being played.

Resources