How to reduce iOS AVPlayer start delay

前端 未结 6 695
渐次进展
渐次进展 2020-12-22 15:06

Note, for the below question: All assets are local on the device -- no network streaming is taking place. The videos contain audio tracks.

I\'m working on an iOS a

相关标签:
6条回答
  • 2020-12-22 15:39

    You should try option #7 first, just to see if you can get that working. I suspect that it will not actually work for your needs since the seek time will likely not be fast enough to give you seamless switching between clips. If you try that and it fails, then I would advise that you do option 4/6 and take a look at my iOS library designed specifically for this purpose, just do a quick google search on AVAnimator to find out more. My library makes it possible to implement seamless loops and switching from one clip to another, it is very fast because video has to be decoded into a file before hand. In your case, all 10 video clips would get decoded into files before you begin, but then switching between them would be fast.

    0 讨论(0)
  • 2020-12-22 15:42

    Without having done anything like this in the past, based on your thoughts and experiences I would try a combination of 7 and 1: Preload one AVPlayer with the first couple of seconds of the 10 follow up videos. Then skipping will very likely be faster and more reliable due to less data. While you are playing the selected piece, you have enough time to prepare the AVPlayer for the rest of the selected follow up video in the background. When the beginning is finished, you switch to the prepared AVPlayer. So in total, you at any given time have a maximum of 2 AVPlayers loaded.

    Of course I don't know whether the switching can be done so smoothly that it does not disturb playback.

    (Would have added this as a comment if I could.)

    Best, Peter

    0 讨论(0)
  • 2020-12-22 15:45

    Here are several properties and methods provided by the AVAsset class that may help:

    - (void)_pu_setCachedDuration:(id)arg1;
    - (id)pu_cachedDuration; 
    - (struct
     { 
       long long x1; 
       int x2;
       unsigned int x3; 
       long long x4; 
    })pu_duration;
    - (void)pu_loadDurationWithCompletionHandler:(id /* block */)arg1;
    
    0 讨论(0)
  • 2020-12-22 15:50

    For iOS 10.x and greater to reduce AVPlayer start delay I set: avplayer.automaticallyWaitsToMinimizeStalling = false; and that seemed to fix it for me. This could have other consequences, but I haven't hit those yet.

    I got the idea for it from: https://stackoverflow.com/a/50598525/9620547

    0 讨论(0)
  • 2020-12-22 15:50

    The asset may not ready once you create it, it may does calculations like duration of movie, be sure to contain all metadata of the movie in the file.

    0 讨论(0)
  • 2020-12-22 15:53

    If I understood your issue correctly, it seems that you have one continuous video to which you need to load the audio track for on a moment's notice.

    If that is the case I suggest looking into BASS. BASS is an audio library much like AVPlayer that gives you (relatively) easy access to the low-level API's of the AudioUnits framework in iOS. What does the mean for you? It means that with a tiny bit of buffer manipulation (you may not even need it, depends on how tiny you want the delay) you can start playing music instantly.

    The limitations however extend to video, as I said, it is an audio library so any video manipulation will still have to be done with AVPlayer. However using-seekToTime:toleranfeBefore:toleranceAfter: you should be able to achieve fast seeking within the video as long as you preroll with all the necessary options.

    If you're syncing across multiple devices (which your application might suggest) just leave a comment and I'd be happy to edit my answer.

    PS: BASS may look daunting at first because of it's C-like format, but it's really really easy to use for what it is.

    0 讨论(0)
提交回复
热议问题