Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video starts playing after the whole file is downloaded #12

Closed
martinflorek opened this issue May 17, 2018 · 4 comments
Closed

Video starts playing after the whole file is downloaded #12

martinflorek opened this issue May 17, 2018 · 4 comments

Comments

@martinflorek
Copy link

I want to start video playback as soon as possible instead of waiting for the whole file to be downloaded first.

I set the AVPLayer's automaticallyWaitsToMinimizeStalling to false and AVPlayerItem's preferredForwardBufferDuration to different values ranging from 0.1 to 2.0 but the AVPLayer always waits for the full download. I also tried AVPLayer's playImmediately(atRate: 1.0) method instead of the plain play().

The KVO observed status in the CachingPlayerItem is changed to "ready" only after the data is fully downloaded.

How can I start video playback immediately after some data is downloaded instead of waiting for the full download?

@neekeetab
Copy link
Owner

I didn't try it with video files so I cannot comment on this. My suggestion is for you to try playing an mp3 file with the same setup. If the behavior doesn't change, chances are you missed something in your code. If everything is ok, then feel free to provide a link to the video file or the source code, I will take a look.

And make sure you're testing it on a device, not a simulator.

@martinflorek
Copy link
Author

@neekeetab thanks for the quick reply. I just tried it with mp3 audio and the playback starts almost instantly and starts before the full download. The status is "ready" after some kilobytes are downloaded and the audio starts playing. So this looks like a a video-only issue.

I tried this on a real device and both the mp3 and mp4 files are hosted on the same server with same permissions. Both HTTP and HTTPS connections behave the same.

I also tried the Big Buck Bunny video and its playback starts almost instantly and the download continues in the background. So it looks like encoding parameters issue. I will play with those now.

@martinflorek
Copy link
Author

Waiting for the whole video to download before starting the playback is caused by the moov atom being at the end of the file. After moving it to the start of the file (e.g. with FFmpeg) the playback start is fast.

@yazeedabalkhail
Copy link

For those wondering how to achieve what @martinflorek mentioned. Just change this flag of your exporter
exporter.optimizeForNetworkUse = true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants