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
Related
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.
Please I know how to play a sound in AVAudioPlayer but I would like to know how to give it a list of on-disk files to play one after the other (play list)
Anyone has any idea?
You have to manage this by yourself, using the 'audioPlayerDidFinishPlaying' method to know when the current song is over, and when to start a new one.
The Apple "AddMusic" sample program does exactly this, setting up a playlist of audio files using MPMusicPlayerController and AVAudioPlayer to do most of the work.
Is there anyway to store audio on an iphone app and then grab that audio file and play it through code. Does anyone have a tutorial to point me to do something like this?
Check the AVAudioPlayer class here http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AudioandVideoTechnologies/AudioandVideoTechnologies.html#//apple_ref/doc/uid/TP40007072-CH19-SW1
Should tell you what you need to know.
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.
I want to use AVAudioPlayer to play MP4 files from iTunes generator. I could use UIWebView to play it and it worked, but I want to put an image of my choice on the background of the player instead of the "QuickTime"-logo.
Here is an example of the m4p file I want to play with AVAudioPlayer.
If your question is, "can someone help me figure out how to use AVAudioPlayer," then I'd recommend taking a look at Apple's avTouch sample app, the documentation for AVAudioPlayer, and the guide Getting Started with Audio & Video.
When it happened to me I had a missing '/' on the end of my url. Adding that cleared me right up.