vendredi 30 octobre 2015

Can't pass an int from button if / else case to media player

how are you supposed to let the mediaplayer know what it is supposed to play?

wholeTextPlayer = MediaPlayer.create(Lesson1Reading.this, engAu);

It works fine if I declare the file in the top:

MediaPlayer wholeTextPlayer;
private int engAu = R.raw.l1r_en_l10;
Button btn_default_acc_whole;

It doesn't work from within a button click if / else statement wherever I try to put it with the following combination:

MediaPlayer wholeTextPlayer;
private int engAu;
Button btn_default_acc_whole;

The button click:

final Button btn_default_acc_whole = (Button) findViewById(R.id.btn_default_acc_whole);
    btn_default_acc_whole.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
            if (wholeTextPlayer.isPlaying()) {
                wholeTextPlayer.pause();

            } else {
                wholeTextPlayer.start();
                startPlayProgressUpdater();
            }
            setEngAu(R.raw.l1r_en_l10); //this line doesn't want to fit anywhere
        }
    });

The setter:

public void setEngAu(int engAu) {
        this.engAu = engAu;
    }

Of course they are separately placed in the activity, I just copied and pasted the relevant bits from it.

Thanks guys.

Aucun commentaire:

Enregistrer un commentaire