Cocoa 如何在使用QTKit编辑后正确保存QTMovie?
我正在使用NSDocument体系结构对应用程序中的QTMovie进行小编辑(例如添加曲目,如下所示)。编辑后,我想保存到原始文件。但是,我不断收到“文件正忙”错误。我认为这是由于我在处理文件时的一些疏忽,或者我在使用NSDocument时的失误。任何提示都会有帮助!以下是(部分)相关代码:Cocoa 如何在使用QTKit编辑后正确保存QTMovie?,cocoa,macos,quicktime,nsdocument,qtkit,Cocoa,Macos,Quicktime,Nsdocument,Qtkit,我正在使用NSDocument体系结构对应用程序中的QTMovie进行小编辑(例如添加曲目,如下所示)。编辑后,我想保存到原始文件。但是,我不断收到“文件正忙”错误。我认为这是由于我在处理文件时的一些疏忽,或者我在使用NSDocument时的失误。任何提示都会有帮助!以下是(部分)相关代码: // open file that has the track I want to add to my movie QTMovie* tempMovie = [QTMovie movieWithURL:ou
// open file that has the track I want to add to my movie
QTMovie* tempMovie = [QTMovie movieWithURL:outputFileURL error:nil];
// Use old API to add the track
AddMovieSelection([movie quickTimeMovie], [tempMovie quickTimeMovie]);
// get the filename from the NSDocument
NSString *filename = [[self fileURL] path];
NSLog(@"writing to filename: %@", filename);
// FLATTEN the movie file so I don't get external references
NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithCapacity:1];
[attributes setObject:[NSNumber numberWithBool:YES] forKey:QTMovieFlatten];
// attempt to write
NSError *error;
// this is where I get the "file is busy"
if (![movie writeToFile:filename withAttributes:attributes error:&error]) {
NSLog(@"Error: %@", [error localizedDescription]);
NSRunAlertPanel(@"Error", [error localizedDescription], nil, nil, nil);
}
我必须首先在我的文档中发布电影吗?这样做的“正确”方式是什么?请记住,我不一定完成此文档,我不会结束它。我刚刚完成此操作,希望磁盘上的文件反映我的更改。我很想使用[movie updateMovieFile],但这个调用似乎并没有使电影变得平坦。我不希望在我的文件中有任何外部引用。我对QuickTime C API不太熟悉,所以我不能告诉您那里出了什么问题绝对猜测:可能缺少对
EndMediaEdits
的调用?虽然
AddMovieSelection
不需要这样做,但您说“[…]例如添加一首曲目[…]”。所以可能还有其他的事情,比如AddMediaSample
或者类似的东西
也就是说,如果您不需要针对10.5以下的任何内容,只需添加另一部电影中的某些片段,就可以实现这一点,而无需使用C API:
看看
- 和 ,如果您希望将插入的段“覆盖”(暂时而言)
- 如果你想要
{movieA.firstPart,movieB,movieA.secondPart}
release
的作用是处理内存管理。这与文件的繁忙状态没有多大关系。结果表明,我只是没有正确使用NSDocument体系结构。当我将其更改为正确使用Save/SaveAs时,这个问题就消失了