how i can save data for an audiofile

Viewed 13

when i open my app and i play a audio file and go to another app and i come back to my app to pause the audio file, it play again how i can save data for an audiofile I tried sharedPreferences on text but i dont know how to use it on audio

Button button,button2;
ImageButton rain;
MediaPlayer mp,pm

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_home, container, false);

    button = rootView.findViewById(R.id.button);
    button2 = rootView.findViewById(R.id.button2);

    pm = MediaPlayer.create(getActivity(),R.raw.lofistudy);
    mp = MediaPlayer.create(getActivity(),R.raw.lightrain);
    mp.setLooping(true);
    pm.setLooping(true);


    rain = rootView.findViewById(R.id.imageButton);

    rain.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!mp.isPlaying()) {
                // Stopping
                mp.start();
                rain.setBackgroundResource(R.drawable.stop23);
            } else {
                // Playing
                mp.stop();
                try {
                    mp.prepare();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                rain.setBackgroundResource(R.drawable.stop2);
            }
        }
    });
    return rootView ;
}
0 Answers
Related