播放 .caf 文件:在模拟器中工作正常,但在 iPhone 中不行

发布于 2024-08-04 03:27:11 字数 994 浏览 11 评论 0原文

我正在建造一个录音机。重新编码和播放在模拟器上运行良好。但在 iPhone 上它不起作用。 (我按照 iPhoneOSProgrammingGuide/AudioandVideoTechnologies)

    printf("%s(player)\n",[[self.soundFileURL absoluteString] UTF8String]);

    AVAudioPlayer *newPlayer =
    [[AVAudioPlayer alloc] initWithContentsOfURL: self.soundFileURL error: nil];

    if([self.soundFileURL isFileURL]){
        printf("isFileURL\n");
    }

    self.player = newPlayer;
    [newPlayer release];

    [player prepareToPlay];
    [player setDelegate: self];
    //recorderLabel.text=@"Playing..";
    [player play];
    printf("playing..\n");

调试器输出为 文件://localhost/var/mobile/Applications/9A607A45-974B-4E9F-9839-FD21B3BC9DD8/Documents/1251828741.caf(播放器) 是文件URL 玩..

I'm building a voice recorder. Recoding and playing works fine on simulator. But on iphone it doesn't work. (I followed the exact steps as mentioned in iPhoneOSProgrammingGuide/AudioandVideoTechnologies)

    printf("%s(player)\n",[[self.soundFileURL absoluteString] UTF8String]);

    AVAudioPlayer *newPlayer =
    [[AVAudioPlayer alloc] initWithContentsOfURL: self.soundFileURL error: nil];

    if([self.soundFileURL isFileURL]){
        printf("isFileURL\n");
    }

    self.player = newPlayer;
    [newPlayer release];

    [player prepareToPlay];
    [player setDelegate: self];
    //recorderLabel.text=@"Playing..";
    [player play];
    printf("playing..\n");

The debugger out put is
file://localhost/var/mobile/Applications/9A607A45-974B-4E9F-9839-FD21B3BC9DD8/Documents/1251828741.caf(player)
isFileURL
playing..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

扛起拖把扫天下 2024-08-11 03:27:11

iPhone OS 设备上没有与 iPhone OS 模拟器相同的可用音频编解码器。在我的项目中,我在播放以一种方式编码的 .caf 文件时遇到问题,但不是另一种方式……一些尝试和错误将在这里有所帮助(我最终使用了 16BLE PCM)。

我会尝试更改录制的音频文件的编码,以尝试找到设备支持的音频编解码器。

The iPhone OS on-device does not have the same audio codecs available to it that the iPhone OS in-simulator does. In my projects I have had problems playing back .caf files encoded one way but not another... a bit of trial and error will help here (I ended up using 16BLE PCM).

I would try altering the recorded audio file's encoding in an attempt to find an audio codec supported by the device.

漫漫岁月 2024-08-11 03:27:11

确保 iPhone 上的声音未关闭。

将以下内容添加到您的委托(自己):

- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)playedPlayer successfully:(BOOL)flag {
    NSLog(@"Done playing %@", flag ? @"with success" : @"with failure" );
}

- (void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError *)error {
    NSLog(@"Error while decoding: %@", [error localizedDescription] );
}

这可能会给您一些线索。

Make sure sound isn't turned off on the iPhone.

Add the following to your delegate (self):

- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)playedPlayer successfully:(BOOL)flag {
    NSLog(@"Done playing %@", flag ? @"with success" : @"with failure" );
}

- (void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError *)error {
    NSLog(@"Error while decoding: %@", [error localizedDescription] );
}

This might give you some clues.

如果没有 2024-08-11 03:27:11

iPhone 的 .caf 文件需要编码为单声道而不是立体声通道,然后它才适用于 iPhone。

.caf file for iPhone need to be encoded as a mono channel and not with a stereo channel then only it will work with iPhone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文