AppDelegate.m: I use this code to start AVAudioPlayer and it works fine for all SKScene.
#import "AppDelegate.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
{
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"game-sound" ofType:@"mp3"];
NSURL *file = [NSURL fileURLWithPath:soundFilePath];
_backgroundMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:file error:nil];
_backgroundMusic.numberOfLoops = -1;
_backgroundMusic.volume = 0.1;
[_backgroundMusic play];
return YES; }
AppDelegate.h: In the header I add framework and AVAudioPlayer.
#import <AVFoundation/AVFoundation.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, AVAudioPlayerDelegate> {
AVAudioPlayer *_backgroundMusic; }
Prefix.pch: In Prefix I add this line:
#import "AppDelegate.h"
#define MyAppDelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate])
I need to stop AVAudioPlayer in the GameScene and to continue playing in the MenuScene. Can anyone help me to find a solution of this problem?:)