0

I have one button. On a long click I want the user to be prompted to assign a song. On a normal click I want the song to play, and if the song is already playing I want it to reset. I have some toasting action going on to help keep things clear to the user. I need another button to pause.

    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.media.MediaPlayer;
    import android.view.View;
    import android.widget.Toast;
    import java.io.IOException;


    public class MainActivity extends AppCompatActivity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }
        public void button_one(View v) {

            try {
                Toast myToast = Toast.makeText(
                        getApplicationContext(),
                        "playing",
                        Toast.LENGTH_LONG);
                //MediaPlayer should Reset
                //MediaPlayer should Play
                myToast.show();

            }catch //something needs to go here to catch all errors
                {
                Toast myToast = Toast.makeText(
                        getApplicationContext(),
                        "add a song first",
                        Toast.LENGTH_LONG);
                myToast.show();

            }

        }
    }
Bryan
  • 13
  • 4

1 Answers1

0

I'm not sure what the question here is.

Do you want to know how to make handlers for a button on a long and normal click? Do you want to know how to play/pause music. Or something else?

For the first case I may have an answer:

Button b = (Button) findViewById(R.id.btnStartMusic);
    b.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            //Assign a song code here
            return false;
        }
    });
    b.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //Play song code here
        }
    });
Dennis van Opstal
  • 1,294
  • 1
  • 22
  • 44
  • I want to know how to handle a button for a normal click and long click. I'll create a different post for the play/pause music later. I'm getting an error "Cannot resolve symbol 'setOnLongClickListener.'" – Bryan Mar 04 '16 at 19:50
  • I resolved the symbol error by following: http://stackoverflow.com/a/19223269/5994686 – Bryan Mar 04 '16 at 23:13
  • I was placing the code in the wrong spot. Thanks. I resolved this issue by reading http://stackoverflow.com/a/28697341/5994686 – Bryan Mar 05 '16 at 02:34