Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Better late than never ;)</strong><br/> I have found the answer here <a href="http://www.cocos2d-iphone.org/forum/topic/15680" rel="nofollow noreferrer">Use cocos2d for playing ogg file in my project?</a>.</p> <blockquote> <p>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.</p> <p>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.</p> </blockquote> <p>They mentioned PASoundMgr. It worked for me. I just copied from cocos2d framework all files->libraries that <em>SoundEngineTest</em> was based on. And got rid of unnecessary code.</p> <h2>Here is my <a href="https://code.google.com/p/play-ogg-vorbis-ios/" rel="nofollow noreferrer">demoProject</a> that shows how to play ogg on ios.</h2> <p>Be careful with iOS 5.* simulators, they have some <a href="https://stackoverflow.com/questions/7961840/what-does-this-gdb-output-mean">problems</a> with sound library. My demo works on 4.3 simulator and on Device.</p> <hr> <p>Here are steps that I made to create demo:</p> <ol> <li><p>First you will need cocos2d-iphone framework. I've already had it, but you can find it here <a href="http://www.cocos2d-iphone.org/download" rel="nofollow noreferrer">cocos-2d_download</a>.</p></li> <li><p>As you can notice <em>SoundEngineTest</em> depends on libvorbis.a. It's a library that made of files from <code>external/Tremor</code> group. Also it depends on OpenAl, AudioToolbox frameworks. </p></li> <li><p>I copied all files from <em>tremor</em> group to my project. Crearted "vorbis" <em>Cocoa Touch Static Library</em>, without ARC. And added all source files and header to the "vorbis" target in <em>Build Phases</em> tab.</p></li> <li><p>In the <em>Build Phases</em> of OggPlayDemo Added libraries (libvorbis, OpenAl, AudioToolbox) to the <em>Link Binary with Libraries</em> box.</p></li> <li><p>Added <em>PA</em> classes to project. And checked OggPlayDemo as a target. To avoid problems with ARC, I disabled ARC compilation for this 3 <em>PA</em> files. (see <a href="https://stackoverflow.com/questions/6646052/how-can-i-disable-arc-for-a-single-file-in-a-project">disable ARC for single file</a>)</p></li> <li><p>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.</p></li> <li><p>Copied audio file.</p></li> <li><p>And finally added this code to ViewController:</p> <pre><code>- (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]; } </code></pre></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload