2012-07-05 5 views
0

최근에는 내 앱이 열렸을 때 열어 놓은 상태에서 사운드가 재생되도록 노력하고 있습니다. 어려움이 있습니다. 나는 버튼을 누를 때 소리를내는 것에 대한 몇 가지 코드를 가지고있다. 그리고 그 자체로 그리고 처음부터 재생할 수있는 비틀기가 있는지, 아니면 내가 말할 수있는 방법이 있는지는 궁금하다. 왜 내가 게임을하고 있는지 사운드 루프를 만들어라.애플 리케이션이 실행 중일 때 오디오 재생

.H

#import <AudioToolbox/AudioToolbox.h> 


    - (IBAction)t1:(id)sender; 

하는 .m

- (IBAction)t1:(id)sender { 

    CFBundleRef mainbundle = CFBundleGetMainBundle(); 
    CFURLRef soundFileUrlRef; 
    soundFileUrlRef = CFBundleCopyResourceURL(mainbundle, (CFStringRef) @"t1", CFSTR ("wav"), NULL); 
    UInt32 soundID; 
    AudioServicesCreateSystemSoundID(soundFileUrlRef, &soundID); 
    AudioServicesPlaySystemSound(soundID); 
} 

답변

1

방법 AVAudioPlayer을 시도하고 -1로 루프의 설정 번호로 연속 재생 켜기에 대한 :

myPlayer.numberOfLoops = -1 

    [myPlayer prepareToPlay]; 

    [myPlayer play]; 


    //when application did enter background or something 
    [myPlayer stop]; 

http://developer.apple.com/library/ios/#DOCUMENTATION/AVFoundation/Reference/AVAudioPlayerClassReference/Reference/Reference.html

또한 오디오 세션이 배경 재생이 제대로 설정되어 있는지 확인 : http://developer.apple.com/library/ios/#DOCUMENTATION/Audio/Conceptual/AudioSessionProgrammingGuide/Basics/Basics.html#//apple_ref/doc/uid/TP40007875-CH2-SW2

+0

난 그냥 그 코드를 추가하거나 내가 코드 친구는 – Picm

+0

감사 버디 더 필요합니까! – Picm

+0

오디오 플레이어를 초기화하고 원본 오디오 파일을 제공해야합니다. AVAudioPlayer * myPlayer = [[AVAudioPlayer alloc] initWithData : [NSDataDataWithContentsOfFile : [[NSBundle mainBundle] pathForResource : @ "audioFile "ofType : @"wav "]] 오류 : 없음]; –

관련 문제