close

Has anyone had issues playing audio via the SKAction playSoundFileNamed using iOS Sprite Kit through the external speaker of your iOS device? I have the following code that plays the M4A file with no issue through the headphones; however, no audio is played when I unplug the headphones stepping through code it executes just no sound. I have another app that does not use this method and it plays with no issue.

-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event{/* Called when a touch begins */for(UITouch*touch in touches){CGPoint location =[touch locationInNode:self];SKAction*sound =[SKAction playSoundFileNamed:@"blast.m4a" waitForCompletion:NO];[self runAction:sound];}




I had a similar issue but was able to fix it by setting AudioSession category to Playback. This causes the audio to be routed through the phone's speaker when headphones aren't plugged in.

要多加下面這一行程式碼

// at the top of AppDelegate.m#import <AVFoundation/AVFoundation.h>// in application:didFinishLaunchingWithOptions:NSError*error;[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];

You can find more information about this in Apple's Audio Session Programming Guide.

arrow
arrow
    全站熱搜

    pcwiki 發表在 痞客邦 留言(0) 人氣()