Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playing sound in iOS7 don't seem to work

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?

like image 731
Arbitur Avatar asked Oct 04 '13 09:10

Arbitur


People also ask

Why is my phone not playing sound on apps?

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.

When I play games on my iPhone there is no sound?

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.

Why is the sound on my apps not working iPhone?

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.

Why is my iPad not playing sound on apps?

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.


1 Answers

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];
like image 70
user1673099 Avatar answered Sep 30 '22 11:09

user1673099