我正在使用Urban Airship来管理应用内购买的非易耗音频文件。 UA将文件存储在库目录中,我想在用户按下按钮时简单地播放特定文件。我一直在玩下面推荐的代码,但似乎无法弄明白。任何人都可以从目录中提供有关如何播放和音频文件的更多详细信息吗?
NSString *productId = @"YOUR PRODUCT ID";
NSString *filename = @"YOUR FILE NAME";
NSString* libraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
// build the fill paths by appending ua and downloads to the base libraryPath
libraryPath = [libraryPath stringByAppendingPathComponent:@"ua"];
libraryPath = [libraryPath stringByAppendingPathComponent:@"downloads"];
// Append the product id:
NSString *downloadDirectory = [libraryPath stringByAppendingPathComponent:productId];
// now append your filename
NSString *fullPathToMyFile = self.filePath = [downloadDirectory stringByAppendingPathComponent:filename];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:fullPathToMyFile error:nil]];
[player play];
答案 0 :(得分:0)
检查文件的路径,即使它存在
你可以看到所有文件在执行NSLog时都通过了。
NSLog(@"fullPathToMyFile = %@",fullPathToMyFile);
如果您使用模拟器,则可以在找到文件时转到文件夹。