简体   繁体   中英

Is it possible to begin playback of large .aac files without downloading the entire file first?

I am trying to begin playback of large .aac files in an iOS app, or, alternatively, dramatically reduce the download time, so playback can begin earlier. This seems like it may be a peculiarity of .aac files specifically.

In web browsers like Safari and Chrome, the duration is incorrect and scrubbing doesn't work well (Chrome) or is limited to seeking incrementally from the beginning (Safari), but playback nevertheless begins quickly. My AVFoundation-based player in iOS does not appear to be able to do this out of the box. While I'd like the scrubbing functionality, simply being able to begin playback with high stability and without a significant delay (50 seconds or more) for larger .aac files would be an acceptable solution.

According to my understanding of the encoding of .aac files, playback can't begin until all individual packets have been downloaded. Seemingly, native AVPlayer functions preferredForwardBufferDuration and automaticallyWaitsToMinimizeStalling should allow me to configure playback in advance of a complete file download, but that doesn't seem to work for me either.

I checked an Apple forum thread here which is unresolved too:

https://forums.developer.apple.com/thread/63435

Has anyone solved this problem?

I used the following third-party framework and working well. I hope it will work for you :)

https://github.com/tumtumtum/StreamingKit

Well I resolved the slow loading time by setting the AVURLAssetPreferPreciseDurationAndTimingKey bool to false/NO for .aac files.

This is a precise fix specifically for slow load times of this file type in iOS apps, with the trade-off that seeking backwards and forwards in the file will not work until the entire download is complete. In Apple speak:

Note that such precision may require additional parsing of the resource in advance of operations that make use of any portion of it, depending on the specifics of its container format. Many container formats provide sufficient summary information for precise timing and do not require additional parsing to prepare for it; QuickTime movie files and MPEG-4 files are examples of such formats. Other formats do not provide sufficient summary information, and precise random access for them is possible only after a preliminary examination of a file's contents.

See the complete documentation here:

https://developer.apple.com/documentation/avfoundation/avurlassetpreferprecisedurationandtimingkey?language=objc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM