设备中的声音问题

时间:2012-07-16 09:21:46

标签: iphone audio

NSString *musicPath = [[NSBundle mainBundle] pathForResource:@"ding" ofType:@"mp3"];
if (musicPath)
{
    if(TapSoud)
    { 
        [TapSoud release];
        TapSoud = nil;
    }
    TapSoud = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:musicPath] error:nil];
}

[TapSoud setDelegate:self];
[TapSoud prepareToPlay];
[TapSoud play];


NSString *musicPath1 = [[NSBundle mainBundle] pathForResource:@"roadrunner" ofType:@"mp3"];
if (musicPath1)
{
    if(MatchSoud)
    { 
        [MatchSoud release];
        MatchSoud = nil;
    }
    MatchSoud = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:musicPath1] error:nil];
}

[MatchSoud setDelegate:self];
[MatchSoud prepareToPlay];

NSString *musicPath2 = [[NSBundle mainBundle] pathForResource:@"Wrong Answer" ofType:@"wav"];
if (musicPath2)
{
    if(WrongMatchSoud)
    { 
        [WrongMatchSoud release];
        WrongMatchSoud = nil;
    }
    WrongMatchSoud = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:musicPath2] error:nil];
}

[WrongMatchSoud setDelegate:self];
[WrongMatchSoud prepareToPlay];

此代码在模拟器中正常工作,但在设备上不会产生声音。这有什么问题?

1 个答案:

答案 0 :(得分:1)

最可能的问题是项目或资源复制阶段缺少音频文件。即使从项目中删除,模拟器也会存储以前复制的资源,直到应用程序从模拟器中完全删除。

确保musicPathmusicPath1musicPath2不为空且有效。