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

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

4

1 回答 1

1

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

确保musicPath和不为空且有效musicPath1musicPath2

于 2012-07-16T09:34:08.193 回答