0
오디오 플레이어가있는 클래스가 있습니다. B 클래스에는 배경 음악 재생을 중단하고 배경 음악을 중단하고 싶을 때 전환 할 수있는 스위치가 있습니다.문제 AVAudioPlayer 시작 및 중지
스위치를 통해 음악을 중단하고 재생할 수 없습니다. 나는 그것을 어떻게 클래스 B의 스위치 없음
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/bgmusic.wav", [[NSBundle mainBundle] resourcePath]]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = -1;
[audioPlayer play];
if (audioPlayer == nil) NSLog([error description]);
else [audioPlayer play];
을 클래스의 viewDidLoad에서 내 오디오 플레이어를 할 수
-(IBAction) musicValueChanged:(id)sender{
if (musicSwitch.on) {
isStopped = FALSE;
firstViewController.player.currentTime = 0;
[firstViewController.audioPlayer play];
}else {
[firstViewController.audioPlayer volume:0];
}
}
되어 이것을이됩니다 ?
어디서 붙어 있습니까? 무엇을 시도 했습니까? 우리는 초능력이 아니므로 디자인이 어떻게 생겼는지 알려줘야합니다. –
이것은 A 클래스의 viewdidload에있는 내 오디오 플레이어입니다. NSURL * url = [NSURL fileURLWithPath : [NSString stringWithFormat : @ "% @/bgmusic.wav", [[NSBundle mainBundle] resourcePath]]]]; \t \t NSError * error; \t audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL : url 오류 : & 오류]; \t audioPlayer.numberOfLoops = -1; \t \t [audioPlayer play]; \t if (audioPlayer == nil) \t \t NSLog ([오류 설명]); \t else \t \t [audioPlayer play]; – iscavengers
이 클래스 B 의 스위치 없음이 - (IBAction를는) musicValueChanged (ID) 송신기 {\t \t 경우 (musicSwitch.on) { \t \t isStopped = FALSE 단계; \t \t firstViewController.player.currentTime = 0; \t \t [firstViewController.audioPlayer play]; \t} else {[firstViewController.audioPlayer volume : 0]; }} – iscavengers