I'm playing a video using AVPlayer in a modal. When I swipe down the view, video play continues like Youtube app and I can hear the sound. But the problem is when I bring the view back, player plays the part of video that was not displayed very quickly until it catches up to current cursor.
For example, if I hid the view at 1:00 and revives it at 1:30, player shows the part from 1:00 to 1:30 in very high rate. I want video to be just playing at 1:30 cursor smoothly.
When hiding the view, you need to pause() the player, i.e.
player.pause()
Now, when you need to unhide the view, call play() method on the player, i.e.
player.play()
Related
Play, next track, previous track buttons gets disabled when I start play a music track after AVPlayerViewController finished showing video.
Reproduction steps:
start music track on AVPlayer
pause music track on AVPlayer
start showing video on AVPlayerViewController with different AVPlayer
close AVPlayerViewController
start (unpause) music track on AVPlayer
show notification screen
And I see that button are disabled.
I want to have enabled buttons rather than disabled. What do I do wrong?
After video is finished you should update nowPlayingInfo in MPNowPlayingInfoCenter
So I have an app built with a player that plays a video, I have a [player pause] and [player play] in the didBecomeActive and willResignActive methods. Most of the time works fine, but when I open the app, and press the home button and repeat again that process, around the 8th time the video will not play even though I see the play method getting called.
Does anyone have any idea what might be going on?
The app can be in several states that are not foreground. Before playing, check to see if you still have a player, that it still has a player.currentItem, and if it's status is AVPlayerStatusReadyToPlay.
If any of those conditions are not met, then the player and the item must be reinitialized using the code that you used to create it in the first place.
This is a good candidate for a lazy initializer for your player property.
I'm playing live video with AVPlayer and AVPlayerItem. I'm observing AVPlayerItem's status, isPlaybackLikelyToKeepUp, and AVPlayerItemPlaybackStalled. I'm also observing AVPlayer's rate.
While I'm testing I found really weird thing happened.
While AVPlayer plays video normally(AVPlayerItem.status == readyToPlay and AVPlayerItem.isPlaybackLikelyToKeepUp == true), if I press home button, the AVPlayer.rate becomes 0.0. It means player stopped playing.
When app got back to foreground and I press play button, it is still AVPlayerItem.status == readyToPlay and AVPlayerItem.isPlaybackLikelyToKeepUp == true but paused and after a while it starts to play.
What I want is to know the player is paused or playing. In this case, even player is not playing video, the status indicates it is playing. (AVPlayerItem.status == readyToPlay, AVPlayerItem.isPlaybackLikelyToKeepUp == true, AVPlayer.rate == 1.0)
I checked AVPlayerItem's loadedTimeRanges and item.loadedTimeRanges.first is not nil(loadedTimeRanges has only one item) and its start and duration are not 0.
What should I check?
I'm adding little more.
This symptom only happens with streaming(m3u8) not with vod(mp4).
So I guess it is a problem of buffered data. While player is playing, buffer has data to play and the data is still valid. After app goes background and back to foreground, player's buffer still has data so isPlaybackLikelyToKeepUp == true, AVPlayerItem.status == readyToPlay. However when I try to play, AVPlayer flushes buffer because it is old.
It looks like the only way so far is create new AVPlayerItem and set when app is back to foreground.
What is the exact problem I'm encountering and want to know how to avoid it.
This is the repo I'm working on.
https://github.com/trick14/SLPlayer
The upper one is live and bottom one is VOD. After loading is done, play and go background and foreground couple times. And if you try to play, all status looks normal but player is stalled.
I have a similar experience long time ago.
At that time, I've stored the status of playing and the playback location when user press home button.
When return to the foreground, I used the stored information to restore or play the location.
I hope you were helpful.
I have one view control that consists of MP Movie Player control. This control loads video from url. It loads the video perfectly. When I move to the previous control which has TableView, the audio of the video is played in background prefectly. The control which has a TableView consists of 'Now Playing' button. On pressing of 'Now Playing' the user is moved back to MP Movie Player control. But the problem persist here is that the video is loaded again where it was instead of continuous playing.
You need to get the current position of the movie from the property currentPlaybackTime while on your TableView. Then when you move to the MP Movie Player control, you need to specify the currentPlaybackTime you had used in the TableView.
I am trying to play a HLS stream using AVPlayer. The player plays the stream fine, however, after navigating away from the player view, it does not seem to stop downloading data for the HLS stream. I see a network data spinner on the status bar for a few minutes after navigating away from the AVPlayer view.
I have tried cancelPendingSeeks, cancelLoading, and tried removing the AVPlayerLayer from its superlayer using removeFromSuperLayer, however, none of these seems to solve the issue — there is still a spinner on the status bar.
This spinner is seen on actual device, but there is no spinner on the simulator. I am certain the video is being downloaded; I can see the data usage in network monitoring apps. How can I fix this?
Call pause on your AVPlayer object, then replace the item with a nil item, and set your video player to nil.
[anAVPlayerObject pause];
[anAVPlayerObject replaceCurrentItemWithPlayerItem:nil];
anAVPlayerObject = nil;