Contents

?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

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
No. Category Subject Author Date Views
297 System/OS [mac] Mac에서 Mac으로 원격제어하기 (맥에서 맥으로) file hooni 2013.10.08 36989
296 System/OS [mac] OS X 엘 캐피탄에서 Soudflower 사용하기 2 file hooni 2016.10.03 876
295 System/OS [mac] OS X 요세미티 사용자가 많이 겪는 버그와 몇몇 불편사항 file hooni 2015.01.04 1518
294 System/OS [mac] OSX(맥) 단축키 설명 ㅎㅎ file hooni 2013.04.23 29561
293 System/OS [mac] SVN 1.8 업데이트 방법 hooni 2013.09.24 14561
292 System/OS [mac] VirtualBox 실행 스크립트와 bash_profile 설정 file hooni 2020.07.08 954
291 System/OS [mac] 맥(OSX)에서 NTFS, 윈도우에서 HFS+ 사용하기 file hooni 2014.03.12 5117
290 System/OS [mac] 맥(OSX)에서 root 패스워드 설정하기 hooni 2013.04.23 22418
289 System/OS [mac] 맥OSX에서 NTFS 쓰기 기능 활성화 hooni 2014.03.12 4286
288 System/OS [mac] 맥에서 APM(apache,php,mysql) 구성하기 hooni 2013.04.23 38616
287 System/OS [mac] 맥에서 기본 실행 앱 변경하기 file hooni 2018.03.02 1804
286 System/OS [mac] 맥에서 슬립(잠자기) 모드 진입을 막는 방법~ hooni 2013.10.10 30880
Board Pagination Prev 1 ... 69 70 71 72 73 74 75 76 77 78 ... 98 Next
/ 98