我正在使用 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 的文件名)-其余部分似乎为文件构建位置,但我收到“找不到属性'文件路径'”错误。我应该在哪里定义“文件路径”?
- 我在想只是用一种播放方法来播放它:
player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:fullPathToMyFile error:nil]];
[player play];