Im having a little problem playing an audio file in iOS7. The audio file doesn't get played because there is no sound when this code is called:
NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"PistolShootSound" ofType:@"mp3"]];
AVAudioPlayer *click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];
[click setVolume:1.0];
[click play];
But no sound is coming out :(
I have checked the sound on my computer and it is working, I have rechecked the "Play user interface sound effects" option in system preferences but with no use. I have tried opening an AVAudioSession like this:
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
[audioSession setActive:YES error:nil];
But that didn't work either.
Is there another way to play a sound in iOS7? or doesn't the simulator play sounds anymore?
Android. Android devices have many different volume controls so it's possible the volume you're turning up isn't the one that controls the volume in the app. To double check, go to your device Settings, find the Sound option and then check the volume level of all the controls.
Check the game settings to make sure the music and sounds are turned on. Force stop and restart the game: double click the home button (or for iPhone X: swipe up from the bottom edge and pause in the center of the screen), find the game and swipe up on the game. Open the game again. Turn your device off and on again.
Go to Settings > Sounds and drag the Ringer And Alerts slider to turn the volume up. If you hear sound from the speaker, follow the rest of these steps. If you can't hear sound from the speaker, contact Apple Support. If your device has a Ring/Silent switch, make sure it's set to ring.
Game apps may have no sound on iPad because the volume in the app's settings is either muted or low. While the device's volume is turned up, you will have to open the app's settings and adjusts the volume accordingly for the sound to resume.
Try this..
@property (nonatomic,strong) AVAudioPlayer *click;
@synthesize click;
NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"PistolShootSound" ofType:@"mp3"]];
click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];
[click setVolume:1.0];
[click preparetoPlay];
[click play];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With