I'm trying to play an audio file in a cocos2d application. Here is the line which tries to play the sound:
[[SimpleAudioEngine sharedEngine] playEffect:#"pig_squeal.wav"];
If I put a log near this line, the log appears, and I can play the sound with iTunes. But when the sound should be played, there is a message displayed:
AudioStreamBasicDescription: 2 ch, 44100 Hz, 'lpcm' (0x00000C2C) 8.24-bit little-endian signed integer, deinterleaved
What's the problem?
This was discussed in comments but I've amalgamated all the possibilities of why it may not work here.:
That's not an error message, just some information.
Is the sound definitely in your library and a part of the target?
You haven't changed the volume of the SimpleAudioEngine or the volume of your device isn't all the way down?
Click the sound in your library. Press Option+Command+1 to bring up the file editor. Scroll down to "Target Membership" and ensure the sound is checked for your target.
Try a different sound effect too? Try and narrow the problem down to "is it SimpleAudioEngine".
Also try and playBackgroundMusic for a sound (This was the solution in this case)
And try an mp3
There isn't a problem. It's a status message written to the log when you initialise the current OpenAL context using alcMakeContextCurrent. As far as I'm aware, you can't get rid of the message.
There is no problems with your code for the Playing of the Sound. Please check the Sound file has been added to the project also do check the format of the sound. It should play the Sound whenever you call the Play Effect. Please also try to PRELOAD the sound effect in the init method.
that message means the song was read correctly and should be playing. possible reasons you don't hear it?
volume turned down.
device malfunctioning
audio has silence in it
audio file is large and will take a long time to load.
sound has been redirect to come out of the headphones or the ear piece (even if not attached)
But the sound is loading and most likely playing.
If you are getting a crash while running in device from xcode pls try this(worked for me). Dissconnect the device from Xcode and run the app in the device. I dont know why it worked like that. But when I did this there was no crash.
Related
I have a Audio Source linked to an Audio Listener looping some music. The problem with the audio is that I cannot hear anything. There are no error messages. I have tried muting the audio and then undoing it. I have also tried to restart Unity and adjusting the values on the Audio Source including pitch, volume, and looping, but the problem continues on. What is even more confusing is that when I started a project, the audio was working well, and then I did some adjusting on the Project Settings: Physics, the audio suddenly stopped. I do not have any code involved in the audio. When I tried to add another Audio Source and testing it to see if the Audio Source is the problem, it still creates no sound. I believe the problem lies nowhere near the Audio Source (though I might be wrong :D). Is there any other way to mute audio that I have missed? Thanks for any help.
Check that the Global Volume Setting under Project settings > Audio and that it is not set to 0. That worked for me.
In my app I want to have an alarm/notification on "Ringer & Alert Volume" level.
In other words on the volume level which phone rings or alarms are used on (Preferences/Sound/Ringer and Alerts). It is different from the system volume level which changes with the volume buttons.
It should also play more than 30 sec.
I know it's possible because some clock apps can do that.
UPDATE:
OK I found an unideal solution. If use AudioServicesCreateSystemSoundID and load my own sound file (aif, wav, etc no mp3 or other compressed audio) than it works.
The only problem is that it has to be 30 sec or shorter, but I can can cut it into 30sec pieces and play them piece by piece.
It does not work when on silent switch on which is a problem for me.
Code:
SystemSoundID mySound;
AudioServicesCreateSystemSoundID(CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("mySound"), CFSTR("aif"), NULL), &mySound);
AudioServicesPlaySystemSound(mySound);
I suspect that OpenAL should do that. Does anyone has a simple example which loads a aif/wav file and plays it on iPhone. I found some complicated examples, but all I need is just play and stop a sound (even if it's leaking that's fine).
I found it out myself. I have to use AudioServicesCreateSystemSoundID and load my own sound file (aif, wav, etc no mp3 or other compressed audio)
The only problem is that it has to be 30 sec or shorter, but I can can cut it into 30sec pieces and play them piece by piece.
It does not work when on silent switch on
Code:
SystemSoundID mySound;
AudioServicesCreateSystemSoundID(CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("mySound"), CFSTR("aif"), NULL), &mySound);
AudioServicesPlaySystemSound(mySound);
You should look into AVAudioPlayer class. It will allow you to play sound files of any duration and you can control the volume output for the specified files you wish to play. I'm not in front of my mac otherwise I would provide code. Let me know if you need further instruction.
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.
Is it possible to play audio and video file at a same time? I want to play different audio file and video file at a same time and also want control for both, so is it possible?
Sorry, not that I know of. The movie view automatically stops all audio files and takes up the whole screen, so you are forced to listen to the audio for the video.
If the audio is part of the video file, yes.
If it's an MP3 file or some other external type how are you planning on playing it? The phone might allow this to happen depending on what you're up too.
You might be in luck soon though...
Another helpful link is here.
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.