0

I want to play a sound in my tabbed activity. Whenever the screen/Fragment is swiped and a new screen/fragment is opened, a sound should be played. But this is not happening.

public static class PlaceholderFragment extends Fragment {
/**
 * The fragment argument representing the section number for this
 * fragment.
 */
private static final String ARG_SECTION_NUMBER = "section_number";

public PlaceholderFragment() {
}

/**
 * Returns a new instance of this fragment for the given section
 * number.
 */
public static PlaceholderFragment newInstance(int sectionNumber) {
    PlaceholderFragment fragment = new PlaceholderFragment();
    Bundle args = new Bundle();
    args.putInt(ARG_SECTION_NUMBER, sectionNumber);
    fragment.setArguments(args);
    return fragment;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);
   /* TextView textView = (TextView) rootView.findViewById(R.id.section_label);
    textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));*/
    final MediaPlayer playmysnake=MediaPlayer.create(getActivity(),R.raw.rattlesnakerattle);
    playmysnake.start();

    return rootView;
}

}

Filnor
  • 1,290
  • 2
  • 23
  • 28
  • Have you tried doing anything to fix it, if yes, what have you tried? Have you checked that your device volume is up? – Ezekiel Sebastine Aug 08 '18 at 21:42
  • yes,.Volume is okay. I've tried some things. So in the above code, I deleted the whole PlaceHolderFragment and created 3 separate Fragment java classes and the same number of layout files. By doing this I was able to play sound but not properly because it threw some errors. I intend to further use soundpool and TTS in my app. – Avinash Tiwari Aug 09 '18 at 18:49

0 Answers0