iOS模拟器中没有声音音频文件

时间:2011-08-15 12:26:41

标签: ios ios-simulator

我正在尝试在iOS模拟器上播放音频文件(.mp3)并且它听不到声音。我很确定代码没有问题(我从书中复制了它......)。

似乎一切运作良好,但你什么都没听到......

更多信息:系统声音在模拟器上运行良好,当您使用AVAudioPlayer时会出现问题。

非常感谢!

卡洛斯

以下是代码:

// init of the ViewController
init {
    self = [super initWithNibName:@"MediaPlayerViewController" bundle:nil];
    NSString *musicPath = [[NSBundle mainBundle] pathForResource:@"Music"       ofType:@"mp3"];
    if (musicPath) {
        NSURL *musicURL = [NSURL fileURLWithPath:musicPath];
    NSError *err;
    audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:musicURL             error:&err];
    if (audioPlayer)
    {
        [audioPlayer setDelegate:self];
    }
    else {
        NSLog(@"Error al iniciar el audioplayer");
    }
}
return self;

}

- (IBAction)playAudioFile:(id) sender
{
NSLog(@"playAudioFile!");
if ([audioPlayer isPlaying]) {
    [audioPlayer stop];
}
else {
    NSLog(@"The song should sound");
    if ([audioPlayer play])
        NSLog(@"The song has been played");
        // I see this message in the console!
    else
        NSLog(@"Something was wrong");
}

}

0 个答案:

没有答案