Misaligned Sound Playback using AVPlayer and AVMutableComposition
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?
- Xcode: Is there a way to change line spacing (UI Label) in interface builder?
- Display List of Episodes from List of Podcasts
- C-style array of pointers to Objective-C objects under ARC
- How do I apply proper perspective to this OpenGL ES texture?
- Return value from inside block (Objective-C)
- How to get UIViewController of a UIView's superView in iPhone SDK?
- A server with the specified hostname could not be found
- How to remove arm64 support from Xcode 6?
- Managing multiple asynchronous NSURLConnection connections
- Can Xcode Use “Folder References” for Code?
- Casting between different UnsafePointer<T> in swift
- Custom keyboard appears with ~5seconds delay
- In custom Prototype Cell in UITableView, UITextField value replaces with other Prototype Cell
- Password protect iPhone app
- Add UISearchBar to UINavigationBar with UIBarButtonItem