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
Related
I was using an AVPlayer to stream remote audio files. When an item ended, i would load up a new item into the AVPlayer and then start playing again. This worked well in both foreground and in the background in iOS 9.2 . With the release of iOS 9.3 this method no longer worked. I had to switch over to using an AVQueuePlayer in order to ensure that when a song ended the audio would continue to the next song.
My issue now is that there are scenarios in my app that require the AVQueuePlayer, or the AVPlayer to get a new URL and load it into the player then begin playing it, all while in the background. This was working fine in iOS 9.2 but now with 9.3 it just stopped working.
Does anybody know why this stopped working and how to fix it? Is it common for Apple to make a change like this and not mention anything about it?
Update: I have even tried a hack, where i begin playback of a second player, while the first one loads a new item from a new URL, so that audio never stops. This also didnt work.
By adding the line
UIApplication.sharedApplication().beginReceivingRemoteControlEvents()
to view did load...this solved the problem...
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)
I have an application that plays video using AVPlayer and AVPlayerLayer. In my app, I'm able to play audio when the app is locked by setting the player property of my AVPlayerLayer to nil when the application enters the background:
-(void)appEnteredBackgroundNotification:(NSNotification *)notification {
[[self playerLayer] setPlayer:nil];
}
However, when I do this, the audio will lag/blip for around 0.5 seconds. This sounds really really bad for the end user. Same goes for when the app enters foreground and I re-set the player property.
How can I avoid this audio blip? As a test I've tried removing the player in a background thread to no avail.
Update: I spoke with an Apple engineer at WWDC and they said that this issue is a bug on their end (so far not fixed in iOS 9) and this approach is the correct approach. Great...
I think may not you call pause before setting to nil and vice versa. And, try calling prepare before play.
I have an app that uses AVPlayer (or AVQueuePLayer) to play local files that were recorded by the App. All works great. But I also want this to work on iPhone when a call is in progress (the videos are event recordings). What I found is that during a phone call, the video feed to avplayerLayer goes blank, AVPlayer rate change to 0 (STOP), and all attempts to change rate to non-zero (PLAY) are ignored (rate stays at 0). There does not appear to be any documentation on this, and the only way to detect this condition in the player, is that player is STOPPED and will not start PLAYBACK. Of course, I also check for audio interruptions, and call center calls in progress.
Obviously, in this case the interruption is caused by a call, so there is always a inactive/resume or a intactive/background/foreground/resume transition. As well as audio route notification, audio interruption. So indirectly I know the condition is probably occurring.
So questions are:
(1) Is there any direct method (specific to AVPlayer,AVPlayerLayer) to be notified that AVPlayer is in this non-playing mode. I now use "avplayer.rate failed to change rate from 0 to non-zero", but this seems hacky (and too much "crossing the streams"!) I want to Notify user that video temporarily can not be played or previewed, so they do not think the App is broken. And also inform them or automatically continue Playback when iPhone call ends. (Without a looping process that keeps trying to start playback every 500ms!)
(2) Can AVPlayer play anything while a iPhone call (Green Bar) is in progress? or is this just the way apple designed the AVPlayer SDK? (If so there is no documentation on this) Obviously, other apps can play video during an iPhone call, but I suspect they are using a lower level SDK and not AVPlayer.
I have used MPMoviePlayerController in my application to play selected video. There is also facility to start video from different location like from 10 min, 20 min, 40 min etc.
Problem in iOS 7:
The problem is when video is played I am able to pause it but it does not resume after pausing. And also the pause button does not turn into play button. After clicking pause button none of the notification like "MPMoviePlayerPlaybackStateDidChangeNotification" get invoked. And same problem occurs when video is playing in fullscreen mode.
Problem in iOS 6:
Here only problem is that pause button does not turn into play button. Here video pause and resume works properly in fullscreenmode also.
one strange behaviour:
For one video when I play it from 40 min it just works perfectly. None of the above issues occur for it. But same video does not work when played from starting or 10,20 min durations.
I have searched a lot but I found only one post here related to this issue. But this solution is not working for me.
Does anybody know how to solve this?
Use AVPlayer as MPMoviePlayer is now deprecated.