|
AIO3128播放声音出现问题
发表于 2018-12-28 14:19:04
浏览:23432
|
回复:25
打印
只看该作者
[复制链接]
楼主
声音时有时无,包括系统提示音和音乐。,外接USB声卡播放正常。
不管是外接声卡还是直接使用板载的音频接口都会出现使用soundpool 出现AUDIO_OUTPUT_FLAG_FAST denied by client警告的问题。
请问该如何解决?
测试代码:
- package com.haijie.test;
- import android.content.Context;
- import android.media.AudioManager;
- import android.media.SoundPool;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import java.util.HashMap;
- public class MainActivity extends AppCompatActivity {
- //audio
- public static SoundPool soundPool;
- public static HashMap<String, Integer> sounddata;
- public static Boolean isLoaded;
- private static int streamID = -1;
- public static void playSound(Context context, String sound, int number) {
- AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
- float audioMaxVolumn = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
- float volumnCurrent = am.getStreamVolume(AudioManager.STREAM_MUSIC);
- float volumnRatio = volumnCurrent / audioMaxVolumn;
- streamID = soundPool.play(sounddata.get(sound),
- volumnRatio,// 左声道音量
- volumnRatio,// 右声道音量
- 1, // 优先级
- number,// 循环播放次数
- 1);// 回放速度,该值在0.5-2.0之间 1为正常速度
- }
- public static void stopSound(){
- soundPool.stop(streamID);
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- initAudio();
- Button button = findViewById(R.id.button);
- button.setOnClickListener(new Button.OnClickListener(){
- @Override
- public void onClick(View v) {
- if (isLoaded){
- if (streamID != -1){
- stopSound();
- }
- playSound(MainActivity.this,"finger",0);
- }
- }
- });
- }
- private void initAudio(){
- soundPool = new SoundPool.Builder().setMaxStreams(5).build();
- sounddata = new HashMap<>();
- sounddata.put("open", soundPool.load(this, R.raw.open, 1));
- sounddata.put("close", soundPool.load(this, R.raw.close, 1));
- sounddata.put("face", soundPool.load(this, R.raw.face, 1));
- sounddata.put("finger", soundPool.load(this, R.raw.finger, 1));
- sounddata.put("ic", soundPool.load(this, R.raw.ic, 1));
- isLoaded = false;
- soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener(){
- @Override
- public void onLoadComplete(SoundPool sound,int sampleId,int status){
- if (sampleId == sounddata.size())
- isLoaded = true;
- }
- });
- }
- }
复制代码 提示:
|
|