NSDocument アーキテクチャを使用するアプリケーションで QTMovie に小さな編集を加えています (以下に示すようにトラックを追加するなど)。編集後、元のファイルに保存したい。ただし、「ファイルがビジーです」というエラーが表示され続けます。これは、ファイルの処理で行った見落とし、または NSDocument の使用方法の失敗によるものだと思います。どんなヒントも役に立ちます!関連するコード(の一部)は次のとおりです。
// 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 でムービーをリリースする必要がありますか? それを行う「適切な」方法は何ですか?覚えておいてほしいのは、私は必ずしもこのドキュメントを終了しているわけではなく、これを閉じているわけではないということです. この操作を終了したばかりで、ディスク上のファイルに変更を反映させたいと考えています。[movie updateMovieFile] を使用したいのですが、その呼び出しではムービーが平坦化されないようです。ファイルに外部参照を入れたくありません。