NullPointerException while using Android's mediaplayer

后端 未结 3 1670
傲寒
傲寒 2020-12-11 13:39

I have two button and it will play a sound to notify about right choice, or wrong one. This is how I do it:

MediaPlayer playError = MediaPlayer.create(QuizA         


        
3条回答
  •  -上瘾入骨i
    2020-12-11 14:35

    I'm afraid all answers here are wrong. I encountered this issue, albeit more than a year later, but after some research found the answer. It's in two parts.

    1. Best to start the mediaplayer AFTER the declaration of the onCompleteListener. This insures that the mediaplayer has a full list of instructions declared before it even start playing.
    2. Use a statically declared object called an AtomicBoolean. This insures that there is only one boolean parameter, and that the process is locked until it finishes the process. This is the only way to insure a process is thread safe.

    Hope you found this useful (all future programmers that encounter this problem) ;-)

提交回复
热议问题