2012-07-18 8 views
0

내가 원하는 것은 내 앱이 배경으로 들어갈 때 (홈 버튼을 눌렀을 때) 사운드 재생을 중단해야한다는 것입니다. 나는 appDelegate.m에 이런 짓을하지만 내가 대표로 내 VC를 가져온 또한 속성으로 soundID 노출 된 use of undeclared identifier 'soundID'앱이 백그라운드로 들어갈 때 이벤트를 처리합니다.

- (void)applicationDidEnterBackground:(UIApplication *)application 
{ 
    AudioServicesDisposeSystemSoundID(soundID) 
} 

말한다. 내가 어디로 잘못 가고 있니? 도와주세요.

NSString *path = [[NSBundle mainBundle] pathForResource:@"something" ofType:@"wav"]; 
    NSURL *url = [NSURL fileURLWithPath:path]; 
    AudioServicesCreateSystemSoundID((CFURLRef)url, &soundID); 
    AudioServicesPlaySystemSound(soundID); 

답변

0

당신이 그 기능을 원하는 경우에 당신은 (아마도 [your-app-name]-Info.plist 이름) 앱이 주요 PLIST 파일에 가서 거기에 키 찾아야한다 : 값

Required background modes 

을 제거

App plays audio 

그 트릭을해야합니다.

---------------- 편집 :

이 시도 :

NSString* path = [[NSBundle mainBundle] pathForResource:@"myWavFile" ofType:@"wav" inDirectory:@"DirectoryName"]; 
self.player = [AVPlayer playerWithURL:[NSURL fileURLWithPath:path]]; 
[self.player play]; 

자체 플레이어 인 경우 :

@property (strong, nonatomic) AVPlayer *player; 

또한해야합니다 :

#import <AVFoundation/AVFoundation.h> 

그리고이 프레임 워크를 프로젝트에 추가하십시오.

+0

'필수 배경 모드'키가 이미 누락되었습니다. –

+0

그러면 오디오가 백그라운드 모드에서 재생되지 않아야합니다! 오디오 재생 방법 코드를 게시하십시오. – Kuba

+0

짧은 시스템 사운드를 사용하여 오디오를 재생하고 있습니다. 나는 내 질문을 편집 할 것이다. –

관련 문제