集音频属性在SoundPool.Builder类API 21 [英] set Audio Attributes in SoundPool.Builder class for API 21

查看:2709
本文介绍了集音频属性在SoundPool.Builder类API 21的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面一个Android编程视频系列讲座,这是设计了pre-API 21倍英寸因此它告诉我以下面的方式创建的Soundpool变量

I am following an Android Programming video lecture series which was designed in the pre-API 21 times. Hence it tells me to create a SoundPool variable in the following manner.

SoundPool sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
//SoundPool(int maxStreams, int streamType, int srcQuality)

不过,我想用这个的Soundpool为API 21为好。所以,我这样做:

However, I want to use this SoundPool for API 21 as well. So, I am doing this:

if((android.os.Build.VERSION.SDK_INT) == 21){
    sp21 = new SoundPool.Builder();
    sp21.setMaxStreams(5);
    sp = sp21.build();
}
else{
    sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
}

SP21是生成器的变量键入API 21和SP是的Soundpool 键入

sp21 is a variable of Builder type for API 21 and sp is of SoundPool type.

这工作得非常好与具有21 API并具有API 19.真正的设备我的AVD(有没有用API 21一个真正的设备尝试,但我认为这将很好地工作)。现在,我想设置流类型 USAGE_MEDIA 中,如果块之前 SP = sp21.build(); 。所以,I型:

This works very well with my AVD having API 21 and real device having API 19. (Haven't tried with a real device with API 21 but I think it will work well). Now, I want to set the streamType to USAGE_MEDIA in the if-block before sp = sp21.build();. So I type:

sp21.setAudioAttributes(AudioAttributes.USAGE_MEDIA);

但皮棉其标记为红色,并说:

But the Lint marks it in red and says:

在类型的方法setAudioAttributes(AudioAttributes)
  SoundPool.Builder不适用的参数(int)的

The method setAudioAttributes(AudioAttributes) in the type SoundPool.Builder is not applicable for the arguments (int)

我知道,即使我不将它设置为USAGE_MEDIA它将被设置为默认情况下是相同的。但我要求以供将来参考,如果我必须将它设置为别的东西,如:。USAGE_ALARM

I know that even if I do not set it to USAGE_MEDIA it will be set to the same by default. But I am asking for future reference if I have to set it to something else like : USAGE_ALARM.

我该如何操作?

请帮助!

我已经提到音频属性,的的Soundpool ,的 SoundPool.builder 和的 AudioManager

I have referred to Audio Attributes, SoundPool, SoundPool.builder and AudioManager.

推荐答案

这是AudioAttributes实例通过它的建造者建造,AudioAttributes.Builder。

An AudioAttributes instance is built through its builder, AudioAttributes.Builder.

可以通过以下方式使用它。

You can use it in the following way.

sp21.setAudioAttributes(new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_MEDIA)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.build());

参考: https://developer.android.com/reference/android/媒体/ AudioAttributes.html

这篇关于集音频属性在SoundPool.Builder类API 21的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆