iPod touch没有播放声音

时间:2017-04-18 11:57:45

标签: ios objective-c

除了iPod touch没有播放前景中的声音外,所有设备都在前台播放声音,当应用收到通知时,

下面我们已经粘贴了确切的代码

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];

1 个答案:

答案 0 :(得分:1)

检查代码:

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!");
            }