6

I have an AVQueuePlayer that is supposed to play sequentially an array of AVURLAsset representing consecutive fragments of one continuous video.

Whenever a fragment ends and another starts, there is a small glitch that can be well noticed (frame hold for approx 0.2sec and sound gets muted)

I tried researching how to get around that issue but haven't found anything. I tried solving it by having 2 AVQueuePlayer's and switch between both around 0.2sec before the end of every fragment. Issue not solved.

Any idea on how to solve that?

Note: When joining the mp4 fragments together using an mp4 joiner software, the output is a single smooth video without any glitch.

blancos
  • 1,576
  • 2
  • 16
  • 38
Joe
  • 2,386
  • 1
  • 22
  • 33
  • does this answer help you? http://stackoverflow.com/questions/28659404/avfoundation-play-consecutive-video-fragments – digitalHound Aug 21 '15 at 18:03

2 Answers2

5

Been through this exactly. You will experience that glitch no matter what you do. Reason being how AVQueuePlayer works. It loads the next item when the previous ends. So if your videos are big, you may also see that blank screen for 2-3 seconds. One solution is what you mentioned, i.e. using two AVQueuePlayer. But as you said its not working for you, and even if you make it work, it will be clumsy.

A better and clean solution is AVMutableComposition. It may look complex at first but its fast and one time task. You create a composition of all of your videos and play it in a simple AVPlayer. And in your case, I assume you just have to play it, so you don't even have to export it.

To know how to use AVMutableComposition, go through this link. It will explain with exact code you need.

blancos
  • 1,576
  • 2
  • 16
  • 38
-1

As you said, "2 AVQueuePlayers" way still has problem(some sound glitch). I faced same problem and solved it by using HLS.

You can play local TS files.

At first, make m3u8 and TS files from original movie file.

e.g.

mediafilesegmenter -t 10 sample.mp4

Then, add resource files to iOS device. You can add files from iTunes, add as resource, or make download function and get from your app.

Run a http server, and then pass the local URL to AVPlayerController. I used cocoaHttpServer.

I put simple example here.

https://github.com/satoshi0212/samples/tree/master/TSPlaySample

satoshi
  • 1
  • 2