声音池在OS棒棒糖中无法播放任何声音,等等

时间:2020-02-24 05:50:33

标签: java android soundpool

我只播放1-3秒的声音来描述用户点击的单词,我使用Whatsapp语音聊天中的.wav声音,当我使用kitkat设备时,声音会播放,但在棒棒糖或Oreo设备中声音不会播放

if (Build.VERSION.SDK_INT>= Build.VERSION_CODES.LOLLIPOP){
            AudioAttributes audioAttributes = new AudioAttributes.Builder()
                    .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
                    .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                    .build();
            soundPool = new SoundPool.Builder()
                    .setMaxStreams(1)
                    .setAudioAttributes(audioAttributes)
                    .build();
        } else {soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);}


        hitam.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                int suara = soundPool.load(BoardActivity.this, R.raw.l2_warna_hitam, 1);

                soundPool.play(suara, 1,1,1,0,1);


                if (listKataYangDipilih == " "){
                    listKataYangDipilih = "Hitam";
                }else listKataYangDipilih = listKataYangDipilih + "- Hitam";
                TextView listText = findViewById(R.id.listKataYangDipilih);
                listText.setText(listKataYangDipilih);
            }
        });

0 个答案:

没有答案