I use PlayerKit in one app to stream video from Cloudinary.
Everything works fine until I use seek to move video forwards or backwards.
I pause the video, use seek to move it to time I wish. After that the video plays fine but audio only starts after 20-30 seconds and is out of sync.
I've tried waiting for it to buffer, and different options on AVPlayerItem, Asset and Player but to no avail. One thing I did notice is that audio is not buffered while video is paused, it starts buffering audio only when I play the video.
PlayerKit is just a wrapper for AVPlayer and uses AVPlayer methods and listeners to inform me of buffering time and playing state so it's not up to the pod.
I resolved it by switching from mp4 to m3u8.
m3u8 is a playlist information file so I was then able to stream from cloudinary instead.
Related
I have to do a Video streaming app (using a remote url) in swift. But there is no any exact video format. Sometimes it can be m3u8 sometimes mp4 etc.. but my video player should support for what ever the format comes from the back end.
Also when the app is in background, the audio should play and when the app comes foreground video should play without any time delay between the vide and the audio.
I want to know whether is it possible to achieve my objectives using AVPlayerViewController or else what is the best player that I can use to achieve my targets. Please help me.
Thanks
AVPlayerViewController supports m3u8 and mp4 both format. For playing video's audio you need some extra configuration. You can check from here...
How do I get my AVPlayer to play while app is in background?
Is it possible to play video using Avplayer in Background?
So according to me AVPlayerViewController is best option for your requirement.
I am using HTTP Live Streaming Protocol to stream video and audio on demand in my app. The video playlist (m3u8 file) has an audio only version which is playing when the connection is very poor. When the app goes in background I want to play the audio of the video. Is there a way to achieve this, like forcing the MPMoviePlayer to switch to audio only, and then when they open the app to switch to a video version.
What I'm doing currently is that, I have a remote URL containing a MP4 file. I download that into a file using NSData and NSFileManager (as I want to cache the file). Now I start to play the file using AVPlayer.
All this works. But the problem is,when the video is getting buffered after a few seconds, the playback cannot be resumed.
Note:
The state of the AVPlayer does not change to Pause.
The current time of the video continues to run even though the video has stalled.
Is there anyway I can pause the video before the buffer happens?
Thanks in advance.
Fixed it myself. Created a file and the downloaded data is written into the file only after say 1MB of it has been downloaded and the player is made to pause when say 90% of this data has been read. This way the player doesn't stall.In the background the file continues to be downloaded. This way the size of the file will continue to increase even if the player is playing/pausing the video.
I have a video with sounds, and I want to play other sounds on the background. So I want to stop the video music to keep playing just the other music. I have to code for all except to stop the music for the video. Is it possible to build?
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.