title: Want to play sound on viewpager Swipe
body: <p>i am working on android app which can play background sound whenever image is swipes. I have gone through multiple tutorials &amp; found codes &amp; i tried for the same but it won't work for me. Here is my code which i tried..</p>
  
  <pre><code>package com.android.learning_numbers;
  
  import android.media.MediaPlayer;
  import android.os.Bundle;
  import android.app.Activity;
  import android.content.Context;
  import android.support.v4.view.PagerAdapter;
  import android.support.v4.view.ViewPager;
  import android.support.v4.view.ViewPager.OnPageChangeListener;
  import android.util.Log;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ImageView;
  
  public class Numbers extends Activity {
  
      private static final OnPageChangeListener change = null;
      public static MediaPlayer mp = null;
  
      @Override
       protected void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.activity_numbers);
           ViewPager viewPager = (ViewPager)findViewById(R.id.view_pager);
           ImagePagerAdapter adapter = new ImagePagerAdapter();
           viewPager.setAdapter(adapter);
           viewPager.setOnPageChangeListener(change);}
  
       private class ImagePagerAdapter extends PagerAdapter {
  
           private int[] mImages = new int[] {R.drawable.sun,R.drawable.sky,R.drawable.moon,};
  
  
           private int[] mAudio= new int[]{R.raw.sun,R.raw.sky,R.raw.moon,};
           @Override
           public int getCount() {
           return mImages.length;
             }
           @Override
           public boolean isViewFromObject(View view, Object object) {
              return view == ((ImageView) object);
                 }
           @Override
           public Object instantiateItem(ViewGroup container, int position) {
              Context context = Numbers.this;
              ImageView imageView = new ImageView(context);
              int padding =context.getResources().  
              getDimensionPixelSize(R.dimen.activity_vertical_margin);
              imageView.setPadding(padding, padding, padding, padding);
              imageView.setScaleType(ImageView.ScaleType.CENTER);
              imageView.setImageResource(mImages[position]);
              ((ViewPager) container).addView(imageView, 0); 
              return imageView;
              }
  
           public OnPageChangeListener change = new OnPageChangeListener() {
  
               @Override public void onPageSelected(int position) {
                   Log.d(ACTIVITY_SERVICE, "OnPageSelected");
                   if 
  
                   (mp != null) {
                    mp.reset();
                    mp.release();
                   }
                   mp = MediaPlayer.create(Numbers.this, mAudio[position]);
                   mp.start();
               }
               @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
               @Override public void onPageScrollStateChanged(int state) {}
              };
  
  
  
           @Override
           public void destroyItem(ViewGroup container, int position, Object object) {
             ((ViewPager) container).removeView((ImageView) object);
           }
       }
       }
  </code></pre>
  
  <p>As i think here sound is not called by class on image swipe. Is there any error in my code? Because here OnPageChangeListener is not working for me at all. What is the solution for this? How do i modify my sound code that works for me?</p>