Mobil Programlama - Media Player
activitymain.xml
MainActivity.java
<LinearLayout 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="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.android.mediaplayer.MainActivity">
<Button
android:id="@+id/baslatbutonu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Play" />
<Button
android:id="@+id/durdurButonu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pause" />
<Button
android:id="@+id/artises"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+" />
<Button
android:id="@+id/eksises"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>
MainActivity.java
private MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button baslat=(Button) findViewById(R.id.baslatbutonu);
Button durdur=(Button) findViewById(R.id.durdurButonu);
mp=MediaPlayer.create(this,R.raw.sarki);
baslat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "Müzik Çalınıyor",Toast.LENGTH_SHORT).show();
mp.start();
}
});
durdur.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mp.stop();
}
});
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
Toast.makeText(getApplicationContext(), "Müzik Bitti! :(",Toast.LENGTH_SHORT).show();
}
});
}
Yorumlar
Yorum Gönder