2014-03-26 5 views
0

내가 너무 좋아, 내 아이폰 OS SpriteKit 응용 프로그램에서 사운드를 재생하기 위해 노력하고있어 재생되지 않는 소리 SpriteKit :

var action = SKAction.PlaySoundFileNamed("filename.wav", false); 
SKAction.RunAction(action, "action-name"); 

사운드 파일이 존재 확인 것, PlaySoundFileNamed 그렇지 않으면 예외가 발생하기 때문.
조치가 처음 실행될 때 응용 프로그램이 약간 불안감을 나타 내기 때문에 무언가가임을 확인할 수도 있습니다 (해결 방법은 알고 있지만, 뭔가 확인한 것입니다). 내가 시도

것들 :
- true 대신 falsePlaySoundFileName 행동에 waitForCompletion을 설정합니다.
- .WAV.M4A 형식의 사운드를 사용 - AVAudioSession.SharedInstance().SetActive(true, out error)
가 호출합니다.
- 장치 및 시뮬레이터 모두에서 테스트되었습니다.

소리가 들리지 않습니다 ...
아이디어가 있으십니까?

+0

확인 (즉 비 압축 wav) – LearnCocos2D

+0

압축되지 않았습니다. 비 압축 wav로 업데이트되었지만 여전히 사운드가 없습니다. 모노 파일입니다. –

답변

1

여전히 Sprite Kit에서 작동하지 않지만 AVAudioPlayer를 사용하여 해결했습니다.

public class SoundFile 
{ 
    private AVAudioPlayer audioPlayer; 

    public SoundFile(string fileName) 
    { 
     this.FileName = fileName; 
    } 

    public string FileName { get; set; } 

    public bool PreLoaded { get; set; } 

    public void PreLoad() 
    { 
     this.audioPlayer = AVAudioPlayer.FromUrl(new NSUrl(this.FileName)); 
     this.audioPlayer.CurrentTime = 0; 
     this.audioPlayer.NumberOfLoops = 0; 
     this.audioPlayer.Volume = 1.0f; 
     this.audioPlayer.PrepareToPlay(); 

     this.PreLoaded = true; 
    } 

    public void Play() 
    { 
     if (!this.PreLoaded) 
     { 
      this.PreLoad(); 
     } 

     Task.Run(() => 
     { 
      this.audioPlayer.CurrentTime = 0; 
      this.audioPlayer.Play(); 
     }); 
    } 
} 

다음과 같이 그것을 재생 :

var sound = new SoundFile("my-filename.wav"); 
sound.Play(); 

(분명히 미리로드 먼저 소리) 사운드 파일이 모노가 아닌 스테레오, 호환되는 형식으로되어 있는지