gpt4 book ai didi

iphone - iPhone sdk 中的 OGG Vorbis

转载 作者:行者123 更新时间:2023-12-03 18:54:15 29 4
gpt4 key购买 nike

我想知道是否可以使用 iPhone SDK 播放 Ogg Vorbis 音频文件,或者是否存在允许这样做的库或框架。

我读过一些有关 OpenAL 的内容,但没有找到任何教程...谁能帮我吗?

最佳答案

迟到总比不到好;)
我在这里找到了答案Use cocos2d for playing ogg file in my project? .

PASoundMgr is a different sound engine that had support for ogg file playback. However, it hasn't been updated since iOS 2.x and there are numerous issues that have cropped up since then that it doesn't handle.

Why do you need to play ogg files? If you convert them to aac you will be able to play them back using hardware decoding which is much more efficient from a cpu usage point of view.

他们提到了 PASoundMgr。这对我有用。我刚刚从 cocos2d 框架复制了 SoundEngineTest 所基于的所有文件->库。并删除了不必要的代码。

这是我的 demoProject这展示了如何在 ios 上玩 ogg。

小心 iOS 5.* 模拟器,他们有一些 problems与声音库。我的演示可以在 4.3 模拟器和设备上运行。

<小时/>

以下是我创建演示的步骤:

  1. 首先您需要 cocos2d-iphone 框架。我已经有了,但你可以在这里找到它 cocos-2d_download .

  2. 正如您所注意到的,SoundEngineTest 依赖于 libvorbis.a。它是一个由 external/Tremor 组的文件组成的库。它还依赖于 OpenAl、AudioToolbox 框架。

  3. 我将 tremor 组中的所有文件复制到我的项目中。创建了“vorbis”Cocoa Touch 静态库,没有 ARC。并将所有源文件和 header 添加到构建阶段选项卡中的“vorbis”目标。

  4. 在 OggPlayDemo 的构建阶段中,将库(libvorbis、OpenAl、AudioToolbox)添加到将二进制文件与库链接框中。

  5. 向项目添加了 PA 类。并检查 OggPlayDemo 作为目标。为了避免 ARC 出现问题,我禁用了这 3 个 PA 文件的 ARC 编译。 (参见disable ARC for single file)

  6. 删除了所有 cocos2d 引用。有一些与根据方向纠正监听器位置相关的代码......我评论了它。我不需要此功能来仅播放音频。

  7. 已复制音频文件。

  8. 最后将这段代码添加到 ViewController 中:

    - (void)viewDidLoad
    {
    [super viewDidLoad];
    //init
    [PASoundMgr sharedSoundManager];
    [[[PASoundMgr sharedSoundManager] listener] setPosition:CGPointMake(0, 0)];
    self.audioSource = [[PASoundMgr sharedSoundManager] addSound:@"trance-loop" withExtension:@"ogg" position:CGPointMake(0, 0) looped:YES];

    // lower music track volume and play it
    [self.audioSource setGain:0.5f];
    }
    - (IBAction)play:(id)sender {
    [self.audioSource playAtListenerPosition];
    }

关于iphone - iPhone sdk 中的 OGG Vorbis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4745618/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com