<filename>TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Util/PlaySound.java
package org.firstinspires.ftc.teamcode.Util;

import android.media.MediaPlayer;

import com.qualcomm.robotcore.hardware.HardwareMap;

import org.firstinspires.ftc.teamcode.R;

public class PlaySound {

    private MediaPlayer mp;


    public PlaySound(HardwareMap hardwareMap, int soundId){
        mp = MediaPlayer.create(hardwareMap.appContext, soundId);
        mp.setOnCompletionListener(MediaPlayer::release);
    }

    public void play(){
        try {
            mp.start();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public void pause(){
        try {
            mp.pause();
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * Stop and release all the resources taken up by the media player
     */
    public void stop(){
        try {
            mp.stop();
            mp.release();
        } catch (Exception e){
            e.printStackTrace();
        }
    }


}
