Prabhat Pandey
Prabhat Pandey

Reputation: 277

iPod touch not Playing sound

All device is playing the sound in foreground except iPod touch not playing the sound in foreground, When the app receive notification,

Below we have paste the exact code

NSString *playSoundOnAlert = @"Sound.wav";
        NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@",[[NSBundle mainBundle] resourcePath],playSoundOnAlert]];
        NSError *error;
        aVAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
        aVAudioPlayer.numberOfLoops = 0;
        [aVAudioPlayer play];

Upvotes: 0

Views: 39

Answers (1)

NAVEEN KUMAR
NAVEEN KUMAR

Reputation: 667

check the code:

NSString *playSoundOnAlert = @"Sound";    

 AVAudioPlayer *audioPlayer;

            NSString *audioPath = [[NSBundle mainBundle] pathForResource: playSoundOnAlert  ofType:@".wav"];
            NSURL *audioURL = [NSURL fileURLWithPath:audioPath];
            NSError *audioError = [[NSError alloc] init];
            audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioURL error:&audioError];

            if (!audioError) {
                [audioPlayer play];
                NSLog(@"playing!");
            }
            else {
                NSLog(@"Error!");
            }

Upvotes: 1

Related Questions