【问题标题】:How can I play audio file from NSLibraryDirectory from Urban Airship?如何从 Urban Airship 播放来自 NSLibraryDirectory 的音频文件?
【发布时间】: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


    【解决方案1】:

    检查文件的路径,即使它存在。
    当它对它执行 NSLog 时,您可以看到所有文件传递。

    NSLog(@"fullPathToMyFile = %@",fullPathToMyFile);
    

    如果您使用模拟器,您可以在找到文件后转到文件夹。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多