player example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://fonts.googleapis.com/css2?family=Montserrat:[email protected]&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha2/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css">
    <title>Player Demo</title>
    <style>
    html {
        margin: 0;
        padding: 0;
        width: 100%;
        height: 100%;
        -webkit-user-select: none; /* Safari */
        -ms-user-select: none; /* IE 10 and IE 11 */
        user-select: none; /* Standard syntax */
    }
    body {
        background-color:#222f3e;
        background-size: cover;
        overflow: hidden;
        color: #fff;
    }
    .date {
        font-size: 1.1rem;
        font-family: 'Montserrat', sans-serif;
        background-color: rgba(0, 0, 0, 0.2);
        padding-top: 5px;
        padding-bottom: 5px;
        margin-right: 15vw;
        margin-left: 15vw;
        border-radius: 10px;
    }
    .btn {
        box-shadow: 0 0 10px 1px rgba(0, 0, 0, 0.6) !important;
        color: #eee;
        text-shadow: 0 0 4px #000;
    }
    .btn:hover,
    .btn:focus,
    .btn:active {
        color: #eee;
    }
    .vol-size {
        font-size: 1.3rem;
    }
    .radio-name {
        font-size: 2rem;
        font-family: 'Montserrat', sans-serif;
        color: #fff;
    }
    .radio-buttons {
        padding-top: 15px;
        padding-bottom: 10px;
        margin-right: 10vw;
        margin-left: 10vw;
        margin-top: 8vh;
        background-color: rgba(0, 0, 0, 0.2);
        border-radius: 10px;
    }
    .radio-volume {
        margin-left: 10vw;
        margin-right: 10vw;
        display: inline-block;
        margin-top: 5vh;
    }
    .radio-volume i {
        margin-right: 10px;
        font-size: 1.2rem;
    }
    </style>
</head>
<body>
    <div class="container-fluid p-3">
        <div class="text-center">
            <h2 class="radio-name">Nome da radio</h2>           
            <p class="status mt-3">
                [<span class="icon">
                    <i class="fas fa-info-circle"></i>
                </span>] 
                <span class="text">Loading...</span>
            </p>
            <audio id="player" src="#" autoplay></audio>
            <div class="radio-buttons">
                <button type="button" id="play" class="btn btn-success btn-round shadow">
                    <i class="far fa-play-circle"></i>
                </button>
                <button type="button" id="pause" class="btn btn-danger shadow">
                    <i class="far fa-pause-circle"></i>
                </button>
                <button type="button" id="stop" class="btn btn-warning shadow">
                    <i class="far fa-stop-circle"></i>
                </button>
                <div class="radio-volume pb-2">
                    <div class="form-group">
                        <input type="range" class="form-control-range" id="vol" value="75" maxvalue="100%">
                        <span class="vol-size">75%</span>
                      </div>
                </div>
            </div>
            <h5 class="date mt-3">03:25:52 - 28/11</h5>
        </div>
    </div>
    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha2/js/bootstrap.bundle.min.js"></script>
    <script>
    const statusText = $('.status .text');
    const statusIcon = $('.status .icon');
    const volSize = $('.vol-size');
    const player = $('#player');
    const url = "https://sonicpanel.oficialserver.com:7146/;";
    
    const zeroPad = (num, places) => String(num).padStart(places, '0'); // adds zeros to numbers below than 10

    const updateTime = () => {
        let dateString = new Date().toLocaleString("en-GB");
        let fTime = dateString.replace(", ", " - ");
        $('.date').html(fTime);
    }

    let status = false;

    player.prop('volume', 0.75); // default

    $(document).ready(function() {
        if (player.attr('src') == '#') {
            player.attr('src', url);
        }
        if (false === status) { // autoplay
            player.get(0).play().then(function() { // can autoplay
                status = true;
                statusText.html('Playing...');
                statusIcon.html('<i class="fas fa-volume-up"></i>');
            }).catch(function() { // throws error, ask to play manual
                statusText.html('Click <strong>Play</strong> to listen!');
            });
        }
        $('#play').click(function() {
            if (false === status) {
                status = true;
                if (player.attr('src') == '#') {
                    player.attr('src', url);
                }
                player.get(0).play();
                statusText.html('Playing...');
                statusIcon.html('<i class="fas fa-volume-up"></i>');
            }
        }),
        $('#pause').click(function() {
            if (true === status) {
                status = false;
                player.get(0).pause();
                statusText.html('Paused');
                statusIcon.html('<i class="fas fa-volume-mute"></i>');
            }
        }),
        $('#stop').click(function() {
            if (true === status) {
                status = false;
                player.attr('src', '#');
                player.get(0).pause();
                statusText.html('Stopped');
                statusIcon.html('<i class="fas fa-volume-mute"></i>');
            }
        }),
        $("#vol").change(function() {
            let volume = $(this).val();
            volSize.html(zeroPad(volume, 2) + '%');
            player.prop("volume", volume / 100);
        }),
        updateTime(),
        setInterval(updateTime, 1000); // every 1 sec obvious
    });
    </script>
</body>
</html>