我使用Urban Airship来管理非消耗性音频文件的应用内购买。UA将文件存储在Library Directory中,我想在用户按下按钮时简单地播放一个特定的文件。我一直在玩下面推荐的代码,但似乎不能弄清楚。谁能提供更多关于如何播放和音频文件从目录的细节?
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];
- 指出:
- productid我假设是com.company.application.product
- 文件名我假设是文件名一旦它被解压缩(文件上传到UA的名称)-其余的似乎建立了文件的位置,但我得到一个"属性'filepath'未找到"错误。我应该在哪里定义'filepath'?
- 我想只是玩它与一个播放方法:
player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:fullPathToMyFile error:nil]];
[player play];
检查文件的路径,即使它存在
你可以看到当它对它执行NSLog时,所有的文件都通过了。
NSLog(@"fullPathToMyFile = %@",fullPathToMyFile);
如果你使用的是模拟器,你可以直接到文件所在的文件夹