skip forward and backward 10 seconds html Audio, JavaScript function not working on Opera And Chrome

I ran into an issue with a project that I’m currently working on, I made a function to skip forward and backward 10 seconds like on YouTube for an html audio player, on browsers like Firefox, Safari and some other browsers this function works perfectly fine (if you click forward you skip 10 seconds and if you click backward you replay/rewind the last 10 seconds) but I wasn’t that successful with chrome and opera it always resets the time to 0:00 no matter which button I click (forward button or backward button), that’s my code hope you can help me TYSM ????.

My HTML Code:

<div class="audioVersionPost">
  
<audio id="audioPlayer" autoplay preload="metadata">
  <source id="audioSource" type="audio/mpeg">
</audio>

<button id="playPauseBtn">
  <span id="playSpanIcon" class="material-symbols-rounded playerSymbols">play_circle</span>
  <span id="pauseSpanIcon" class="material-symbols-rounded playerSymbols">pause_circle</span>
  <span id="playText">Playing</span>
  <span id="pauseText">Paused</span>
</button>
  
<button id="replayBtn">
  <span class="material-symbols-rounded playerSymbols">replay</span>
  <span>Replay</span>
</button>

<button id="skipBackwardBtn">
  <span class="material-symbols-rounded playerSymbols">replay_10</span>
</button>
  
<button id="skipForwardBtn">
  <span class="material-symbols-rounded playerSymbols">forward_10</span>
</button>
  
<span id="currentTime">0:00</span>

<input type="range" id="seekSlider" min="0" max="100" value="0" disabled>
  
<span id="totalTime">0:00</span>
  
<select id="speedSelect">
  <option value="0.5">0.5x</option>
  <option value="1" selected>1x</option>
  <option value="1.5">1.5x</option>
  <option value="2">2x</option>
</select>
  
</div>

My JavaScript Script:

const audioPlayer = document.getElementById('audioPlayer');
  const playPauseBtn = document.getElementById('playPauseBtn');
  const skipBackwardBtn = document.getElementById('skipBackwardBtn');
  const skipForwardBtn = document.getElementById('skipForwardBtn');
  const speedSelect = document.getElementById('speedSelect');
  const currentTime = document.getElementById('currentTime');
  const totalTime = document.getElementById('totalTime');
  const seekSlider = document.getElementById('seekSlider');

  // Play/pause button functionality
  playPauseBtn.addEventListener('click', function() {
    if (audioPlayer.paused) {
      audioPlayer.play();
    } else {
      audioPlayer.pause();
    }
  });

  // Skip backward button functionality
  skipBackwardBtn.addEventListener('click', function() {
    audioPlayer.currentTime -= 10;
  });

  // Skip forward button functionality
  skipForwardBtn.addEventListener('click', function() {
    audioPlayer.currentTime += 10;
  });

  // Speed control functionality
  speedSelect.addEventListener('change', function() {
    audioPlayer.playbackRate = parseFloat(speedSelect.value);
  });

  // Update current time and total time
  audioPlayer.addEventListener('timeupdate', function() {
    currentTime.textContent = formatTime(audioPlayer.currentTime);
    totalTime.textContent = formatTime(audioPlayer.duration);
    const value = (audioPlayer.currentTime / audioPlayer.duration) * 100;
    seekSlider.value = value;
    seekSlider.style.background = `linear-gradient(to right, #3557FF ${value}%, #EDF0FF ${value}%)`;
  });

  // Format time function
  function formatTime(seconds) {
    const minutes = Math.floor(seconds / 60);
    const remainingSeconds = Math.floor(seconds % 60);
    const formattedMinutes = minutes === 0 ? '0' : minutes.toString();
    const formattedSeconds = remainingSeconds < 10 ? '0' + remainingSeconds : remainingSeconds.toString();
    return `${formattedMinutes}:${formattedSeconds}`;
  }

  // Seek functionality
  seekSlider.addEventListener('input', function() {
    const value = (seekSlider.value / 100) * audioPlayer.duration;
    audioPlayer.currentTime = value;
    seekSlider.style.background = `linear-gradient(to right, #3557FF ${seekSlider.value}%, #EDF0FF ${seekSlider.value}%)`;
  });

  document.getElementById("playPauseBtn").addEventListener("click", function() {
    var playIcon = document.getElementById("playSpanIcon");
    var pauseIcon = document.getElementById("pauseSpanIcon");
    var playText = document.getElementById("pauseText");
    var pauseText = document.getElementById("playText");

    if (playIcon.style.display === "none") {
        playIcon.style.display = "block";
        pauseIcon.style.display = "none";
        playText.style.display = "block";
        pauseText.style.display = "none";
    } else {
        playIcon.style.display = "none";
        pauseIcon.style.display = "block";
        playText.style.display = "none";
        pauseText.style.display = "block";
    }
  });

  const replayBtn = document.getElementById('replayBtn');

  audioPlayer.addEventListener('ended', function() {
    // Show replay button and hide play/pause button
    replayBtn.style.display = 'flex';
    playPauseBtn.style.display = 'none';
  });

  replayBtn.addEventListener('click', function() {
    // Reset audio playback
    audioPlayer.currentTime = 0;
    audioPlayer.play();

    // Toggle display of play/pause buttons
    playPauseBtn.style.display = 'block';
    replayBtn.style.display = 'none';
  });

I want to fix the issue without effecting my existing code, I want the forward button to skip 10 seconds and the backward button to replay the last 10 seconds

New contributor

Oliver Gray Silva is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật