Misaligned Sound Playback using AVPlayer and AVMutableComposition

大兔子大兔子 提交于 2019-12-01 07:30:23

问题


I'm trying to create a song from multiple instrument samples using AVComposition.

When I play two sound assets at kCMTimeZero in an AVMutableComposition, I would expect them to play at the same time, but there is a very slight offset.

This only happens on the first playthrough, so it would seem to be some kind of loading delay, but no matter what I try it doesn't go away.

I've made sure to preload the sound asset tracks, preload the composition tracks, wait for the playerItem to be ready, and wait for the player to be ready to play. I've tried prerolling the player, play/pausing it, etc. There is always a slight offset between the tracks the first time they're played.

I've created a small sample project to demonstrate the effect here

The main code is here

Note that when you first load the application and hit play, the sounds are slightly offset. Subsequent repeats of the sounds (and replays of the same playerItem) do not have this issue.

Delaying the initial sounds slightly seems to resolve the issue, but this is not a very nice option.

Any idea if this can be fixed or if I'm missing something?

Thanks

来源:https://stackoverflow.com/questions/14114542/misaligned-sound-playback-using-avplayer-and-avmutablecomposition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!