시작시에만 음악을 어떻게 재생합니까? 나는 시작시에만 음악을 연주하고 싶다. 지금은 viewDidLoad 메서드에 있습니다. 그 페이지로 돌아올 때마다 소리가 재생됩니다. 한 번만 재생할 수 있습니까?시작시 음악을 어떻게 재생합니까?
알았습니다. 당신은 applicationDidBecomeActive 문에 넣어 :
코드 :
-(void)applicationDidBecomeActive:(UIApplication *)application {
[player setVolume:1];
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/PBLTune.mp3", [[NSBundle mainBundle] resourcePath]]];
NSError *error;
player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
player.numberOfLoops = 0;
if (player == nil)
NSLog([error description]);
else
[player setVolume:0.1];
[player play];
}
한 번 재생하려면'numberOfLoops'를 1로 설정하십시오. –