Saturday, 23 September 2017

Play Song

step 1;

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    
android:orientation="vertical" 
android:layout_width="match_parent"    
android:layout_height="match_parent"    
android:gravity="center">
<Button    
android:id="@+id/play"    
android:layout_width="100dp"    
android:layout_height="100dp"    
android:background="@drawable/image"/>
</LinearLayout>
step 2:

MainActivity.java
public class MainActivity extends AppCompatActivity {

    MediaPlayer mPlayer;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button = (Button)findViewById(R.id.play);
     button.setOnClickListener(new View.OnClickListener() {
         @Override         
public void onClick(View v) {
             if (mPlayer != null) {
                 mPlayer.stop();
                 mPlayer.reset();
             }

             mPlayer = MediaPlayer.create(MainActivity.this, R.raw.song);
             mPlayer.start();
         }

     });

    }}

step 3:

res/raw/song.mp3>>>>>>> user song

step 4:

res/drawable/image.pnd>>>>>> user image

No comments:

Post a Comment

HOW TO CREATE CIRCLE IMAGE VIEW

Step 1: implementation 'de.hdodenhof:circleimageview:3.0.0' Step 2: <de.hdodenhof.circleimageview.CircleImageView xmlns:ap...