DRUM PAD TUTORIAL (ANDROID STUDIO)
. DRUM PAD TUTORIAL (ANDROID STUDIO)
MANIFEST FILE :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="drumpad.deekshithrajbasa.com.solodrumpad">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</application>
</manifest>
XML FILE :
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:onClick="sound1"
android:background="#3498db"
android:layout_width="100dp"
android:layout_height="100dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"/>
<Button
android:onClick="sound2"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:background="#2980b9"
android:layout_width="100dp"
android:layout_height="100dp" />
<Button
android:onClick="sound3"
android:background="#1abc9c"
android:layout_width="100dp"
android:layout_height="100dp" />
</LinearLayout>
<LinearLayout
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:onClick="sound4"
android:background="#9b59b6"
android:layout_width="100dp"
android:layout_height="100dp" />
<Button
android:onClick="sound5"
android:background="#2c3e50"
android:layout_width="100dp"
android:layout_height="100dp" />
<Button
android:onClick="sound6"
android:background="#e74c3c"
android:layout_width="100dp"
android:layout_height="100dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:onClick="sound7"
android:background="#ecf0f1"
android:layout_width="100dp"
android:layout_height="100dp" />
<Button
android:onClick="sound8"
android:background="#1abc9c"
android:layout_width="100dp"
android:layout_height="100dp" />
<Button
android:onClick="sound9"
android:background="#f1c40f"
android:layout_width="100dp"
android:layout_height="100dp" />
</LinearLayout>
</LinearLayout>
Tutorial Video
JAVA FILE :
import android.media.AudioManager;
import android.media.SoundPool;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
// created by deekshith raj basa on 29/01/2018
public class MainActivity extends AppCompatActivity {
private SoundPool sp;
private int sound1;
private int sound2;
private int sound3;
private int sound4;
private int sound5;private int sound6;private int sound7 ;private int sound8;private int sound9;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sp = new SoundPool(2, AudioManager.STREAM_MUSIC,0);
sound1 = sp.load(getApplicationContext(),R.raw.sounda,1);
sound2 = sp.load(getApplicationContext(),R.raw.soundb,1);
sound3 = sp.load(getApplicationContext(),R.raw.soundc,1);
sound4 = sp.load(getApplicationContext(),R.raw.soundd,1);
sound5 = sp.load(getApplicationContext(),R.raw.sounde,1);
sound6 = sp.load(getApplicationContext(),R.raw.soundf,1);
sound7 = sp.load(getApplicationContext(),R.raw.soundg,1);
sound8 = sp.load(getApplicationContext(),R.raw.soundh,1);
sound9 = sp.load(getApplicationContext(),R.raw.soundi,1);
//sound00 = sp.load(getApplicationContext(),R.raw.sound00,1);
}
public void sound1 (View v) {
sp.play(sound1,1.0f,1.0f,0,0,10f);
}
public void sound2 (View v) {
sp.play(sound2,1.0f,1.0f,0,0,10f);
}
public void sound3 (View v) {
sp.play(sound3,1.0f,1.0f,0,0,10f);
}
public void sound4 (View v) {
sp.play(sound4,1.0f,1.0f,0,0,10f);
}
public void sound5 (View v) {
sp.play(sound5,1.0f,1.0f,0,0,10f);
}
public void sound6 (View v) {
sp.play(sound6,1.0f,1.0f,0,0,10f);
}
public void sound7 (View v) {
sp.play(sound7,1.0f,1.0f,0,0,10f);
}
public void sound8 (View v) {
sp.play(sound8,1.0f,1.0f,0,0,10f);
}
public void sound9 (View v) {
sp.play(sound9,1.0f,1.0f,0,0,10f);
}
No comments