表題の件について質問させてください。
AndroidのSoundPoolで、
再生開始後、はじめに1秒の間隔を空けてから、5つの音を400ms間隔で再生しようとしているのですが、
空白が終わった後の1音目と2音目の間だけ間隔が狭くなり、その後は順調に再生されます。
なぜ最初だけ間隔が合わないのか、心当たりのある方いらっしゃいますでしょうか?
よろしくお願いいたします。
Kotlin
1var playList = mutableListOf<Int>(3,5,2,1,4,5,3,1,3,5,3,4,1,2,5) 2 3val audioAttributes = AudioAttributes.Builder() 4 .setUsage(AudioAttributes.USAGE_GAME) 5 .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH) 6 .build() 7 8val sp = SoundPool.Builder() 9 .setAudioAttributes(audioAttributes) 10 .setMaxStreams(5) 11 .build() 12 13val sound1 = sp.load(this, R.raw.sound1, 1) 14val sound2 = sp.load(this, R.raw.sound2, 1) 15val sound3 = sp.load(this, R.raw.sound3, 1) 16val sound4 = sp.load(this, R.raw.sound4, 1) 17val sound5 = sp.load(this, R.raw.sound5, 1) 18 19val runnable = object : Runnable { 20 override fun run() { 21 22 if (setCount == 0) { 23 // 最初に1秒の空白 24 setCount++ 25 handler.postDelayed(this, 1000) 26 } 27 else if (setCount > 3) { 28 // 再生を終了 29 handler.removeCallbacks(this) 30 } 31 else { 32 // 400ms間隔で再生 33 playSound = playList[playCount].toString() 34 when(playSound) { 35 "1" -> sp.play(sound1, 1.0f, 1.0f, 0, 0, 1.0f) 36 "2" -> sp.play(sound2, 1.0f, 1.0f, 0, 0, 1.0f) 37 "3" -> sp.play(sound3, 1.0f, 1.0f, 0, 0, 1.0f) 38 "4" -> sp.play(sound4, 1.0f, 1.0f, 0, 0, 1.0f) 39 "5" -> sp.play(sound5, 1.0f, 1.0f, 0, 0, 1.0f) 40 } 41 playCount++ 42 43 if (playCount % 5 == 0) { 44 setCount++ 45 } 46 47 handler.postDelayed(this, 400) 48 } 49 } 50} 51 52val btn = findViewById(R.id.measureBtn) 53btn.setOnClickListener { 54 handler.post(runnable) 55}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。