Advertisement
Guest User

Untitled

a guest
Aug 31st, 2013
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.32 KB | None | 0 0
  1. package com.example.tabt1;
  2.  
  3. import android.media.MediaPlayer;
  4. import android.os.Bundle;
  5. import android.app.Activity;
  6. import android.view.Menu;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10. import android.widget.TextView;
  11.  
  12. public class MainActivity extends Activity {
  13.     MediaPlayer oursong;
  14.    
  15.     boolean play,playing;
  16.     Button add;
  17.     TextView display;
  18.     EditText thef;
  19.     String thefull,letter;
  20.     int numbl,cur;
  21.     @Override
  22.     protected void onCreate(Bundle savedInstanceState) {
  23.         super.onCreate(savedInstanceState);
  24.         setContentView(R.layout.activity_main);
  25.        
  26.          oursong = MediaPlayer.create(MainActivity.this, R.raw.soundt);
  27.        
  28.          
  29.         thef = (EditText) findViewById(R.id.editText1);
  30.        
  31.         MediaPlayer mp = new MediaPlayer();
  32.         mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
  33.         {
  34.            
  35.             @Override
  36.             public void onCompletion(MediaPlayer mp)
  37.             {
  38.                 oursong.stop();
  39.                 oursong.release();
  40.                 playing=false;
  41.                 numbl=numbl-1;
  42.                 cur=cur+1;
  43.                
  44.             }
  45.         });
  46.        
  47.         play=false;
  48.         playing=false;
  49.         numbl=0;
  50.         cur=0;
  51.         add = (Button) findViewById(R.id.button1);
  52.         display = (TextView) findViewById(R.id.textView1);
  53.         add.setOnClickListener(new View.OnClickListener()
  54.         {
  55.             @Override
  56.             public void onClick(View v)
  57.         {
  58.                 if(play==false)
  59.         // TODO Auto-generated method stub     
  60.                 display.setText("Click");
  61.                 play=true;
  62.                 thefull = thef.getText().toString();
  63.                 numbl=thefull.length();
  64.                 }
  65.         });
  66.     }
  67.  
  68.     public void onResume()
  69.     {
  70.         if(play==true)
  71.         {
  72.             if(playing==false)
  73.             {
  74.                 if(numbl>0)
  75.                 {
  76.                 letter=thefull.substring(cur, cur+1);
  77.                 if(letter.equals("m"))
  78.                 {
  79.                     oursong = MediaPlayer.create(MainActivity.this, R.raw.m);
  80.                     oursong.start();
  81.                     playing=true;
  82.                 }
  83.                 else if(letter.equals("a"))
  84.                 {
  85.                     oursong = MediaPlayer.create(MainActivity.this, R.raw.a);
  86.                     oursong.start();
  87.                     playing=true;
  88.                 }
  89.                 else if(letter.equals("r"))
  90.                 {
  91.                     oursong = MediaPlayer.create(MainActivity.this, R.raw.r);
  92.                     oursong.start();
  93.                     playing=true;
  94.                 }
  95.                 }
  96.             }
  97.            
  98.            
  99.         }
  100.        
  101.     }
  102.  
  103.     @Override
  104.     public boolean onCreateOptionsMenu(Menu menu) {
  105.         // Inflate the menu; this adds items to the action bar if it is present.
  106.         getMenuInflater().inflate(R.menu.main, menu);
  107.         return true;
  108.     }
  109.  
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement