我在使用NSDocument体系结构的应用程序(如添加轨道,如下所示)中对QTMovie进行了少量编辑。编辑完成后,我想保存到原始文件。但是,我不断收到'文件忙'的错误。我认为这是由于我在处理这些文件时所做的一些疏忽,或者是我如何使用NSDocument而导致的。任何提示将有所帮助!这里是(一些)相关的代码:如何在使用QTKit编辑后正确保存QTMovie?
// 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);
}
我必须首先发布我的NSDocument中的电影吗?什么是“正确”的方式来做到这一点?请记住,我不一定完成了这个文件,我没有完成它。我刚刚完成了这个操作,我想让磁盘上的文件反映我的更改。我很乐意使用[电影updateMovieFile],但那个电话似乎并没有使电影变平。我不想在我的文件中有任何外部引用。