Настройка громкости звука Soundpool

Не знаю как сделать так чтобы пользователь менял звук в моем приложении с помощью боковых кнопок громкости на телефоне.Помогите пожалуйста)) вот код:

public class BlankFragment5 extends Fragment {
    private int sound, sound1, sound2, sound3, sound4;
    private SoundPool soundPool;




    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_blank_fragment5, container, false);



        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);
        }


        sound = soundPool.load(getActivity(), R.raw.belkaaa,1);
        sound1 = soundPool.load(getActivity(), R.raw.zauacc,1);
        sound2 = soundPool.load(getActivity(), R.raw.mausse,1);
        sound3 = soundPool.load(getActivity(), R.raw.nutriia,1);
        sound4 = soundPool.load(getActivity(), R.raw.dikobrazz,1);


        ImageButton imageButton = (ImageButton) view.findViewById(R.id.imageButton);


        imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            /*  if (sound1 != null) {
                    sound1.stop();
                }
                if (sound2 != null) {
                    sound2.stop();
                }
                if (sound3 != null) {
                    sound3.stop();
                }
                if (sound4 != null) {
                    sound4.stop();
                }*/

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

            }
        });

        ImageButton imageButton2 = (ImageButton) view.findViewById(R.id.imageButton2);

        imageButton2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


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


            }
        });

        ImageButton imageButton3 = (ImageButton) view.findViewById(R.id.imageButton3);


        imageButton3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

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


            }
        });

        ImageButton imageButton4 = (ImageButton) view.findViewById(R.id.imageButton4);


        imageButton4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

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

            }
        });

        ImageButton imageButton5 = (ImageButton) view.findViewById(R.id.imageButton5);


        imageButton5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

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


            }
        });



        return view;
    }

    public void onCreate (Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setRetainInstance(true);

    }




    @Override
    public   void onDestroy(){
        super.onDestroy();
        soundPool.release();
        soundPool = null;
    }



}

Ответы (0 шт):