MediaPlayer finalized without being released… Soun

2019-10-19 12:18发布

我的代码工作正常,但突然的声音越来越停止这种错误“的MediaPlayer而不释放敲定”

我的代码是

public void PLAYSOUND(MediaPlayer Player, boolean value,SOUND sound) throws IllegalArgumentException, SecurityException, IllegalStateException, IOException{

      try {
            AssetFileDescriptor descriptor = null;
            if (Player != null) {
                Player.stop();
                Player.release();
                Player = new MediaPlayer();
            }else
                Player = new MediaPlayer();

            descriptor = GameManager.getInstance().getCurrentActivity().getAssets().openFd("sound/mainmenu.wav");

            //AssetFileDescriptor descriptor = GameManager.getInstance().getCurrentActivity().getAssets().openFd("sound/mainmenu.wav");
            Player.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());    
            Player.setAudioStreamType(AudioManager.STREAM_MUSIC);

            descriptor.close();

            Player.prepare();
            Player.setLooping(value);
            if(mCheckVolumeOnOff)
                Player.setVolume(2.0f, 2.0f);
            else
                Player.setVolume(2.0f,2.0f);
            Player.start();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

我已签的声音是没有得到,因为.stop()和.release()停止。

文章来源: MediaPlayer finalized without being released… Sound is getting stop