2016-11-16 1 views
3

iPhone ios10にインストールした後、出荷準備完了のアプリストアのサウンドが再生されなくなりました!助けて! SKAction:ios9すべてが完璧スプライトキットがiOS10でサウンドを再生しなくなった

SKAction.playSoundFileNamed("Lose_bell.wav", waitForCompletion: false) 

[72963 476]:働いたとサウンドリソース

+0

同じ問題https://forums.developer.apple.com/thread/63532 – SashDing

+0

残念なことに、SpriteKitのサウンドに関する長い歴史があります。そのサウンドがSKActionによって見つかったことを確認しましたか?アクションを格納する変数を作成しようとしましたか?これは奇妙ですが、プロジェクトにサウンドファイルを再インポートしてみてください...一つずつ...? – Confused

+0

@SashDingによってリンクされたスレッドから、これを試してください: 'var enemyCollisionSound:SKAction {return SKAction.playSoundFileNamed(" Lose_bell.wav "、waitForCompletion:false)}' – Confused

答えて

2

を演奏エラーを私は、この問題によって、本当にイライラしたので、私は一時的にこの問題を回避するためにJKAudioPlayerと呼ばれる独自のカスタムクラスを作成し、私のために私のすべてのオーディオを処理します。

2つのAVAudioPlayerオブジェクトがあります。 1は音楽を再生し、1は音を再生します。

ここにクラスがあります。

import Foundation 
import SpriteKit 
import AVFoundation 

/**Manages a shared instance of JKAudioPlayer.*/ 
private let JKAudioInstance = JKAudioPlayer() 

/**Provides an easy way to play sounds and music. Use sharedInstance method to access 
    a single object for the entire game to manage the sound and music.*/ 
open class JKAudioPlayer { 

    /**Used to access music.*/ 
    var musicPlayer: AVAudioPlayer! 
    var soundPlayer: AVAudioPlayer! 

    /** Allows the audio to be shared with other music (such as music being played from your music app). 
    If this setting is false, music you play from your music player will stop when this app's music starts. 
    Default set by Apple is false. */ 
    static var canShareAudio = false { 
     didSet { 
      canShareAudio ? try! AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient) 
       : try! AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategorySoloAmbient) 
     } 
    } 

    /**Creates an instance of the JAAudio class so the user doesn't have to make 
     their own instance and allows use of the functions. */ 
    open class func sharedInstance() -> JKAudioPlayer { 
     return JKAudioInstance 
    } 

    /**Plays music. You can ignore the "type" property if you include the full name with extension 
     in the "filename" property. Set "canShareAudio" to true if you want other music to be able 
     to play at the same time (default by Apple is false).*/ 
    open func playMusic(_ fileName: String, withExtension type: String = "") { 
     if let url = Bundle.main.url(forResource: fileName, withExtension: type) { 
      musicPlayer = try? AVAudioPlayer(contentsOf: url) 
      musicPlayer.numberOfLoops = -1 
      musicPlayer.prepareToPlay() 
      musicPlayer.play() 
     } 
    } 

    /**Stops the music. Use the "resumeMusic" method to turn it back on. */ 
    open func stopMusic() { 
     if musicPlayer != nil && musicPlayer!.isPlaying { 
      musicPlayer.currentTime = 0 
      musicPlayer.stop() 
     } 
    } 

    /**Pauses the music. Use the "resumeMusic" method to turn it back on. */ 
    open func pauseMusic() { 
     if musicPlayer != nil && musicPlayer!.isPlaying { 
      musicPlayer.pause() 
     } 
    } 

    /**Resumes the music after being stopped or paused. */ 
    open func resumeMusic() { 
     if musicPlayer != nil && !musicPlayer!.isPlaying { 
      musicPlayer.play() 
     } 
    } 

    /**Plays a single sound.*/ 
    open func playSoundEffect(named fileName: String) { 
     if let url = Bundle.main.url(forResource: fileName, withExtension: "") { 
      soundPlayer = try? AVAudioPlayer(contentsOf: url) 
      soundPlayer.stop() 
      soundPlayer.numberOfLoops = 1 
      soundPlayer.prepareToPlay() 
      soundPlayer.play() 
     } 
    } 
} 

使用方法は次のとおりです。まず、オーディオを扱うためのグローバル変数を作成します。

let audio = JKAudioPlayer.sharedInstance() 

次に、サウンドを再生するときはいつでも、これを実行します。

audio.playSoundEffect(named: "SoundFileName.type") 

サウンドが再生されます。文字列にファイルの種類を指定する必要があります。私は完全にサウンドを再生し、自分のコードに変更したすべてのSKActionsを取り除きました。それは今すべて完璧に動作し、エラーはありません。私はJKButtonNodeと一緒にこのクラスを使ってサウンドを再生しました。

そして、私のサウンドファイルはすべて.mp3から.wavにしました。それがうまくいくかどうかは分かりませんが、SKActionエラーが発生した時点ですべてを切り替えました。

また、私のためにショートカットを追加しました。ユーザーが自分のゲームをプレイしているときに音楽を再生できるようにするには、このコードをGameViewControllerに追加します。

JKAudioPlayer.canShareAudio = true 
+2

ありがとうございます! – SashDing

+0

これはおそらく、次のようなサウンドをロードするときの例外を取り除きます: 'let actionSound1 = SKAction.playSoundFileNamed(" ActionBeep_AP1。6 "、waitForCompletion:false)' – Confused

+0

上記のコメントのように、SKActionsでこのようなサウンドが読み込まれているようで、3つの例外を作成してプロジェクトのフォルダ内の最初の3つの検索で見つけられません。それは27回の例外で、私が始めるたびに怒っているのですが、それ以外の意味ではうまくいきます。 – Confused

2

英語を修正してください。申し訳ありません。私は問題が何かを発見した。以前は、アクションはすべての構成要素を完了するまで終了しませんでした。 iOS10は、重要な問題を再生することを考慮せず、他のアクション項目を完了するとすぐに破棄します。満たすために

run(SKAction.sequence([SKAction.playSoundFileNamed("Lose_bell.wav", waitForCompletion: fals), SKAction.removeFromParent()])) 

しかし、この時間:たとえば、このオプションは、オーディオスニペットを実行しません

run(SKAction.sequence([SKAction.playSoundFileNamed("Lose_bell.wav", waitForCompletion: fals),SKAction.wait(forDuration: 5.0), SKAction.removeFromParent()])) 

それが何らかの形で実行する株式を待たせすることは可能ですか?メソッドwaitForCompletion: trueは機能しません。

関連する問題