IOS Multiple AVPlayer Objects Lost Audio / Video Sync

I am trying to use two different AVQueuePlayer in my application. The first player plays a series of short videos broadcast over the network. The second object plays only one video, but it is much longer. It is also broadcast. I checked that all clips have the correct audio / video synchronization.

I noticed that if I create one AVPlayer object after another one is created, the audio / video synchronization of the second player will be lost. Sound plays between 800 ms - 1500 ms too early.

I tried several things, including adding a delay between clearing the first player and distributing the second player, removing all calls to the AudioSession code, etc. None of this helps. Very often, the sound will be synchronized, but in fact it happens about 1 time in 30 times.

Has anyone else seen the same behavior? Does anyone know how to fix this?

Thanks to everyone who can help!

+4
source share
1 answer

I am also facing the same problem. I looked through some information in the AVPlayerLayer documentation:

During playback, AVPlayer can compensate for the temporal drift between its visual result and its audibility output to one or more audio outputs with independent device synchronization by adjusting the time of its associated player layers. The effects of these adjustments are usually very small; however, customers who wish to remain unchanged by such adjustments may wish layers for which time in the independent temporary subtrees of their layer trees is important.

You can create an arbitrary number of player layers with the same AVPlayer object. Only the most recently created player layer will actually display the video on the screen.

Unfortunately, I did not decrypt this in the actual code, but I decided that this could help you in the right direction. If you come up with a solution, please post it here and I will do the same.

+3
source

Source: https://habr.com/ru/post/1339805/


All Articles