Firefly开源社区

标题: AIO3128播放声音出现问题 [打印本页]

作者: 萤火虫    时间: 2018-12-28 14:19
标题: AIO3128播放声音出现问题
声音时有时无,包括系统提示音和音乐。,外接USB声卡播放正常。
不管是外接声卡还是直接使用板载的音频接口都会出现使用soundpool 出现AUDIO_OUTPUT_FLAG_FAST denied by client警告的问题。
请问该如何解决?

测试代码:

  1. package com.haijie.test;

  2. import android.content.Context;
  3. import android.media.AudioManager;
  4. import android.media.SoundPool;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import java.util.HashMap;

  10. public class MainActivity extends AppCompatActivity {

  11.     //audio
  12.     public static SoundPool soundPool;
  13.     public static HashMap<String, Integer> sounddata;
  14.     public static Boolean isLoaded;
  15.     private static int streamID = -1;

  16.     public static void playSound(Context context, String sound, int number) {
  17.         AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
  18.         float audioMaxVolumn = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
  19.         float volumnCurrent = am.getStreamVolume(AudioManager.STREAM_MUSIC);
  20.         float volumnRatio = volumnCurrent / audioMaxVolumn;

  21.         streamID = soundPool.play(sounddata.get(sound),
  22.                 volumnRatio,// 左声道音量
  23.                 volumnRatio,// 右声道音量
  24.                 1, // 优先级
  25.                 number,// 循环播放次数
  26.                 1);// 回放速度,该值在0.5-2.0之间 1为正常速度
  27.     }

  28.     public static void stopSound(){
  29.         soundPool.stop(streamID);
  30.     }

  31.     @Override
  32.     protected void onCreate(Bundle savedInstanceState) {
  33.         super.onCreate(savedInstanceState);
  34.         setContentView(R.layout.activity_main);

  35.         initAudio();

  36.         Button button = findViewById(R.id.button);
  37.         button.setOnClickListener(new Button.OnClickListener(){
  38.             @Override
  39.             public void onClick(View v) {
  40.                 if (isLoaded){
  41.                     if (streamID != -1){
  42.                         stopSound();
  43.                     }
  44.                     playSound(MainActivity.this,"finger",0);
  45.                 }
  46.             }
  47.         });
  48.     }

  49.     private void initAudio(){
  50.         soundPool = new SoundPool.Builder().setMaxStreams(5).build();
  51.         sounddata = new HashMap<>();
  52.         sounddata.put("open", soundPool.load(this, R.raw.open, 1));
  53.         sounddata.put("close", soundPool.load(this, R.raw.close, 1));
  54.         sounddata.put("face", soundPool.load(this, R.raw.face, 1));
  55.         sounddata.put("finger", soundPool.load(this, R.raw.finger, 1));
  56.         sounddata.put("ic", soundPool.load(this, R.raw.ic, 1));
  57.         isLoaded = false;
  58.         soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener(){
  59.             @Override
  60.             public void onLoadComplete(SoundPool sound,int sampleId,int status){
  61.                 if (sampleId == sounddata.size())
  62.                     isLoaded = true;
  63.             }
  64.         });
  65.     }

  66. }
复制代码
提示:





作者: 萤火虫    时间: 2018-12-28 15:32
有木有大佬解决下啊?
作者: 萤火虫    时间: 2018-12-28 15:47

有木有大佬解决下啊?
作者: 萤火虫    时间: 2018-12-28 16:10
有木有大佬解决下啊?
作者: 萤火虫    时间: 2018-12-28 17:21
有木有大佬解决下啊?
作者: wx_Mr.Lee_g8Ao8    时间: 2018-12-29 09:58
萤火虫 发表于 2018-12-28 17:21
有木有大佬解决下啊?
声音时有时无,包括系统提示音和音乐。

说明一下操作步骤
作者: wx_Mr.Lee_g8Ao8    时间: 2018-12-29 10:11
wx_Mr.Lee_g8Ao8 发表于 2018-12-29 09:58
说明一下操作步骤

还有是用耳机还是喇叭
作者: wx_Mr.Lee_g8Ao8    时间: 2018-12-29 10:20
现在官网SDK有更新,可以更新源码再试试
作者: 萤火虫    时间: 2018-12-29 10:53
wx_Mr.Lee_g8Ao8 发表于 2018-12-29 09:58
说明一下操作步骤

就是直接播放MP3格式的文件,放着放着突然没有声音了就。触摸时的提示音也有的时候有,有的时候没有。
作者: wx_Mr.Lee_g8Ao8    时间: 2018-12-29 10:58
萤火虫 发表于 2018-12-29 10:53
就是直接播放MP3格式的文件,放着放着突然没有声音了就。触摸时的提示音也有的时候有,有的时候没有。

更新最新源码
作者: 萤火虫    时间: 2018-12-29 11:15
wx_Mr.Lee_g8Ao8 发表于 2018-12-29 10:11
还有是用耳机还是喇叭

都试了,效果一样。插USB声卡的话播放声音正常,但是APP使用soundpool还是会出现提示
作者: 萤火虫    时间: 2018-12-29 11:19
wx_Mr.Lee_g8Ao8 发表于 2018-12-29 10:58
更新最新源码

就是最新的固件,官方百度云的那个
作者: wx_Mr.Lee_g8Ao8    时间: 2018-12-29 11:20
萤火虫 发表于 2018-12-29 11:15
都试了,效果一样。插USB声卡的话播放声音正常,但是APP使用soundpool还是会出现提示

系统声音和音乐播放还有没有问题?至于你APP调用soundpool问题就要看你调用的是不是对的
作者: 萤火虫    时间: 2018-12-29 11:22
wx_Mr.Lee_g8Ao8 发表于 2018-12-29 10:20
现在官网SDK有更新,可以更新源码再试试

用的是官网的最新固件,八月份的那个。
作者: wx_Mr.Lee_g8Ao8    时间: 2018-12-29 11:22
萤火虫 发表于 2018-12-29 11:19
就是最新的固件,官方百度云的那个

你没有SDK源码?
作者: 萤火虫    时间: 2018-12-29 11:27
wx_Mr.Lee_g8Ao8 发表于 2018-12-29 11:22
你没有SDK源码?

我这边没有办法编译SDK。。。而且我看官网百度云上的SDK是5月份的?
作者: 萤火虫    时间: 2018-12-29 11:30
wx_Mr.Lee_g8Ao8 发表于 2018-12-29 11:20
系统声音和音乐播放还有没有问题?至于你APP调用soundpool问题就要看你调用的是不是对的

有问题的,不接外部声卡就播放不了。
还有,能帮忙看一下上面贴的DEMO中的调用方法是不是正确吗?
作者: wx_Mr.Lee_g8Ao8    时间: 2018-12-29 11:31
萤火虫 发表于 2018-12-29 11:27
我这边没有办法编译SDK。。。而且我看官网百度云上的SDK是5月份的?

需要更新啊,http://wiki.t-firefly.com/zh_CN/AIO-3128C/compile_Android_firmware.html

作者: 萤火虫    时间: 2018-12-29 11:38
wx_Mr.Lee_g8Ao8 发表于 2018-12-29 11:31
需要更新啊,http://wiki.t-firefly.com/zh_CN/AIO-3128C/compile_Android_firmware.html,

是不是硬件故障啊?有没有出厂固件?我刷回出厂固件试一下,刚买来的时候没事有声音问题,还有,断电会导致安卓系统启动不起来吗?
作者: wx_Mr.Lee_g8Ao8    时间: 2018-12-29 11:51
萤火虫 发表于 2018-12-29 11:38
是不是硬件故障啊?有没有出厂固件?我刷回出厂固件试一下,刚买来的时候没事有声音问题,还有,断电会导 ...

下载固件试试:链接:https://pan.baidu.com/s/1DmqqmbjEn28qOueMtoBBiw
提取码:zr29
一个一个问题解决,先弄清楚声音问题。

正常情况断电不会导致系统起不来,抓log
作者: wx_Mr.Lee_g8Ao8    时间: 2018-12-29 14:36
wx_Mr.Lee_g8Ao8 发表于 2018-12-29 11:51
下载固件试试:链接:https://pan.baidu.com/s/1DmqqmbjEn28qOueMtoBBiw
提取码:zr29
一个一个问题 ...

不好意思链接发错,
请按照以下链接下载:
链接:https://pan.baidu.com/s/17UEeNeydaEPh0CqlLZ2n7Q
提取码:2646

作者: 萤火虫    时间: 2018-12-29 15:10
wx_Mr.Lee_g8Ao8 发表于 2018-12-29 11:51
下载固件试试:链接:https://pan.baidu.com/s/1DmqqmbjEn28qOueMtoBBiw
提取码:zr29
一个一个问题 ...

好的 ,我试试,辛苦了,谢谢!
作者: 萤火虫    时间: 2018-12-31 09:27
wx_Mr.Lee_g8Ao8 发表于 2018-12-29 14:36
不好意思链接发错,
请按照以下链接下载:
链接:https://pan.baidu.com/s/17UEeNeydaEPh0CqlLZ2n7Q

声音播放还是有问题,看现象可能是系统把音频设备休眠了。第一次播放声音前几秒会卡掉或者被刺啦声代替。播放出声音来之后再继续播放其他声音不会出现这个问题。不播放声音后几秒钟可能是自动休眠音频设备了,音响会轻微的噗一声响。然后再重新播放声音的时候就又会出现卡掉开头的问题了。
作者: 萤火虫    时间: 2019-1-2 11:42
wx_Mr.Lee_g8Ao8 发表于 2018-12-29 14:36
不好意思链接发错,
请按照以下链接下载:
链接:https://pan.baidu.com/s/17UEeNeydaEPh0CqlLZ2n7Q

能不能把音频设备休眠的这个去掉?我猜测去掉就没问题了
作者: 萤火虫    时间: 2019-1-5 15:22
wx_Mr.Lee_g8Ao8 发表于 2018-12-29 14:36
不好意思链接发错,
请按照以下链接下载:
链接:https://pan.baidu.com/s/17UEeNeydaEPh0CqlLZ2n7Q

在吗?
作者: 萤火虫    时间: 2019-1-9 09:19
大佬,在不?




欢迎光临 Firefly开源社区 (https://dev.t-firefly.com/) Powered by Discuz! X3.1