OGG Vorbis in iPhone sdk - iphone

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

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:
First you will need cocos2d-iphone framework. I've already had it, but you can find it here cocos-2d_download.
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.
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.
In the Build Phases of OggPlayDemo Added libraries (libvorbis, OpenAl, AudioToolbox) to the Link Binary with Libraries box.
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)
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.
Copied audio file.
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];
}

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

Related

How to obtain m4v metadata using iOS SDK

Is there a way to access the metadata (such as width and height of the video) via iOS SDK for m4v inside the resource bundle? I would like to use this info to center the video around the screen bounds.
On a mac this would be easy, because you can utilise the spotlight metadata, but on iOS it's slightly more complicated. A couple of suggestions:
The easiest way to do this is just to load your movie into an MPMoviePlayerController and check the naturalSize property. There are a number of other properties including playableDuration. The downside to this is you have to load the movie into an MPMoviePlayerController, which may be fine for you if you're going to play the file straight away.
The harder but more efficient way is to use the open source libmediainfo library, but it's obviously more complex to integrate than using an MPMoviePlayerController 'out of the box'.

ffmpeg for extract a frame from iPhone video camera

I am trying to extract an image frame from a video taken from iPhone camera using ffmpeg. But it usually throws me a EXEC_BAD_ACCESS and the stacktrace is showing in another method calls that is never called (I know my code didn't call it)
I am using the ffmpeg built from the instruction of the iFrameExtractor website. If anybody do it successfully, please help me or if possible, send me some codes. I don't know why it crashes, although it works well on the simulator (which I manually import a video into the library). My guess is that ffmpeg cannot decode the iPhone video camera correctly.
I already tried to use all 3 sets of library files like arvm6, arvm7 and i386 but doesn't work. My iPhone is 3gs. My iphone sdk is 3.1.3
I think it is my fault in calling the VideoFrameExtractor. The example code doesn't work well. I have to change from videoExtractor.currentImage to [videoExtractor currentImage]
Why would you use ffmpeg? You can extract frames using the AVFoundation framework in iOS4. It's faster and easier to use.
Can you paste in your stack trace and possibly the code you are using to read the frames?

Cannot play a recorded sound on device

I'm using the exact code from the iPhone Application Programming Guide Multimedia Support to use AVAudioRecorder to record a file to the disk and then AVAudioPlayer to load and play that file.
This is working fine in the simulator but is not working on the device. The file gets loaded (we can see the NSTimeInterval) but does not play (play returns false).
After it didn't work with the sample code from the website, we tried changing to a bunch of different codecs with no success. And of course, the sound is on.
Thanks a bunch.
SOLVED!
The problem was that after you set the AVAudioSession category to Record for recording, you have to set it to Play for playing. Sounds obvious now but you know how it is. When you use the Simulator it uses a different underlying implementation so this problem does not show up.

NSSound undeclared on iPhone?

sound = [[NSSound alloc] initWithContentsOfFile:#"staticbeam09.wav" byReference:YES];
Code referenced from Apple docs. Getting an error when I put this in viewDidLoad. If I put
NSSound *sound;
in the header file, I get the specifier-qualifier error at the top of my implementation file. What do I have to do to make this work? I was just pasting the code from Apple's documentation - has this been deprecated? Thanks for your help!
There is no NSSound class in iPhone SDK
It's only for MacOS
Oxigen’s right. If you want to play sounds on iPhone, there are several options. Probably the easiest one is using Audio Services (example wrapper), then there is AVAudioPlayer and then you can also use OpenAL (I’ve written a very basic OpenAL sound effect engine called Finch). Depends on what you need to do.
http://icodeblog.com/2009/05/04/iphone-game-programming-tutorial-part-4-basic-game-audio/
that is how i did the audio bg music and sound effects at the end for iconquer

How to debug a AVAudioPlayer play failure?

I'm using an AVAudioPlayer to play a mono AIFF file from my app's Documents directory.
On the simulator, [player play] returns YES and I hear the file playing. On the device the play method returns NO and nothing happens. I grabbed the file via the Organizer - it plays back fine on my Mac and seems to be well-formed. I realize the simulator can access codecs that aren't available on the iPhone, but that shouldn't matter in this case, should it?
I'm at a loss as to how to debug this. Any suggestions?
I asked this question on Apple's forum and someone there asked if I had activated an Audio Session. I hadn't, and doing so fixed my problem.
Make sure you do not use an absolute path to the audio file. When you move to device, the paths change. You need to get the path to the documents folder using the standard methods and then add the relative path to your audio file. That way you get a correct path regardless of the hardware or other changes.
Create a delegate to the audio player, and override -audioPlayerDecodeErrorDidOccur:error: to see if any error happens.