My first coding project is a soundboard type thing on andriod using eclipse (on 2.3.3) and im really confused as to whats wrong with my code, I dont get any errors but the button doesnt play the sounds. If anyone could have a quick look at the code that would be great
Code:
package com.mkyong.android;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
public class AppActivity extends Activity {
Button button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
addListenerOnButton();
}
public void addListenerOnButton() {
final Context context = this;
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(context, App2Activity.class);
startActivity(intent);
}
});
}
public class PlayIt extends Activity implements OnClickListener {
MediaPlayer mp1;
MediaPlayer mp2;
public void onCreate1(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mp1 = MediaPlayer.create(this, R.raw.froze);
mp2 = MediaPlayer.create(this, R.raw.lasagna);
final Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener((OnClickListener) this);
final Button button = (Button) findViewById(R.id.button02);
button.setOnClickListener((OnClickListener) this);
}
public void onClick(View v) {
switch(v.getId()) {
case R.id.button1:
mp1.start();
break;
case R.id.button02:
mp2.start();
break;
}
}
@Override
protected void onDestroy() {
mp1.release();
mp2.release();
super.onDestroy();
}
}
}