title: Mediaplayer not pausing while switching fragment
body: <p>I am new to android studio. Please help. I have an app with 3 fragments, one have list of video view using recycler adapter, one have list of image view, other have same list of video view as no 1 fragment. First and last fragment are using same adapter. The problem is that while switching fragmment from first one to second video keeps playing.</p>
  
  <pre><code> //fragment code
   public class funny_moments extends Fragment {
  FirebaseDatabase database = FirebaseDatabase.getInstance();
  DatabaseReference myRef = database.getReference("funnymomments");
   ArrayList&lt;funny_momments_row&gt; data;
   funny_momments_adapter adapter;
   VideoView mVideoView;
   View pos;
  
  private RecyclerView mRecyclerView;
  public funny_moments() {
      // Required empty public constructor
  }
  
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.fragment_funny_moments, container, false);
      mRecyclerView =(RecyclerView) view.findViewById(R.id.recylerview);
      mVideoView = (VideoView)view.findViewById(R.id.videoView);
  
      data = new ArrayList&lt;&gt;();
      myRef.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
  
              for (DataSnapshot videoSnapshot : dataSnapshot.getChildren()){
                  funny_momments_row video = new funny_momments_row(videoSnapshot.child("like").getValue().toString(),videoSnapshot.child("url").getValue().toString());
  
                  data.add(video);
  
              }
  
             adapter = new funny_momments_adapter(getActivity(),data,mCommunication);
              mRecyclerView.setAdapter(adapter);
              mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
          }
  
          @Override
          public void onCancelled(@NonNull DatabaseError databaseError) {
  
          }
  
      });
  
  
  
      // Inflate the layout for this fragment
      return view;
  }
    @Override
  public void onPause() {
      adapter.mMediaPlayer.pause();
      super.onPause();
  
  }
  
  
  //adapter code
   public class funny_momments_adapter extends RecyclerView.Adapter&lt;funny_momments_adapter.funnyVideoHolder&gt; {
  private final LayoutInflater inflator;
  List&lt;funny_momments_row&gt; data = Collections.emptyList();
  communication mCommunicator;
  Context mContext;
  
  
  
  public funny_momments_adapter(Context context, List&lt;funny_momments_row&gt; data, communication communicator){
  
      inflator = LayoutInflater.from(context);
      this.data = data;
      this.mContext = context;
      mCommunicator = communicator;
  }
  @NonNull
  @Override
  public funnyVideoHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
  
          View view = inflator.inflate(R.layout.funny_momments_row,viewGroup,false);
          funnyVideoHolder funnyHolder = new funnyVideoHolder(view,mCommunicator);
      return funnyHolder;
  }
  
  @Override
  public void onBindViewHolder(@NonNull final funnyVideoHolder viewHolder, int i) {
  
      funny_momments_row current = data.get(i);
      VideoView f1 = viewHolder.mVideoView;
      viewHolder.mVideoView.setVideoURI(Uri.parse(current.getUrl()));
  
      viewHolder.likecount.setText(current.getLike());
  
      viewHolder.mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
          @Override
          public void onPrepared(final MediaPlayer mp) {
              FragmentManager manager = ((AppCompatActivity)mContext).getSupportFragmentManager();
              Fragment f = manager.findFragmentByTag("android:switcher:" + R.id.viewPager + ":" + 2);
  
              mMediaPlayer = mp;
  
              viewHolder.playpause.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      if (mp.isPlaying()) {
                          mp.pause();
                      }
                      else {
                          mp.start();
                      }
                  }
              });
          }
      });
  
      viewHolder.playpause.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              if (viewHolder.mVideoView.isPlaying()) {
                  viewHolder.mVideoView.requestFocus();
                  viewHolder.mVideoView.pause();
              }
              else {
                  viewHolder.mVideoView.requestFocus();
                  viewHolder.mVideoView.start();
              }
          }
      });
  
  
  }
  
  
  
  @Override
  public int getItemCount() {
      return data.size();
  }
  
     public class funnyVideoHolder extends  RecyclerView.ViewHolder implements View.OnClickListener{
  
      VideoView mVideoView;
      ImageView likeicon;
      TextView likecount;
      ImageView playpause;
      communication mCommunication;
      public funnyVideoHolder(@NonNull View itemView,communication communication) {
          super(itemView);
          mVideoView = (VideoView)itemView.findViewById(R.id.videoView);
          likeicon = (ImageView)itemView.findViewById(R.id.likeicon);
          likecount = (TextView)itemView.findViewById(R.id.likecount);
          playpause = (ImageView)itemView.findViewById(R.id.playpause);
          mCommunication = communication;
  
      }
  
     @Override
     public void onClick(View v) {
          mCommunication.respond(v);
     }
  </code></pre>
  
  <p>}
  }</p>
  
  <p>I want to stop playback while switching fragment.</p>