?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

Sprite Kit & playing sound leads to app termination


게임에서 중요한 효과 중에 하나인 사운드.

Sprite Kit을 이용하는 경우 아래와 같이 SKAction class method를 이용해 사운드를 재생할 수 있다.

@implementation Scene{
    . . .
    SKAction *pointSound;
}

- (void) initSounds
{
    . . .
    pointSound = [SKAction playSoundFileNamed:@"point.mp3"
        waitForCompletion:NO];
}

- (void) updateScore:(NSTimeInterval) currentTime
{
    . . .
    [self runAction:pointSound];
}

하지만, 앱이 백그라운드로 진입하면 비정상적으로 종료되는 현상이 발생된다.

(이 현상은 설치된 앱보다 디버깅 상태에서 쉽게 발견할 수 있음)


앱이 백그라운드에 진입하면 AVAudioSession이 활성화 될 수 없기 때문이다.

하지만, Sprite Kit 내부적으로 AVAudioSession을 사용한다는 언급이 없기 때문에 명확한 원인은 아닐 수 있다.

이런 원인으로 접근했을 때 개선하는 방법은 간단하다.

아래처럼 AVAudioSessoin을 앱이 백그라운드 상태 동안 비활성, 포그라운드로 진입하면 활성화로 설정하는 코드를 추가하면 된다.


AVAudioSession 활성화 설정 코드

#import <AVFoundation/AVFoundation.h>
...

- (void)applicationWillResignActive:(UIApplication *)application
{
    // prevent audio crash
    [[AVAudioSession sharedInstance] setActive:NO error:nil];
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // prevent audio crash
    [[AVAudioSession sharedInstance] setActive:NO error:nil];
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // resume audio
    [[AVAudioSession sharedInstance] setActive:YES error:nil];
}


[출처] http://stackoverflow.com/questions/18976813/sprite-kit-playing-sound-leads-to-app-termination

?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
293 System/OS [mac] SVN 1.8 업데이트 방법 hooni 2013.09.24 14705
292 System/OS [mac] VirtualBox 실행 스크립트와 bash_profile 설정 file hooni 2020.07.08 1194
291 System/OS [mac] 맥(OSX)에서 NTFS, 윈도우에서 HFS+ 사용하기 file hooni 2014.03.12 5184
290 System/OS [mac] 맥(OSX)에서 root 패스워드 설정하기 hooni 2013.04.23 22627
289 System/OS [mac] 맥OSX에서 NTFS 쓰기 기능 활성화 hooni 2014.03.12 4370
288 System/OS [mac] 맥에서 APM(apache,php,mysql) 구성하기 hooni 2013.04.23 38828
287 System/OS [mac] 맥에서 기본 실행 앱 변경하기 file hooni 2018.03.02 1968
286 System/OS [mac] 맥에서 슬립(잠자기) 모드 진입을 막는 방법~ hooni 2013.10.10 31292
285 System/OS [mac] 컨텍스트(Context) 메뉴 "다음으로 열기" 내용 정리 hooni 2013.07.10 18900
284 System/OS [mac] 패키지 매니저, MacPort hooni 2015.01.03 1126
283 System/OS [mac][추천 무료앱] 구름 입력기 - 국내 맥 사용자를 위한 한글 대안 입력기 1 file hooni 2015.01.04 2305
282 Develop [matlab] ZigZag-Scanning (2-D Array) file hooni 2016.10.15 2115
281 Develop [matlab] 정보은닉 스테가노그래피(Steganography) 수업 file hooni 2016.10.03 787
280 Develop [maven] Mac OS에 메이븐(maven) 설치하기 file hooni 2015.01.21 1222
279 System/OS [ms-sql] 서브스트링(substring), 프로시저(SP) 작성 예제 hooni 2013.04.23 41394
278 System/OS [ms-sql] 프로시져 예제.. file hooni 2013.04.23 13503
Board Pagination Prev 1 ... 54 55 56 57 58 ... 74 Next
/ 74