کد HTML:
package com.darkhah1.tar;
import java.io.FileInputStream;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
public class MainActivity extends Activity {
LinearLayout lnr = (LinearLayout) findViewById(R.id.tableRow);
Button b1 = new Button(this);
lnr.addView(b1);
// Associate the event
b1.setOnTouchListener(new OnTouchListener() {
MediaPlayer mp = new MediaPlayer();
@Override
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
// Finger started pressing --> play sound in loop mode
try {
FileInputStream fileInputStream = new FileInputStream( PATH );
mp.setDataSource(fileInputStream.getFD());
mp.prepare();
mp.setLooping(true);
mp.start();
} catch (Exception e) {}
break;
case MotionEvent.ACTION_UP:
// Finger released --> stop playback
try {
mp.stop();
mp.reset();
} catch (Exception e) {}
break;
}
return true;
}
});
private AudioManager audioManager;
private NoteManager noteManager = new NoteManager();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button p=(Button) findViewById(R.id.button100);
p.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startActivity(new Intent(MainActivity.this, Note.class));
}
});
createClickEvents();
}
private void createClickEvents() {
//Fix this up to go by ID.
noteManager.defineKeyNote(this, R.id.button1, R.raw.c3);
noteManager.defineKeyNote(this, R.id.button2, R.raw.b3);
noteManager.defineKeyNote(this, R.id.button3, R.raw.a2);
noteManager.defineKeyNote(this, R.id.button4, R.raw.b2);
noteManager.defineKeyNote(this, R.id.button5, R.raw.a8);
noteManager.defineKeyNote(this, R.id.button6, R.raw.a1);
noteManager.defineKeyNote(this, R.id.button7, R.raw.a7);
noteManager.defineKeyNote(this, R.id.button8, R.raw.c3);
noteManager.defineKeyNote(this, R.id.button01, R.raw.b5);
noteManager.defineKeyNote(this, R.id.button02, R.raw.c5);
noteManager.defineKeyNote(this, R.id.button03, R.raw.a5);
noteManager.defineKeyNote(this, R.id.button04, R.raw.b4);
noteManager.defineKeyNote(this, R.id.button05, R.raw.c4);
noteManager.defineKeyNote(this, R.id.button06, R.raw.a4);
noteManager.defineKeyNote(this, R.id.button07, R.raw.a3);
noteManager.defineKeyNote(this, R.id.button08, R.raw.c3);
noteManager.defineKeyNote(this, R.id.button01, R.raw.a5);
noteManager.defineKeyNote(this, R.id.button9, R.raw.b2);
noteManager.defineKeyNote(this, R.id.button10, R.raw.a8);
noteManager.defineKeyNote(this, R.id.button11, R.raw.a1);
noteManager.defineKeyNote(this, R.id.button12, R.raw.a7);
noteManager.defineKeyNote(this, R.id.button13, R.raw.c7);
noteManager.defineKeyNote(this, R.id.button14, R.raw.b7);
noteManager.defineKeyNote(this, R.id.button15, R.raw.a6);
noteManager.defineKeyNote(this, R.id.button16, R.raw.c6);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void playAudio(View view) {
Intent objIntent = new Intent(this, PlayAudio.class);
startService(objIntent);
}
public void stopAudio(View view) {
Intent objIntent = new Intent(this, PlayAudio.class);
stopService(objIntent);
}
public boolean onCreateOptionsMenu1(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void playAudio1(View view) {
Intent objIntent = new Intent(this, PlayAudio1.class);
startService(objIntent);
}
public void stopAudio1(View view) {
Intent objIntent = new Intent(this, PlayAudio1.class);
stopService(objIntent);
}
public boolean onCreateOptionsMenu11(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void playAudio2(View view) {
Intent objIntent = new Intent(this, PlayAudio2.class);
startService(objIntent);
}
public void stopAudio2(View view) {
Intent objIntent = new Intent(this, PlayAudio2.class);
stopService(objIntent);
}
public boolean onCreateOptionsMenu2(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void playAudio3(View view) {
Intent objIntent = new Intent(this, PlayAudio3.class);
startService(objIntent);
}
public void stopAudio3(View view) {
Intent objIntent = new Intent(this, PlayAudio3.class);
stopService(objIntent);
}
public boolean onCreateOptionsMenu4(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void playAudio4(View view) {
Intent objIntent = new Intent(this, PlayAudio4.class);
startService(objIntent);
}
public void stopAudio4(View view) {
Intent objIntent = new Intent(this, PlayAudio4.class);
stopService(objIntent);
}
}
این کل کد Mainactivity هستش الان دکمه هام صدا میده ولی تک به تک می خوام موقع لمس از اول تا اخر دکمه یکی یکی صدا بده؟؟؟