2011-02-09 41 views
1

我在使用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],但那个电话似乎并没有使电影变平。我不想在我的文件中有任何外部引用。

回答

0

原来我只是没有正确使用NSDocument架构。当我将其更改为正确使用Save/SaveAs时,此问题就消失了。

0

我对QuickTime C API不太熟悉,所以我实在不能告诉你任何有关错误的地方。 绝对猜测:也许打电话给EndMediaEdits丢失?
尽管AddMovieSelection不需要这样做,但是您说“[...] 添加了一个轨道”。所以也许还有其他的事情,比如AddMediaSample或类似的东西?

这就是说,如果你不需要将低于10.5的任何和所有你需要做的是从另一个影片添加一些段,就可以实现,如果没有下降到了C API:

有一个看

我必须首先在我的NSDocument中发布电影吗?

你的意思是为了写它到磁盘?否:这甚至会导致崩溃。

release的作用是处理内存管理。它与文件的繁忙状态无关。

相关问题