7

I have a very simple Fragment which is my app's starting screen. It's basically just two buttons and when you click the PLAY button a sound is played using a SoundPool and the app navigates to another Fragment. The code is as follows:

class FirstFragment : Fragment(R.layout.fragment_first) {

    // Set up binding for FirstFragment
    private var _binding: FragmentFirstBinding? = null
    private val binding get() = _binding!!

    // Prepare button views
    private lateinit var playButton: Button
    private lateinit var leaderboardButton: Button

    // SoundPool for playing PLAY sound
    private lateinit var soundPool: SoundPool
    private var soundIdStart: Int = 0

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        _binding = FragmentFirstBinding.inflate(inflater, container, false)
        return binding.root
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
        soundPool.release()
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        // Set soundPool and PLAY sound
        soundPool = SoundPool.Builder().setMaxStreams(1).build()
        soundIdStart = soundPool.load(context, R.raw.start_sound, 1)

        // Get button views
        playButton = binding.playButton
        leaderboardButton = binding.leaderboardButton

        // On click of LEADERBOARD show top scores
        leaderboardButton.setOnClickListener {
            CoroutineScope(Dispatchers.Main).launch {
                // Navigate to the Leaderboard fragment
                findNavController().navigate(R.id.action_FirstFragment_to_SecondFragment)
            }
        }

        // On click of PLAY start game in new Fragment
        playButton.setOnClickListener {
            CoroutineScope(Dispatchers.Main).launch {
                // Play the start sound
                playStartSound(soundIdStart)
                // Navigate to the game fragment
                findNavController().navigate(R.id.action_FirstFragment_to_ThirdFragment)
            }
        }
    }

    private fun playStartSound(resourceFile: Int) {
        soundPool.play(resourceFile, 1.0F, 1.0F, 0, 0, 1.0F)
    }
}

The app doesn't crash, but I get a bunch of errors:

E/FMQ: grantorIdx must be less than 3
E/FMQ: grantorIdx must be less than 3
E/ion: ioctl c0044901 failed with code -1: Inappropriate ioctl for device
E/FMQ: grantorIdx must be less than 3
E/FMQ: grantorIdx must be less than 3

I searched online and it seems like it's linked to the SoundPool, but I'm not sure what to do with it. It doesn't crash the app, but it's annoying and clearly something is wrong with it. After moving to the next Fragment which has SoundPool too I get the same errors. Any help will be highly appreciated.

Klariskao
  • 133
  • 1
  • 8

1 Answers1

1

This octl error mostly occurs when you are using an inappropriate property for a view.

In my situation, I was using the layout_center_horizontal property on an ImageView.

check your views and the properties you associated with them.

pz64_
  • 2,212
  • 2
  • 20
  • 43
Iupac
  • 11
  • 2