How do I make shuffle playlist button and repeat button in android studio

Zetsube

I dont know how to convert this code to android studio i am stuck on it for 2 days and cant figure it out Plz help me

btnRepeat.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            if(isRepeat){
                isRepeat = false;
                Toast.makeText(getApplicationContext(), "Repeat is OFF", Toast.LENGTH_SHORT).show();
                btnRepeat.setImageResource(R.drawable.btn_repeat);
            }else{
                // make repeat to true
                isRepeat = true;
                Toast.makeText(getApplicationContext(), "Repeat is ON", Toast.LENGTH_SHORT).show();
                // make shuffle to false
                isShuffle = false;
                btnRepeat.setImageResource(R.drawable.btn_repeat_focused);
                btnShuffle.setImageResource(R.drawable.btn_shuffle);
            }
        }
    });

and another one

btnShuffle.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            if(isShuffle){
                isShuffle = false;
                Toast.makeText(getApplicationContext(), "Shuffle is OFF", Toast.LENGTH_SHORT).show();
                btnShuffle.setImageResource(R.drawable.btn_shuffle);
            }else{
                // make repeat to true
                isShuffle= true;
                Toast.makeText(getApplicationContext(), "Shuffle is ON", Toast.LENGTH_SHORT).show();
                // make shuffle to false
                isRepeat = false;
                btnShuffle.setImageResource(R.drawable.btn_shuffle_focused);
                btnRepeat.setImageResource(R.drawable.btn_repeat);
            }
        }
    });

this is last pice of code

@Override public void onCompletion(MediaPlayer arg0) {

    // check for repeat is ON or OFF
    if(isRepeat){
        // repeat is on play same song again
        playSong(currentSongIndex);
    } else if(isShuffle){
        // shuffle is on - play a random song
        Random rand = new Random();
        currentSongIndex = rand.nextInt((songsList.size() - 1) - 0 + 1) + 0;
        playSong(currentSongIndex);
    } else{
        // no repeat or shuffle ON - play next song
        if(currentSongIndex < (songsList.size() - 1)){
            playSong(currentSongIndex + 1);
            currentSongIndex = currentSongIndex + 1;
        }else{
            // play first song
            playSong(0);
            currentSongIndex = 0;
        }
    }
}
Peter P

You should use something like a toggle button! Instead of a normal button so you don't have to care what is switched on and off! Here the JavaDoc:

http://developer.android.com/reference/android/widget/ToggleButton.html

And this link contains a nice tutorial on how to use it within your code:

http://www.mkyong.com/android/android-togglebutton-example/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

VLC: how to shuffle playlist? The button is not there

From Dev

How do i make 1 button play random sounds each time i press the button using android studio

From Dev

Android - How do I make the button taller in a linear layout?

From Dev

How do I make a google plus button with a custom layout in android?

From Dev

How do I play sound on button click in android studio?

From Dev

How do i Make a load more button

From Dev

How do I make a button stay pressed?

From Dev

How do i Make a load more button

From Dev

How do i make a button activate JavaScript?

From Dev

How do I make a JQuery close a button?

From Dev

How do I make floating button clickable

From Dev

How do i make and attache action to button

From Dev

How do I show text and a button? (android)

From Dev

How do I change the button to text on clicking the button which is inside ng-repeat?

From Dev

Android Studio Java: How to make a button break a while loop

From Dev

How do i make next page button in android (click to go next fragment)

From Dev

How do I change my button's Text after it is pressed in android studio?

From Dev

How do I change my button's Text after it is pressed in android studio?

From Dev

Android studio Bottom navigation bar: How do I set the middle button to be clicked first?

From Dev

Android shuffle button position onClick

From Dev

How to make an android raised button?

From Dev

How to make button like this in Android?

From Dev

how do I make selectable or not selectable a kendo grid by a button

From Dev

In Oracle APEX, how do I make my button delete a row?

From Dev

How do I make a play button for my full page video?

From Dev

How do I make a button in a custom NSView change color on mouseover?

From Dev

How do I make a NSWindow popup when a button is pressed

From Dev

How do I make rounded button-group in Foundation 6?

From Dev

How do I make a textfield editable for 10 seconds on the click of a button?

Related Related

  1. 1

    VLC: how to shuffle playlist? The button is not there

  2. 2

    How do i make 1 button play random sounds each time i press the button using android studio

  3. 3

    Android - How do I make the button taller in a linear layout?

  4. 4

    How do I make a google plus button with a custom layout in android?

  5. 5

    How do I play sound on button click in android studio?

  6. 6

    How do i Make a load more button

  7. 7

    How do I make a button stay pressed?

  8. 8

    How do i Make a load more button

  9. 9

    How do i make a button activate JavaScript?

  10. 10

    How do I make a JQuery close a button?

  11. 11

    How do I make floating button clickable

  12. 12

    How do i make and attache action to button

  13. 13

    How do I show text and a button? (android)

  14. 14

    How do I change the button to text on clicking the button which is inside ng-repeat?

  15. 15

    Android Studio Java: How to make a button break a while loop

  16. 16

    How do i make next page button in android (click to go next fragment)

  17. 17

    How do I change my button's Text after it is pressed in android studio?

  18. 18

    How do I change my button's Text after it is pressed in android studio?

  19. 19

    Android studio Bottom navigation bar: How do I set the middle button to be clicked first?

  20. 20

    Android shuffle button position onClick

  21. 21

    How to make an android raised button?

  22. 22

    How to make button like this in Android?

  23. 23

    how do I make selectable or not selectable a kendo grid by a button

  24. 24

    In Oracle APEX, how do I make my button delete a row?

  25. 25

    How do I make a play button for my full page video?

  26. 26

    How do I make a button in a custom NSView change color on mouseover?

  27. 27

    How do I make a NSWindow popup when a button is pressed

  28. 28

    How do I make rounded button-group in Foundation 6?

  29. 29

    How do I make a textfield editable for 10 seconds on the click of a button?

HotTag

Archive