I am creating an Android app that needs to play an audio when a button is pressed. But it does not play the music although the rest of the code functions.Also there is an error on context that says context cannot be resolved to a variable.
Here is my main activity
public class BroadcastNewSms extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.androidexample_broadcast_newsms);
Button b1;
b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
MediaPlayer mp;
mp = MediaPlayer.create(context,R.raw.hospital_alarm);
mp.start();
String phoneNumber = "+9198zxxxxxxx";
String message = "Ambulance sent!";
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNumber, null, message, null, null);
}
});
}
}