iPhone sdk 中的 OGG Vorbis [英] OGG Vorbis in iPhone sdk

查看:22
本文介绍了iPhone sdk 中的 OGG Vorbis的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to know if it's possible to play Ogg Vorbis audio file with iPhone SDK or if exist a library or a framework that allow this.

我已经阅读了一些关于 OpenAL 的内容,但我没有找到任何教程...谁能帮帮我??

I've read something about OpenAL but I don't find any tutorial... Can anyone help me??

推荐答案

迟到总比不到好 ;)
我在这里找到了答案在我的项目中使用 cocos2d 播放 ogg 文件?.

PASoundMgr 是一个不同的声音引擎,它支持 ogg 文件回放.但是,它自 iOS 2.x 以来一直没有更新,并且有从那以后出现的许多问题都没有处理.

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.

为什么需要播放ogg文件?如果您将它们转换为 aac,您将能够使用硬件解码播放它们,这是更多从 CPU 使用率的角度来看是高效的.

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 所基于的所有文件->库.并去掉了不必要的代码.

They mentioned PASoundMgr. It worked for me. I just copied from cocos2d framework all files->libraries that SoundEngineTest was based on. And got rid of unnecessary code.

小心 iOS 5.* 模拟器,它们有一些问题带声音库.我的演示适用于 4.3 模拟器和设备.

Be careful with iOS 5.* simulators, they have some problems with sound library. My demo works on 4.3 simulator and on Device.

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

Here are steps that I made to create demo:

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

如您所见,SoundEngineTest 依赖于 libvorbis.a.这是一个由 external/Tremor 组的文件组成的库.它还取决于 OpenAl、AudioToolbox 框架.

As you can notice SoundEngineTest depends on libvorbis.a. It's a library that made of files from external/Tremor group. Also it depends on OpenAl, AudioToolbox frameworks.

我将 tremor 组中的所有文件复制到我的项目中.创建了vorbis"Cocoa Touch 静态库,没有 ARC.并将所有源文件和标题添加到 Build Phases 选项卡中的vorbis"目标.

I copied all files from tremor group to my project. Crearted "vorbis" Cocoa Touch Static Library, without ARC. And added all source files and header to the "vorbis" target in Build Phases tab.

在 OggPlayDemo 的构建阶段中,将库(libvorbis、OpenAl、AudioToolbox)添加到 Link Binary with Libraries 框中.

In the Build Phases of OggPlayDemo Added libraries (libvorbis, OpenAl, AudioToolbox) to the Link Binary with Libraries box.

向项目添加了 PA 类.并检查 OggPlayDemo 作为目标.为了避免 ARC 出现问题,我禁用了这 3 个 PA 文件的 ARC 编译.(请参阅禁用单个文件的 ARC)

Added PA classes to project. And checked OggPlayDemo as a target. To avoid problems with ARC, I disabled ARC compilation for this 3 PA files. (see disable ARC for single file)

删除了所有 cocos2d 引用.有一些与根据方向更正听众位置相关的代码......我评论了它.我不需要这个功能来播放音频.

Removed all cocos2d references. There were some code related to correcting position of listener depending on orientation... I commented it. I don't need this feature for just playing audio.

复制的音频文件.

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

And finally added this code to 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 sdk 中的 OGG Vorbis的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆