MediaPlayer最终确定而未被释放......声音正在停止

时间:2014-03-07 06:39:06

标签: android media-player audio

我的代码工作正常,但突然声音因此错误而停止“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(),我检查过声音没有停止。

0 个答案:

没有答案