Results 1 to 3 of 3
  1. #1
    skylab is offline Member
    Join Date
    Aug 2012
    Posts
    1
    Rep Power
    0

    Default 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();
    	}
    
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Simple App Question

    Please go through the Forum Rules -- particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Simple App Question

    Quote Originally Posted by skylab View Post
    I have this code below. It is for an android app.
    Moved from New to Java.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. A simple question
    By chris.bos in forum New To Java
    Replies: 11
    Last Post: 12-02-2011, 05:37 PM
  2. Simple Question
    By new2oojava in forum New To Java
    Replies: 1
    Last Post: 09-29-2011, 07:14 AM
  3. Simple Question
    By stackptr89 in forum New To Java
    Replies: 13
    Last Post: 01-29-2011, 05:35 PM
  4. some simple question?
    By jperson in forum New To Java
    Replies: 4
    Last Post: 05-03-2010, 05:32 PM
  5. Probably a really simple question...
    By ibanez270dx in forum New To Java
    Replies: 0
    Last Post: 11-16-2007, 01:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •