I follow a series of lectures on Android programming that has been developed in the pre-API 21 times. Therefore, he tells me that I am creating the SoundPool variable as follows.
SoundPool sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0); //SoundPool(int maxStreams, int streamType, int srcQuality)
However, I want to use this SoundPool for API 21. So, I do 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 is a variable of type Builder for API 21 and sp is of type SoundPool .
This works very well with my AVD having API 21 and a real device having API 19. (I didnβt try to work with a real device with API 21, but I think it will work well). Now I want to set streamType to USAGE_MEDIA in the if block before sp = sp21.build(); . Therefore, I type:
sp21.setAudioAttributes(AudioAttributes.USAGE_MEDIA);
But Lint marks it in red and says:
The setAudioAttributes (AudioAttributes) method in type SoundPool.Builder is not applicable for arguments (int)
I know that even if I do not set it to USAGE_MEDIA, it will be installed by default. But I ask for a future link if I need to set it to something else: USAGE_ALARM.
How should I proceed?
Please, help!
I mentioned Audio Attributes , SoundPool , SoundPool.builder and AudioManager .