Today I want to present you a Vietnamese dialect game. If you press the "Play" Button you'll hear a short sentence in one of Vietnamese dialect.
In the spinner below you choose one of the options and then press the "Submit" Button. If it is true it will add up to your score, other wise not.
Here's an example on how to use it:
First create a folder "raw" in the "res" folder. In the "raw" folder put all of your audio files:
In the MainActivity.java file put the following code (as you can see I didn't include all variables, because I wanted to keep the code short and concentrate on the featuares I haven't talked about in my Blog):
public void onCreate(Bundle savedInstanceState) { try{ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Set the ClickListener: play_button.setOnClickListener(this); pause_button.setOnClickListener(this); btnSubmit.setOnClickListener(this); // Set path to media player = MediaPlayer.create(this, R.raw.v01); seek_bar.setMax(player.getDuration()); }catch(NullPointerException e){ Log.v(getString(R.string.app_name), e.getMessage()); } } Runnable run = new Runnable() { @Override public void run() { seekUpdation(); } }; public void seekUpdation() { seek_bar.setProgress(player.getCurrentPosition()); seekHandler.postDelayed(run, 1000); } public void onClick(View view) { Intent serv=new Intent(this,MuzakService.class); switch (view.getId()) { case R.id.play_button: text_shown.setText("Playing..."); player.start(); startService(serv); break; case R.id.pause_button: player.pause(); text_shown.setText("Paused..."); break; case R.id.btnSubmit: tries++; String item = spinner1.getSelectedItem().toString(); if (item.equals(dialect)){ score++; quota=(float) (score/(tries*1.0))*100; text_score.setText("Accurate! New Score: "+quota+"% accuracy out of "+tries+" trials."); } else{ quota=(float) (score/(tries*1.0))*100; text_score.setText("Are you deaf?! New Score: "+quota+"% accuracy"+tries+" trials."); } btnSubmit.setEnabled(false); break; }
You can download the app here
No comments:
Post a Comment