XML : I am trying to customize the sound that plays using radio buttons

I am trying to set three radio buttons to three different sounds in a preference screen. I have created the radio buttons, and have referenced them as booleans in the main activity. The program is supposed to display a animation on button click, and on that same button click play the sound that you have picked with the radio buttons to play. I am not sure why it's not working. The animation and everything works, but when I add in the radio buttons it stops working. Here is my MainActivity

  public void buttonClick() {      imgView = (ImageView) findViewById(R.id.imageView);      button = (Button) findViewById(R.id.button);      blade = (ImageView)findViewById(R.id.imageView4);      final Animation animRotate = AnimationUtils.loadAnimation(this, R.anim.rotate);      standardSound = MediaPlayer.create(this, R.raw.fanpost);      alternateSound = MediaPlayer.create(this, R.raw.alternate_fan);      whiteSound = MediaPlayer.create(this, R.raw.white_noise);        button.setOnClickListener(                new View.OnClickListener() {                    @Override                  public void onClick(View v) {                      SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());                      boolean alternate = getPrefs.getBoolean("alternate", false);                      boolean white = getPrefs.getBoolean("white", false);                      boolean standard = getPrefs.getBoolean("standard",false);                        if (blade.getAnimation() == null) {                          // no animation, start it                          if (alternate = true){                              alternateSound.start();                              blade.startAnimation(animRotate);                            } else if (white){                              whiteSound.start();                              blade.startAnimation(animRotate);                            }                          else if (standard){                              standardSound.start();                              blade.startAnimation(animRotate);                            }                        } else {                          //animation is showing, stop it                          blade.clearAnimation();                          standardSound.stop();                          standardSound.prepareAsync();                          whiteSound.stop();                          whiteSound.prepareAsync();                          alternateSound.stop();                          alternateSound.prepareAsync();    

Prefs.xml...

  <PreferenceCategory      android:title="Sound Settings">      <ListPreference          android:entries="@array/soundEntries"            android:entryValues="@array/soundValues"          android:key="soundPref"          android:title="Sound Settings"/>  </PreferenceCategory>    

Array

  <resources>      <string-array name="soundEntries">          <item>StandardFan</item>          <item>AlternateFan</item>          <item>WhiteNoise</item>      </string-array>          <string-array name="soundValues">          <item>Standard is selected</item>          <item>Alternate is selected</item>          <item>White is selected</item>      </string-array>  </resources>    

If anyone knows why this isn't working please let me know thanks.

No comments:

Post a Comment