我試圖設計音頻流應用程序一切正常,但我不知道如何下載音頻文件到設備並閱讀後記。如何從xcode中的目錄文件播放音頻?
- Download audio to document directory.
- play it back from document directory.
添加代碼:
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [path firstObject];
NSString *filePath = [documentDirectory stringByAppendingPathComponent:@"evet.mp3"];
// UIImage *cellImage = [[UIImage alloc] initWithContentsOfFile:filePath];
NSLog(@"%@",filePath);
NSError *error;
NSData *_objectData = [NSData dataWithContentsOfURL:[NSURL URLWithString:filePath]];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:_objectData error:&error];
[audioPlayer play];
你有什麼試過的?你卡在哪裏?你現在的問題看起來像一個代碼請求,這是皺眉,可能會讓你失望。 – rckoenes 2015-04-02 14:38:21
我可以將音頻下載到設備中,但我無法從目錄中回放 – Aree 2015-04-02 14:39:38
添加無法使用的代碼。 – zaph 2015-04-02 14:43:21