Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.tabt1;
- import android.media.MediaPlayer;
- import android.os.Bundle;
- import android.app.Activity;
- import android.view.Menu;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- public class MainActivity extends Activity {
- MediaPlayer oursong;
- boolean play,playing;
- Button add;
- TextView display;
- EditText thef;
- String thefull,letter;
- int numbl,cur;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- oursong = MediaPlayer.create(MainActivity.this, R.raw.soundt);
- thef = (EditText) findViewById(R.id.editText1);
- MediaPlayer mp = new MediaPlayer();
- mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
- {
- @Override
- public void onCompletion(MediaPlayer mp)
- {
- oursong.stop();
- oursong.release();
- playing=false;
- numbl=numbl-1;
- cur=cur+1;
- }
- });
- play=false;
- playing=false;
- numbl=0;
- cur=0;
- add = (Button) findViewById(R.id.button1);
- display = (TextView) findViewById(R.id.textView1);
- add.setOnClickListener(new View.OnClickListener()
- {
- @Override
- public void onClick(View v)
- {
- if(play==false)
- // TODO Auto-generated method stub
- display.setText("Click");
- play=true;
- thefull = thef.getText().toString();
- numbl=thefull.length();
- }
- });
- }
- public void onResume()
- {
- if(play==true)
- {
- if(playing==false)
- {
- if(numbl>0)
- {
- letter=thefull.substring(cur, cur+1);
- if(letter.equals("m"))
- {
- oursong = MediaPlayer.create(MainActivity.this, R.raw.m);
- oursong.start();
- playing=true;
- }
- else if(letter.equals("a"))
- {
- oursong = MediaPlayer.create(MainActivity.this, R.raw.a);
- oursong.start();
- playing=true;
- }
- else if(letter.equals("r"))
- {
- oursong = MediaPlayer.create(MainActivity.this, R.raw.r);
- oursong.start();
- playing=true;
- }
- }
- }
- }
- }
- @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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement