#ios #objective-c #avplayer #avmutablecomposition
Вопрос:
Я разработал приложение для воспроизведения музыки iOS, используя Objective-C. Но иногда AVPlayer не издает случайных звуков с помощью AVMutableComposition.
здесь нет никаких звуков проблемного кода
MPMediaItem* mediaItem = [songObj mediaItem];
NSURL* assetUrl = [mediaItem valueForProperty:MPMediaItemPropertyAssetURL];
self.mediaAsset_A = [AVAsset assetWithURL:assetUrl];
AVMutableComposition* myMutableComposition = [AVMutableComposition composition];
NSError* error = nil;
[myMutableComposition insertTimeRange:CMTimeRangeMake(self.startPoint, self.reSampledDuration) ofAsset:self.mediaAsset_A atTime:kCMTimeZero error:amp;error];
if(error)
NSLog(@"Insertion error: %@", error);
AVComposition *composition = [myMutableComposition copy];
self.mediaAsset_A = (AVAsset*) composition;
[self.mediaAsset_A loadValuesAsynchronouslyForKeys:@[@"duration"] completionHandler:^{
AVPlayerItem* playerItem = [AVPlayerItem playerItemWithAsset:self.mediaAsset_A];
if (self.mediaPlayer_A)
[self.mediaPlayer_A replaceCurrentItemWithPlayerItem:playerItem];
else
self.mediaPlayer_A = [AVPlayer playerWithPlayerItem:playerItem];
}];
[self.mediaPlayer_A play];
если я не использую AVMutableComposition, и тогда AVPlayer работает хорошо.
MPMediaItem* mediaItem = [songObj mediaItem];
NSURL* assetUrl = [mediaItem valueForProperty:MPMediaItemPropertyAssetURL];
self.mediaAsset_A = [AVAsset assetWithURL:assetUrl];
[self.mediaAsset_A loadValuesAsynchronouslyForKeys:@[@"duration"] completionHandler:^{
AVPlayerItem* playerItem = [AVPlayerItem playerItemWithAsset:self.mediaAsset_A];
if (self.mediaPlayer_A)
[self.mediaPlayer_A replaceCurrentItemWithPlayerItem:playerItem];
else
self.mediaPlayer_A = [AVPlayer playerWithPlayerItem:playerItem];
}];
[self.mediaPlayer_A play];
Итак, я не уверен, почему AVPlayer не издает случайных звуков с помощью AVMutableComposition. Помогите мне найти решение.