Results 1 to 3 of 3
Thread: Simple App Question
- 08-13-2012, 08:27 AM #1
Member
- Join Date
- Aug 2012
- Posts
- 1
- Rep Power
- 0
Simple App Question
I have this code below. It is for an android app. What it does now is, it uses a slider similar to the picture attached. What I want is to modify the code below so that it can play the appropriate audio for each page not only the audio called cat.mp3. Because now, whenever I slide to the next image and click on it, I still here the audio of the cat, not the dog or cow. Any help would be greatly appreciated.
Image of the app: View image: prototype
Code of the app:
Java Code:package myapp; import java.io.InputStream; import android.app.Activity; import android.content.res.AssetManager; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.media.MediaPlayer; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; public class MyLanguages extends Activity { Button prev_btn; Button next_btn; ImageView main_img_vw; ImageView audio_img_vw; TextView words_txt_vw; public static int index_of_pic; String[] mydefinition; String[] myword; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); prev_btn = (Button) findViewById(R.id.previous_btn); next_btn = (Button) findViewById(R.id.next_btn); // main_img_vw = (ImageView) findViewById(R.id.); words_txt_vw = (TextView) findViewById(R.id.words_textView); main_img_vw = (ImageView) findViewById(R.id.main_imageView); audio_img_vw = (ImageView) findViewById(R.id.audio_imageView); index_of_pic = 0; next_btn.setClickable(true); prev_btn.setClickable(true); Resources res = getResources(); mydefinition = res.getStringArray(R.array.french_string_array); myword = res.getStringArray(R.array.english_string_array_name); words_txt_vw.setText(myword[0] + " - " + mydefinition[0]); try { } catch (Exception e) { System.out.println(e.getMessage()); // e.printStackTrace(); } prev_btn.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub System.out.println("prev button clicked"); try { index_of_pic = (index_of_pic - 1) % (myword.length); if (index_of_pic < 0) index_of_pic = myword.length - 1; Bitmap btm = getBitmapFromAsset("animal_pics/" + myword[index_of_pic] + ".png"); main_img_vw.setImageBitmap(btm); words_txt_vw.setText(myword[index_of_pic] + " - " + mydefinition[index_of_pic]); } catch (Exception e) { System.out.println(e.getMessage()); } } }); next_btn.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub System.out.println("next button clicked"); // main_img_vw.setBackgroundResource(); // myword[(index_of_pic + 1)% myword.length]); try { index_of_pic = (index_of_pic + 1) % (myword.length); Bitmap btm = getBitmapFromAsset("animal_pics/" + myword[index_of_pic] + ".png"); main_img_vw.setImageBitmap(btm); words_txt_vw.setText(myword[index_of_pic] + " - " + mydefinition[index_of_pic]); } catch (Exception e) { System.out.println(e.getMessage()); } } }); main_img_vw.setClickable(true); main_img_vw.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub MediaPlayer mPlayer = MediaPlayer.create( MyLanguages.this, R.raw.cat); mPlayer.start(); } }); audio_img_vw.setClickable(true); audio_img_vw.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub MediaPlayer mPlayer = MediaPlayer.create( MyLanguages.this, R.raw.cat); mPlayer.start(); } }); } // MediaPlayer mPlayer; private Bitmap getBitmapFromAsset(String strName) throws Exception { AssetManager assetManager = getAssets(); InputStream istr = assetManager.open(strName); Bitmap bitmap = BitmapFactory.decodeStream(istr); return bitmap; } @Override protected void onDestroy() { super.onDestroy(); // mPlayer.stop(); // finish(); } }
- 08-13-2012, 02:36 PM #2
Re: Simple App Question
Please go through the Forum Rules -- particularly the third paragraph.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 08-13-2012, 02:37 PM #3
Similar Threads
-
A simple question
By chris.bos in forum New To JavaReplies: 11Last Post: 12-02-2011, 05:37 PM -
Simple Question
By new2oojava in forum New To JavaReplies: 1Last Post: 09-29-2011, 07:14 AM -
Simple Question
By stackptr89 in forum New To JavaReplies: 13Last Post: 01-29-2011, 05:35 PM -
some simple question?
By jperson in forum New To JavaReplies: 4Last Post: 05-03-2010, 05:32 PM -
Probably a really simple question...
By ibanez270dx in forum New To JavaReplies: 0Last Post: 11-16-2007, 01:27 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks