2014-01-18 37 views
0

我在我的應用中使用AVAsset並遇到了下一個問題。 當我寫這樣的東西:來自應用沙盒的AVAsset

AVAsset *audioAsset = [AVAsset assetWithURL:[NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/Hello.mp3", [[NSBundle mainBundle] resourcePath]]]]; 

它的工作很好。但是,當我試圖從應用程序的沙箱一樣,從我的tmp目錄新鮮的記錄文件:

AVAsset *audioAsset2 = [AVAsset assetWithURL:[NSURL URLWithString:[NSTemporaryDirectory() stringByAppendingPathComponent:[@"speechRecord" stringByAppendingPathExtension:@"m4a"]]]]; 

它不工作過。即使我嘗試將視頻文件添加到沙箱中的資產 - 結果也是一樣的。 我甚至嘗試過使用AVURLAsset,但資產總是空着。我需要它將兩個音頻文件混合在一起,然後將它與錄製的視頻合併。如果我可以在沒有AVAsset的情況下做到這一點,並且有另一種方法,如果您告訴我,我會很感激。或者可能有另外一個功能呢?

回答

2

使用URLWithString選擇器創建audioAsset2的第二個URL。您的第一個資產正確加載,因爲您使用了fileURLWithPath選擇器。

如果要在給定的URL上加載文件,請始終使用fileURLWithPath選擇器創建NSURL對象。

所以,簡單地嘗試:

AVAsset *audioAsset2 = [AVAsset assetWithURL:[NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:[@"speechRecord" stringByAppendingPathExtension:@"m4a"]]]];