0

enter image description hereOBJECTIVE: to play animals sounds of cows and pigs

  1. The opening screen displays an img of a farm and the title, animal voices for six seconds

  2. second screen will display img on a cow and a pig with their respective play buttons under them.

  3. When one button is pressed, the other button and image disappear and vice versa.

  4. when a button is pressed, their respective sounds will be played

    package net.androidbootcamp.animalvoices;
    
    import android.media.MediaPlayer;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    
    public class MainActivity extends AppCompatActivity {
        Button btnCow, btnPig;
        MediaPlayer mpPig, mpCow;
        int playing;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            btnPig = (Button)findViewById(R.id.btnPig);
            btnCow = (Button)findViewById(R.id.btnCow);
            btnPig.setOnClickListener(bPig);
            btnCow.setOnClickListener(bCow);
            mpPig = new MediaPlayer();
            mpPig = MediaPlayer.create(this, R.raw.pigs);
            mpCow = new MediaPlayer();
            mpCow = MediaPlayer.create(this, R.raw.cows);
            playing = 0;
        }
        Button.OnClickListener bPig = new Button.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (playing) {
                    case 0:
                        mpPig.start();
                        playing = 1;
                        btnCow.setText("Pause the Cows");
                        btnPig.setVisibility(View.INVISIBLE);
                        break;
                    case 1:
                        mpPig.pause();
                        playing = 0;
                        btnCow.setText("Listen to the Cows");
                        btnPig.setVisibility(View.VISIBLE);
                        break;
                }
            }
        };
        Button.OnClickListener bCow = new Button.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (playing) {
                    case 0:
                        mpCow.start();
                        playing = 1;
                        btnCow.setText("Pause the Pigs");
                        btnPig.setVisibility(View.INVISIBLE);
                        break;
                    case 1:
                        mpCow.pause();
                        playing = 1;
                        btnCow.setText("Listen to the Pigs");
                        btnPig.setVisibility(View.VISIBLE);
                }
            }
        };
    }
    
  • Please include the error message to help us help you – Wildan Maulana Syahidillah Oct 14 '16 at 01:36
  • Please put snapshot of your raw folder . I want to check if you properly insert your file or not . – Gevaria Purva Oct 14 '16 at 03:54
  • Gevaria Purva, how do i add a screenshot? also, Wildan Maulana Syahidillah, here is error message: – Cha Hernandez Oct 17 '16 at 21:27
  • 5:10:44 PM Executing tasks: [:app:clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:assembleDebug] 5:13:51 PM Gradle build finished with 1 error(s) in 2m 58s 209ms 5:15:28 PM Can't bind to local 8609 for debugger – Cha Hernandez Oct 17 '16 at 21:27

0 Answers0