iPhone SdK:添加音轨后 AVPlayer 将无法播放作品
将音轨(使用 AVAudioRecorder 录制)添加到合成后,AVPlayer 将无法播放它。 AVPlayer.status = 1 且 AVPlayer.error = null。
我看过 WWDC10 AVEdit 演示代码,它非常相似。会不会是音频格式不兼容?
原始作品已包含视频资产中的视频和音频轨道。
删除新添加的音轨后,播放器仍然无法播放 删除原始音轨后,播放器将播放。
我还发现很难获得可以指出问题的调试信息。如果有人有建议,我们将不胜感激。
这是我添加音轨的代码,
非常欢迎任何帮助
Jean-Pierre
-(void)editAudioViewController:(EditAudioViewController *)editAudioViewController didEditAudio:(NSURL *)url
{
[self dismissModalViewControllerAnimated:TRUE];
BOOL result;
NSError * error = nil;
if (url)
{
AVURLAsset * asset = [AVURLAsset URLAssetWithURL:url options:nil] ;
CMTimeRange audioTimeRange = CMTimeRangeMake(kCMTimeZero , asset.duration);
if (CMTIME_COMPARE_INLINE(CMTimeRangeGetEnd(audioTimeRange), >, [composition duration]))
audioTimeRange.duration = CMTimeSubtract([composition duration], audioTimeRange.start);
AVMutableCompositionTrack *compositionAudioTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio
preferredTrackID:kCMPersistentTrackID_Invalid];
AVAssetTrack *audioTrack = [asset compatibleTrackForCompositionTrack:compositionAudioTrack];
result = [compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, audioTimeRange.duration) ofTrack:audioTrack atTime:audioTimeRange.start error:&error];
if (!result)
{
NSLog(@"%@", [error description]);
}
[mp replaceCurrentItemWithPlayerItem:[AVPlayerItem playerItemWithAsset:composition]];
[mp seekToTime:kCMTimeZero];
}
}
After adding an audio track (recorded with AVAudioRecorder) to a composition AVPlayer will not play it. AVPlayer.status = 1 and AVPlayer.error = null.
I have looked at the WWDC10 AVEdit demo code and it's pretty much similar. Could it be an audio format incompatibility?
the original composition allready contains a video and audio track from a video asset.
after removing the newly added audio track the player still does not play
after removing the original audio track the player will play.
I'm also finding it hard to get debug information that would point me to the problem. If anyone has a suggestion it would be greatly appreciated.
Here is my code for adding the audio track
any help is most welcome
Jean-Pierre
-(void)editAudioViewController:(EditAudioViewController *)editAudioViewController didEditAudio:(NSURL *)url
{
[self dismissModalViewControllerAnimated:TRUE];
BOOL result;
NSError * error = nil;
if (url)
{
AVURLAsset * asset = [AVURLAsset URLAssetWithURL:url options:nil] ;
CMTimeRange audioTimeRange = CMTimeRangeMake(kCMTimeZero , asset.duration);
if (CMTIME_COMPARE_INLINE(CMTimeRangeGetEnd(audioTimeRange), >, [composition duration]))
audioTimeRange.duration = CMTimeSubtract([composition duration], audioTimeRange.start);
AVMutableCompositionTrack *compositionAudioTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio
preferredTrackID:kCMPersistentTrackID_Invalid];
AVAssetTrack *audioTrack = [asset compatibleTrackForCompositionTrack:compositionAudioTrack];
result = [compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, audioTimeRange.duration) ofTrack:audioTrack atTime:audioTimeRange.start error:&error];
if (!result)
{
NSLog(@"%@", [error description]);
}
[mp replaceCurrentItemWithPlayerItem:[AVPlayerItem playerItemWithAsset:composition]];
[mp seekToTime:kCMTimeZero];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的录音机代码中有两个单独的会话,一个用于录音,一个用于播放。
我切换到单个录制/播放会话,这以某种方式解决了问题:
I had two separate sessions in my audio recorder code one for recording and one for playback.
I switched to a single record/play session and this somehow fixed the problem: