Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
535 views
in Technique[技术] by (71.8m points)

audio - OGG Vorbis in iPhone sdk

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??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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];   
    }
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...