OGG Vorbis in iPhone sdk

2020-02-04 06:17发布

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.

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

标签: iphone audio ogg
2条回答
我想做一个坏孩纸
2楼-- · 2020-02-04 06:59

Cricket Audio will play ogg files, among others, and works on iOS/Android/WP8.

查看更多
Bombasti
3楼-- · 2020-02-04 07:12

Better late than never ;)
I have found the answer here 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.

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.

Here is my demoProject that shows how to play ogg on ios.

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. First you will need cocos2d-iphone framework. I've already had it, but you can find it here cocos-2d_download.

  2. 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.

  3. 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.

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

  5. 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)

  6. 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.

  7. Copied audio file.

  8. 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];   
    }
    
查看更多
登录 后发表回答