【问题标题】:Problem while playing sound using AVAudioPlayer?使用 AVAudioPlayer 播放声音时出现问题?
【发布时间】:2011-09-05 07:07:22
【问题描述】:

在我的应用程序中,我正在从库目录播放声音。

这里的声音以不同的命名约定存储在不同的文件夹中。

例如,

文件夹喜欢:TestTest 2

现在,当我尝试从Test 播放声音时,它会播放声音。

但是当我尝试从Test 2 播放声音时,它没有播放任何声音。

我正在使用以下代码播放声音:

recordFile : "/Users/taxsmart2/Library/Application Support/iPhone Simulator/4.3/Applications/E2F2C422-605A-4EC7-A40A-7429A966351C/Library/List13-Test/rec212:13:21.caf" // 播放声音

recordFile : "/Users/taxsmart2/Library/Application Support/iPhone Simulator/4.3/Applications/E2F2C422-605A-4EC7-A40A-7429A966351C/Library/List13-Test 2/rec212:13:21.caf" // 可以不播放声音

// May be because of space `Test 2`

AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:recordFile] error:nil];

[player prepareToPlay];

在按钮上单击我有以下代码:

[player play];

我该如何解决这个问题?

【问题讨论】:

    标签: iphone objective-c ios4 avaudioplayer


    【解决方案1】:

    使用[NSURL fileURLWithPath:recordFile] 而不是URLWithString:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-22
      • 1970-01-01
      相关资源
      最近更新 更多