2009-06-23 3 views
1

먼저 StackOverflow 팀에게 감사드립니다. 왜냐하면 저는 iPhone에서 개발 중이므로 매우 유용한 웹 사이트이기 때문입니다. 2 차적으로, 제 언어를 실례합니다. 나는 frenchie이고 모든 frenchies처럼 나는 영어로 매우 나쁘다.SystemSoundID의 다른 인스턴스가 다른 스트림에서 재생 중입니다!

내 iPhone 프로그램에서 내 소리에 이상한 문제가 있습니다. aiff에서 짧은 사운드를 재생하는 클래스를 구현했습니다. 여기에 있습니다 :

@implementation SoundPlayer 

-(id)initWithFile:(NSString*)file{ 
    self = [super init]; 
    NSString *soundPath = [[NSBundle mainBundle] pathForResource:file ofType:@"aiff"]; 
    AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath: soundPath], &soundID); 
    return self; 
} 

-(void)play { 
    if(SOUND_ACTIVATED){ 
     AudioServicesPlaySystemSound (soundID); 
     } 
} 

-(void)dealloc{ 
    [super dealloc]; 
} 

@end 

매우 훌륭하게 작동하지만 인스턴스가 같은 방식으로 초기화 되더라도 동일한 오디오 스트림에 있지는 않습니다.

아이폰의 볼륨 + 버튼과 볼륨 버튼을 누르면 어떤 경우에는 메인 오디오 스트림을 제어하기 때문에, 다른 경우에는 링 볼륨을 제어하기 때문에 눈치 챘다. 주 스트림을 볼륨 0에 넣으면 A 소리는 들리지 않지만 B 소리가 들립니다.

비슷한 문제가 있습니까? 너는 어떤 생각을 가지고 있니?

고마워요.

마틴

+0

soundID가 SystemSoundID 변수라는 것을 잊어 버렸습니다. – Martin

답변

1

확인. 문제에 대한 답을 찾는 것이 재미있을 것 같습니다. 오디오 컨텍스트를 초기화하는 전역 함수가 있습니다. 그것은 내가 올바른 방법으로 사용하지 않는 것 같지만 문제는 거기에서 오는 것이라고 생각합니다.

// Initialize the Audio context 
AudioSessionInitialize (
    NULL,   // 'NULL' to use the default (main) run loop 
    NULL,   // 'NULL' to use the default run loop mode 
    NULL,   // a reference to your interruption callbac 
    self   // data to pass to your interruption listener callback 
); 

// What kind of sound will be played 
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback; 
AudioSessionSetProperty (
    kAudioSessionProperty_AudioCategory, 
    sizeof (sessionCategory), 
    &sessionCategory 
); 

이 두 기능에도 불구하고 하나의 사운드가 링 스트림에 남아 있으며 실제로 이상합니다. 누군가 나를 도울 수 있습니까?

관련 문제