【发布时间】:2011-12-09 23:54:26
【问题描述】:
我正在使用 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];
- 注意事项:
- productid 我假设是 com.company.application.product
- 文件名我假设是解压后的文件名(上传到UA的文件名) - 其余部分似乎建立了文件的位置,但我收到“找不到属性'文件路径'”错误。我应该在哪里定义“文件路径”?
- 本来想用play方法来玩的:
player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:fullPathToMyFile error:nil]];
[player play];
【问题讨论】:
标签: iphone in-app-purchase urbanairship.com audio-player