(gambar
1)
(gambar
2)
bahan bahan yang di butuhkan
silahkan download :
activity_main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/loading"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.raihan.drum.MainActivity" >
<Button
android:id="@+id/buttonExit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btndrum"
android:layout_alignBottom="@+id/btndrum"
android:layout_alignParentRight="true"
android:layout_marginRight="50dp"
android:text="Keluar"
android:textColor="#fff" />
<Button
android:id="@+id/btndrum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="43dp"
android:layout_toLeftOf="@+id/buttonExit"
android:text="Play"
android:textColor="#fff" />
</RelativeLayout>
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/loading"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.raihan.drum.MainActivity" >
<Button
android:id="@+id/buttonExit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btndrum"
android:layout_alignBottom="@+id/btndrum"
android:layout_alignParentRight="true"
android:layout_marginRight="50dp"
android:text="Keluar"
android:textColor="#fff" />
<Button
android:id="@+id/btndrum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="43dp"
android:layout_toLeftOf="@+id/buttonExit"
android:text="Play"
android:textColor="#fff" />
</RelativeLayout>
activity_drum.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@drawable/background"
android:gravity="end"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.raihan.drum.Drum" >
<Button
android:id="@+id/kick_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="174dp"
android:background="@drawable/kick_2"
/>
<Button
android:id="@+id/kick_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/kick_2"
android:layout_alignBottom="@+id/kick_2"
android:layout_alignParentLeft="true"
android:layout_marginLeft="34dp"
android:background="@drawable/kick_1"
/>
<Button
android:id="@+id/tom_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/kick_2"
android:layout_toRightOf="@+id/kick_1"
android:background="@drawable/tom_1"
/>
<Button
android:id="@+id/tom_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/kick_1"
android:layout_toLeftOf="@+id/tom_1"
android:background="@drawable/tom_2"
/>
<Button
android:id="@+id/tom_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/snare"
android:layout_alignRight="@+id/kick_2"
android:layout_marginBottom="21dp"
android:layout_marginRight="24dp"
android:background="@drawable/tom_3"
/>
<Button
android:id="@+id/pedal_kick_kiri"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/kick_1"
android:layout_below="@+id/tom_1"
android:layout_marginRight="39dp"
android:layout_marginTop="26dp"
android:background="@drawable/pedal_kick_kiri"
/>
<Button
android:id="@+id/hit_hat_open"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/tom_3"
android:layout_toLeftOf="@+id/tom_2"
android:background="@drawable/hit_hat_open"
/>
<Button
android:id="@+id/crash_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/tom_3"
android:layout_centerHorizontal="true"
android:background="@drawable/crash_3" />
<Button
android:id="@+id/ride"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/tom_2"
android:layout_marginLeft="35dp"
android:layout_toRightOf="@+id/tom_1"
android:background="@drawable/ride"
/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/kick_1"
android:layout_alignTop="@+id/ride"
android:background="@drawable/crash_1" />
<Button
android:id="@+id/splash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/pedal_kick_kiri"
android:layout_alignParentLeft="true"
android:layout_below="@+id/crash_2"
android:layout_marginLeft="15dp"
android:background="@drawable/splash"
/>
<Button
android:id="@+id/cym"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/tom_3"
android:layout_alignBottom="@+id/tom_3"
android:layout_marginLeft="17dp"
android:layout_toRightOf="@+id/crash_3"
android:background="@drawable/cym"
/>
<Button
android:id="@+id/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/ride"
android:layout_marginLeft="20dp"
android:layout_toRightOf="@+id/cym"
android:text="Menu" />
<Button
android:id="@+id/snare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tom_2"
android:layout_marginRight="29dp"
android:layout_toLeftOf="@+id/tom_3"
android:background="@drawable/snare" />
<Button
android:id="@+id/pedal_kick_kanan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/pedal_kick_kiri"
android:layout_alignLeft="@+id/kick_2"
android:background="@drawable/pedal_kick_kanan" />
<Button
android:id="@+id/crash_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/crash_3"
android:background="@drawable/crash_2" />
</RelativeLayout>
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@drawable/background"
android:gravity="end"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.raihan.drum.Drum" >
<Button
android:id="@+id/kick_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="174dp"
android:background="@drawable/kick_2"
/>
<Button
android:id="@+id/kick_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/kick_2"
android:layout_alignBottom="@+id/kick_2"
android:layout_alignParentLeft="true"
android:layout_marginLeft="34dp"
android:background="@drawable/kick_1"
/>
<Button
android:id="@+id/tom_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/kick_2"
android:layout_toRightOf="@+id/kick_1"
android:background="@drawable/tom_1"
/>
<Button
android:id="@+id/tom_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/kick_1"
android:layout_toLeftOf="@+id/tom_1"
android:background="@drawable/tom_2"
/>
<Button
android:id="@+id/tom_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/snare"
android:layout_alignRight="@+id/kick_2"
android:layout_marginBottom="21dp"
android:layout_marginRight="24dp"
android:background="@drawable/tom_3"
/>
<Button
android:id="@+id/pedal_kick_kiri"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/kick_1"
android:layout_below="@+id/tom_1"
android:layout_marginRight="39dp"
android:layout_marginTop="26dp"
android:background="@drawable/pedal_kick_kiri"
/>
<Button
android:id="@+id/hit_hat_open"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/tom_3"
android:layout_toLeftOf="@+id/tom_2"
android:background="@drawable/hit_hat_open"
/>
<Button
android:id="@+id/crash_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/tom_3"
android:layout_centerHorizontal="true"
android:background="@drawable/crash_3" />
<Button
android:id="@+id/ride"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/tom_2"
android:layout_marginLeft="35dp"
android:layout_toRightOf="@+id/tom_1"
android:background="@drawable/ride"
/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/kick_1"
android:layout_alignTop="@+id/ride"
android:background="@drawable/crash_1" />
<Button
android:id="@+id/splash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/pedal_kick_kiri"
android:layout_alignParentLeft="true"
android:layout_below="@+id/crash_2"
android:layout_marginLeft="15dp"
android:background="@drawable/splash"
/>
<Button
android:id="@+id/cym"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/tom_3"
android:layout_alignBottom="@+id/tom_3"
android:layout_marginLeft="17dp"
android:layout_toRightOf="@+id/crash_3"
android:background="@drawable/cym"
/>
<Button
android:id="@+id/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/ride"
android:layout_marginLeft="20dp"
android:layout_toRightOf="@+id/cym"
android:text="Menu" />
<Button
android:id="@+id/snare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tom_2"
android:layout_marginRight="29dp"
android:layout_toLeftOf="@+id/tom_3"
android:background="@drawable/snare" />
<Button
android:id="@+id/pedal_kick_kanan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/pedal_kick_kiri"
android:layout_alignLeft="@+id/kick_2"
android:background="@drawable/pedal_kick_kanan" />
<Button
android:id="@+id/crash_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/crash_3"
android:background="@drawable/crash_2" />
</RelativeLayout>
mainactivity.java
package com.raihan.drum;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
Button btndrum;
MediaPlayer audioBackground;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Intent drumb = new Intent(this,Drum.class);
//Memanggil file my_sound pada folder raw
audioBackground = MediaPlayer.create(this, R.raw.my_sound);
//Set looping ke true untuk mengulang audio jika telah selesai
audioBackground.setLooping(false);
//Set volume audio agar berbunyi
audioBackground.setVolume(1,1);
//Memulai audio
audioBackground.start();
Button btn_kaluar = (Button) findViewById(R.id.buttonExit);
btn_kaluar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
close();
}
});
btndrum=(Button)findViewById(R.id.btndrum);
btndrum.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(drumb);
}
});
}
public void close(){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Apakah Anda Benar-Benar ingin keluar?")
.setCancelable(false)
.setPositiveButton("Ya",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
MainActivity.this.finish();
}
})
.setNegativeButton("Tidak",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
dialog.cancel();
}
}).show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
Button btndrum;
MediaPlayer audioBackground;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Intent drumb = new Intent(this,Drum.class);
//Memanggil file my_sound pada folder raw
audioBackground = MediaPlayer.create(this, R.raw.my_sound);
//Set looping ke true untuk mengulang audio jika telah selesai
audioBackground.setLooping(false);
//Set volume audio agar berbunyi
audioBackground.setVolume(1,1);
//Memulai audio
audioBackground.start();
Button btn_kaluar = (Button) findViewById(R.id.buttonExit);
btn_kaluar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
close();
}
});
btndrum=(Button)findViewById(R.id.btndrum);
btndrum.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(drumb);
}
});
}
public void close(){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Apakah Anda Benar-Benar ingin keluar?")
.setCancelable(false)
.setPositiveButton("Ya",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
MainActivity.this.finish();
}
})
.setNegativeButton("Tidak",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
dialog.cancel();
}
}).show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
drum.java
package com.raihan.drum;
import android.app.Activity;
import android.content.Intent;
import android.content.res.AssetFileDescriptor;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Drum extends Activity {
Button button1,crash_1,crash_2,crash_3,cwm,hi_hat_open,pedal_hit_kanan,
pedal_hit_kiri,ride,snare,splash,tom_1,tom_2,tom_3,menu;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_drum);
final Intent drumb = new Intent(this,MainActivity.class);
menu=(Button)findViewById(R.id.menu);
menu.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(drumb);
}
});
tom_3 = (Button)findViewById(R.id.tom_3);
tom_3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("tom_3.wav");
}
});
tom_2 = (Button)findViewById(R.id.tom_2);
tom_2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("tom_2.wav");
}
});
tom_1 = (Button)findViewById(R.id.tom_1);
tom_1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("tom_1.wav");
}
});
splash = (Button)findViewById(R.id.splash);
splash.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("pedal_kick_kanan.wav");
}
});
snare = (Button)findViewById(R.id.snare);
snare.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("snare.wav");
}
});
ride = (Button)findViewById(R.id.ride);
ride.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("ride.wav");
}
});
pedal_hit_kiri = (Button)findViewById(R.id.pedal_kick_kiri);
pedal_hit_kiri.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("kick.wav");
}
});
pedal_hit_kanan = (Button)findViewById(R.id.pedal_kick_kanan);
pedal_hit_kanan.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("kick.wav");
}
});
hi_hat_open = (Button)findViewById(R.id.hit_hat_open);
hi_hat_open.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("hi_hat_open.wav");
}
});
cwm = (Button)findViewById(R.id.cym);
cwm.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("cym.wav");
}
});
crash_3 = (Button)findViewById(R.id.crash_3);
crash_3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("crash_3.wav");
}
});
crash_2 = (Button)findViewById(R.id.crash_2);
crash_2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("crash_2.wav");
}
});
button1 = (Button)findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("crash_1.wav");
}
});
}
protected void playBeep(String soundfile) {
// TODO Auto-generated method stub
MediaPlayer m;
try {
m = new MediaPlayer();
// AssetManager mngr = getAssets();
if (m.isPlaying()) {
m.stop();
m.release();
m = new MediaPlayer();
}
// AssetFileDescriptor afd = getAssets().openFd(fileName);
AssetFileDescriptor descriptor = getAssets().openFd(soundfile);
m.setDataSource(descriptor.getFileDescriptor(),
descriptor.getStartOffset(), descriptor.getLength());
descriptor.close();
m.prepare();
m.setVolume(1f, 1f);
// m.setLooping(true);
m.start();
} catch (Exception e) {
// TODO: handle exception
}
}
}
import android.app.Activity;
import android.content.Intent;
import android.content.res.AssetFileDescriptor;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Drum extends Activity {
Button button1,crash_1,crash_2,crash_3,cwm,hi_hat_open,pedal_hit_kanan,
pedal_hit_kiri,ride,snare,splash,tom_1,tom_2,tom_3,menu;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_drum);
final Intent drumb = new Intent(this,MainActivity.class);
menu=(Button)findViewById(R.id.menu);
menu.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(drumb);
}
});
tom_3 = (Button)findViewById(R.id.tom_3);
tom_3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("tom_3.wav");
}
});
tom_2 = (Button)findViewById(R.id.tom_2);
tom_2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("tom_2.wav");
}
});
tom_1 = (Button)findViewById(R.id.tom_1);
tom_1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("tom_1.wav");
}
});
splash = (Button)findViewById(R.id.splash);
splash.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("pedal_kick_kanan.wav");
}
});
snare = (Button)findViewById(R.id.snare);
snare.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("snare.wav");
}
});
ride = (Button)findViewById(R.id.ride);
ride.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("ride.wav");
}
});
pedal_hit_kiri = (Button)findViewById(R.id.pedal_kick_kiri);
pedal_hit_kiri.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("kick.wav");
}
});
pedal_hit_kanan = (Button)findViewById(R.id.pedal_kick_kanan);
pedal_hit_kanan.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("kick.wav");
}
});
hi_hat_open = (Button)findViewById(R.id.hit_hat_open);
hi_hat_open.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("hi_hat_open.wav");
}
});
cwm = (Button)findViewById(R.id.cym);
cwm.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("cym.wav");
}
});
crash_3 = (Button)findViewById(R.id.crash_3);
crash_3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("crash_3.wav");
}
});
crash_2 = (Button)findViewById(R.id.crash_2);
crash_2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("crash_2.wav");
}
});
button1 = (Button)findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
playBeep("crash_1.wav");
}
});
}
protected void playBeep(String soundfile) {
// TODO Auto-generated method stub
MediaPlayer m;
try {
m = new MediaPlayer();
// AssetManager mngr = getAssets();
if (m.isPlaying()) {
m.stop();
m.release();
m = new MediaPlayer();
}
// AssetFileDescriptor afd = getAssets().openFd(fileName);
AssetFileDescriptor descriptor = getAssets().openFd(soundfile);
m.setDataSource(descriptor.getFileDescriptor(),
descriptor.getStartOffset(), descriptor.getLength());
descriptor.close();
m.prepare();
m.setVolume(1f, 1f);
// m.setLooping(true);
m.start();
} catch (Exception e) {
// TODO: handle exception
}
}
}
Atau download file projectnya di
sini
catatan :
apl yg digunakan :
min : apl 18
target : apl 18
max : apl 18
resolusi layar = 720 * 1280 xhdpi
0 Response to "Membuat aplikasi Drum android menggunakan eclips atau android studio"
Post a Comment