Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7905953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:42:02+00:00 2026-06-03T10:42:02+00:00

h i am doing one here i need to display some images,at the same

  • 0

h i am doing one here i need to display some images,at the same time i need to play that images relted sound.using mediaplyer i did that one its plyaing good but my prblm is in middle of the app if i click home button thatn time also music still playing.but i need to stop music when the user click home button, i treied using on pause().but its not working any one help where i did wrong…

     GalleryMedia .class:

    public class GalleryMedia extends Activity  implements OnItemSelectedListener{
  public boolean Visibility=true;
     Boolean  loaded = false;
     MediaPlayer intro1, intro2, intro3, intro4, intro5, intro6, intro7, intro8,
        intro9, intro10, intro11, intro12, intro13;
    /** Called when the activity is first created. */
       @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        intro1 = MediaPlayer.create(this, R.raw.babycooing05);
        intro2 = MediaPlayer.create(this, R.raw.bokstavslottet_2);
        intro3 = MediaPlayer.create(this, R.raw.bokstavslottet_3);
        intro4 = MediaPlayer.create(this, R.raw.bokstavslottet_4);
        intro5 = MediaPlayer.create(this, R.raw.bokstavslottet_5);
        intro6 = MediaPlayer.create(this, R.raw.bokstavslottet_6);
        intro7 = MediaPlayer.create(this, R.raw.bokstavslottet_7);
        intro8 = MediaPlayer.create(this, R.raw.bokstavslottet_8);
        intro9 = MediaPlayer.create(this, R.raw.bokstavslottet_9);
        intro10 = MediaPlayer.create(this, R.raw.bokstavslottet_10);
        intro11 = MediaPlayer.create(this, R.raw.bokstavslottet_11);
        intro12 = MediaPlayer.create(this, R.raw.bokstavslottet_12);
        intro13 = MediaPlayer.create(this, R.raw.starwars);
        Gallery g=(Gallery)findViewById(R.id.gallery);
          g.setAdapter(new ImageAdapter(this));
          g.setSpacing(10);

          g.setOnItemSelectedListener(this);
  } 
    public class ImageAdapter extends BaseAdapter {
        private Context myContext;
        private int[] myImageIds = {
                R.drawable.bokstavslottet01,
                R.drawable.bokstavslottet02,
                R.drawable.bokstavslottet03,
                R.drawable.bokstavslottet04,
                R.drawable.bokstavslottet05,
                R.drawable.bokstavslottet06,
                R.drawable.bokstavslottet07,
                R.drawable.bokstavslottet08,
                R.drawable.bokstavslottet09,
                R.drawable.bokstavslottet10,
                R.drawable.bokstavslottet11,
                R.drawable.bokstavslottet12,
                R.drawable.bokstavslottet13
    };
             public ImageAdapter(Context c) { this.myContext = c; }
        public int getCount() {
            // TODO Auto-generated method stub
            return this.myImageIds.length;
        }

        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
             ImageView i = new ImageView(this.myContext);

                 i.setImageResource(this.myImageIds[position]);




             /* Image should be scaled as width/height are set. */
             i.setScaleType(ImageView.ScaleType.FIT_XY);
             /* Set the Width/Height of the ImageView. */
             i.setLayoutParams(new Gallery.LayoutParams(700, 400));
             Integer e = myImageIds.length;
             Log.i("","length-------"+e);

             return i;
         }

         /** Returns the size (0.0f to 1.0f) of the views
          * depending on the 'offset' to the center. */
         public float getScale(boolean focused, int offset) {
                 /* Formula: 1 / (2 ^ offset) */
             return Math.max(0, 1.0f / (float)Math.pow(2, Math.abs(offset)));
         }
        }

    public void onItemSelected(AdapterView<?> arg0, View arg1, int position,
            long arg3) {
        // TODO Auto-generated method stub
        if (position == 0) {

            intro1.start();
            intro1 = MediaPlayer.create(this, R.raw.babycooing05);
            intro1.start();
        }
        if (position == 1) {
            intro1.stop();
            intro2.start();
            intro2 = MediaPlayer.create(this, R.raw.bokstavslottet_2);
            intro2.start();
        }
        if (position == 2) {
            intro2.stop();
            intro3.start();
            intro3 = MediaPlayer.create(this, R.raw.bokstavslottet_3);
            intro3.start();
        }
        if (position == 3) {
            intro3.stop();
            intro4.start();
            intro4 = MediaPlayer.create(this, R.raw.bokstavslottet_4);
            intro4.start();
        }
        if (position == 4) {
            intro4.stop();
            intro5.start();
            intro5 = MediaPlayer.create(this, R.raw.bokstavslottet_5);
            intro5.start();
        }
        if (position == 5) {
            intro5.stop();
            intro6.start();
            intro6 = MediaPlayer.create(this, R.raw.bokstavslottet_6);
            intro6.start();
        }
        if (position == 6) {
            intro6.stop();
            intro7.start();
            intro7 = MediaPlayer.create(this, R.raw.bokstavslottet_7);
            intro7.start();
        }
        if (position == 7) {
            intro7.stop();
            intro8.start();
            intro8 = MediaPlayer.create(this, R.raw.bokstavslottet_8);
            intro8.start();
        }
        if (position == 8) {
            intro8.stop();
            intro9.start();
            intro9 = MediaPlayer.create(this, R.raw.bokstavslottet_9);
            intro9.start();
        }
        if (position == 9) {
            intro9.stop();
            intro10.start();
            intro10 = MediaPlayer.create(this, R.raw.bokstavslottet_10);
            intro10.start();
        }
        if (position == 10) {
            intro10.stop();
            intro11.start();
            intro11 = MediaPlayer.create(this, R.raw.bokstavslottet_11);
            intro11.start();
        }
        if (position == 11) {
            intro10.stop();
            intro12.start();
            intro12 = MediaPlayer.create(this, R.raw.bokstavslottet_12);
            intro12.start();
        }
        if (position == 12) {
            intro12.stop();
            intro13.start();
            intro13 = MediaPlayer.create(this, R.raw.starwars);
            intro13.start();
        }
        }
    @Override
    protected void onPause() {
        super.onPause();
        if (intro1 != null){
            intro1.stop();
            if (isFinishing()){
                intro1.stop();
                intro1.release();
            }
        }

        if (intro2 != null){
            intro2.stop();
            if (isFinishing()){
                intro2.stop();
                intro2.release();
            }
        }
            if (intro3 != null){
                intro3.stop();
                if (isFinishing()){
                    intro3.stop();
                    intro3.release();
                }
            }
            if (intro4 != null){
                intro4.stop();
                if (isFinishing()){
                    intro4.stop();
                    intro4.release();
                }
            }
            if (intro5 != null){
                intro5.stop();
                if (isFinishing()){
                    intro5.stop();
                    intro5.release();
                }
            }
            if (intro6 != null){
                intro6.stop();
                if (isFinishing()){
                    intro6.stop();
                    intro6.release();
                }
            }
            if (intro7 != null){
                intro7.stop();
                if (isFinishing()){
                    intro7.stop();
                    intro7.release();
                }
            }
            if (intro8 != null){
                intro8.stop();
                if (isFinishing()){
                    intro8.stop();
                    intro8.release();
                }
            }
            if (intro9 != null){
                intro9.stop();
                if (isFinishing()){
                    intro9.stop();
                    intro9.release();
                }
            }
            if (intro10 != null){
                intro10.stop();
                if (isFinishing()){
                    intro10.stop();
                    intro10.release();
                }
            }
            if (intro11 != null){
                intro11.stop();
                if (isFinishing()){
                    intro11.stop();
                    intro11.release();
                }
            }
            if (intro12 != null){
                intro12.stop();
                if (isFinishing()){
                    intro12.stop();
                    intro12.release();
                }
            }
            if (intro13 != null){
                intro13.stop();
                if (isFinishing()){
                    intro13.stop();
                    intro13.release();
                }
            }
    }
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub

    }
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T10:42:17+00:00Added an answer on June 3, 2026 at 10:42 am

    You need to stop your media service in onStop method of your Activity. The method onStop is always get called when you navigate away from your activity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi i am doing one application here i need to disply 6 images in
hi i am doing one app here when i click button that time i
I'm doing one application like raising email intent by time using AlarmManager . In
I am doing one project on Struts 2 that I am getting knowledge little
I'm doing some custom authentication written in PHP and need to set the REMOTE_USER
in my C#-Silverlight-3-Application, I have created a class, that is doing some calculations that
I'm doing one research on video encoding tools for flv. I tested flvtool2 and
i am doing one small application , wheich have login functionality, in the user
Before I have tried about doing one attachment (upload) for each record of my
I am very new to grails.I am doing one sample project for image uploading

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.