1. app > res >raw நீங்கள் Play செய்ய விரும்பிய படலை Copy path தில் paste செய்து கீழ் உள்ள படி முறைகளை பின்பற்றுங்கள்.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView"
android:layout_width="414dp"
android:layout_height="229dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/logo" />
<Button
android:id="@+id/play_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="48dp"
android:text="Play"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView" />
<Button
android:id="@+id/pause_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stop"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/play_button"
app:srcCompat="@android:drawable/ic_media_pause" />
</androidx.constraintlayout.widget.ConstraintLayout>
3.app > java > your(package) > MainActivity க்கு சென்று கீழே தரப்பட்டுள்ள Code ஐ உள்ளீடு செய்யுங்கள்.
package mit.solution.apps;
import androidx.appcompat.app.AppCompatActivity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button play_btn,pause_btn;
MediaPlayer mediaPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
play_btn = findViewById(R.id.play_button);
pause_btn = findViewById(R.id.pause_button);
mediaPlayer = MediaPlayer.create(this, R.raw.music);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
play_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!mediaPlayer.isPlaying())
mediaPlayer.start();
}
});
pause_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mediaPlayer.isPlaying()) {
mediaPlayer.pause();
}
}
});
}
}
கருத்துரையிடுக