IOS 4.0的新功能列表显示,AV基金会框架已经实现了媒体资产管理、跟踪管理、媒体编辑和媒体项目元数据管理。这是什么意思?
使用跟踪管理和媒体资产管理的
我试图在这方面得到一些帮助/文件,却找不到任何东西..
谢谢,
托尼
发布于 2010-11-24 16:32:55
是的,你可以做你提到的大部分事情。我认为访问你手机的媒体文件并不是那么简单。但是你可以从网络中读取数据,如果你愿意的话,你可以把它导出到你的相机上。
首先,您必须导入您的视频或音频文件。
您需要开始的是您自己的视频播放器,您在您自己的观点创建。如果你不喜欢播放你的视频,而只是简单地写你的东西,你可以简单地去没有一个视图。
这很简单: 1.创建一个可变的组合:
AVMutableComposition *composition = [AVMutableComposition composition];
这会保存你的视频。现在你有了一个空的组合--资产。从您的目录或web添加一些文件:
NSURL* sourceMovieURL = [NSURL fileURLWithPath:moviePath];
AVURLAsset* sourceAsset = [AVURLAsset URLAssetWithURL:sourceMovieURL options:nil];
然后将你的视频添加到你的作文中
// calculate time
CMTimeRange editRange = CMTimeRangeMake(CMTimeMake(0, 600), CMTimeMake(sourceAsset.duration.value, sourceAsset.duration.timescale));
// and add into your composition
BOOL result = [composition insertTimeRange:editRange ofAsset:sourceAsset atTime:composition.duration error:&editError];
如果您想要添加更多的视频到您的作文,您可以添加另一个资产,并再次设置到您的作文使用您的时间范围。现在您可以使用如下代码导出您的新组合:
NSError *exportError = nil;
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetHighestQuality];
NSURL *exportURL = [NSURL fileURLWithPath:exportVideoPath];
exportSession.outputURL = exportURL;
exportSession.outputFileType = @"com.apple.quicktime-movie";
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch (exportSession.status) {
case AVAssetExportSessionStatusFailed:{
NSLog (@"FAIL");
[self performSelectorOnMainThread:@selector (doPostExportFailed:)
withObject:nil
waitUntilDone:NO];
break;
}
case AVAssetExportSessionStatusCompleted: {
NSLog (@"SUCCESS");
[self performSelectorOnMainThread:@selector (doPostExportSuccess:)
withObject:nil
waitUntilDone:NO];
break;
}
};
}];
如果您想播放视频,请使用这样的代码(我想,您可以访问您的视图):
// create an AVPlayer with your composition
AVPlayer* mp = [AVPlayer playerWithPlayerItem:[AVPlayerItem playerItemWithAsset:composition]];
// Add the player to your UserInterface
// Create a PlayerLayer:
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:mp];
// integrate it to your view. Here you can customize your player (Fullscreen, or a small preview)
[[self view].layer insertSublayer:playerLayer atIndex:0];
playerLayer.frame = [self view].layer.bounds;
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
最后播放你的视频:
[mp play];
输出到相机卷:
NSString* exportVideoPath = >>your local path to your exported file<<
UISaveVideoAtPathToSavedPhotosAlbum (exportVideoPath, self, @selector(video:didFinishSavingWithError: contextInfo:), nil);
如果完成通知(回调方法),则获取通知。
- (void) video: (NSString *) videoPath didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo {
// Error is nil, if succeeded
NSLog(@"Finished saving video with error: %@", error);
// do postprocessing here, i.e. notifications or UI stuff
}
不幸的是,我没有找到任何“合法”的解决方案,从摄影师阅读。
一开始的一个很好的来源是:
http://www.subfurther.com/blog/?cat=51
请下载VTM_Player.zip、VTM_AVRecPlay.zip或VTM_AVEditor.zip,以便对此进行很好的介绍。
https://stackoverflow.com/questions/3298290
复制相似问题