How to make enhanced music or audio file in the background?

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • How to make enhanced music or audio file in the background?

    Hello friends, can you help me with a coding I need for Newstar? How can I ensure that the background sound plays even if the pages are refreshed? What should be done for this? Can you share the software codes? What should be the codes in the main file or in the audio player file that will be given for help? Will it be with Ajax or JS?
  • Now I created a code with artificial intelligence and integrated it into my own system everything is stable and works very well I configured the browser to prevent instant music playback with the click system but there is a problem here I couldn't solve it the problem is this

    "The song is playing but there is a momentary lag during page transitions how can I eliminate this, how can I fix this lag how can I fix the lag during page transitions"

    other than that the song continues without stopping this is nice on the other hand how can I fix this momentary lag I am sharing the code here can you help me friends

    JavaScript Source Code

    1. <script type="text/javascript">
    2. const playlist = [
    3. "music1.mp3",
    4. "music2.mp3",
    5. "music3.mp3",
    6. "music4.mp3",
    7. "music5.mp3",
    8. "music6.mp3",
    9. "music7.mp3",
    10. "music8.mp3",
    11. "music9.mp3",
    12. "music10.mp3",
    13. ];
    14. // Şu anda çalan şarkıyı ve süreyi sessionStorage'dan al
    15. let currentTrackIndex = sessionStorage.getItem("currentTrackIndex")
    16. ? parseInt(sessionStorage.getItem("currentTrackIndex"))
    17. : 0;
    18. let currentTime = sessionStorage.getItem("currentTime")
    19. ? parseFloat(sessionStorage.getItem("currentTime"))
    20. : 0;
    21. // Şarkıyı başlat
    22. const audio = new Audio();
    23. audio.src = playlist[currentTrackIndex];
    24. audio.currentTime = currentTime;
    25. audio.volume = 0.5;
    26. // Sayfa değişiminde müzik durmadan devam etmesi için event listener
    27. window.addEventListener("beforeunload", function () {
    28. sessionStorage.setItem("currentTime", audio.currentTime);
    29. sessionStorage.setItem("currentTrackIndex", currentTrackIndex);
    30. });
    31. // Eğer şarkı bitmişse bir sonraki şarkıya geç, döngüye girsin
    32. audio.addEventListener("ended", function () {
    33. currentTrackIndex = (currentTrackIndex + 1) % playlist.length;
    34. sessionStorage.setItem("currentTrackIndex", currentTrackIndex);
    35. sessionStorage.setItem("currentTime", 0);
    36. audio.src = playlist[currentTrackIndex];
    37. audio.play();
    38. });
    39. // Müzik çalmaya başla
    40. audio
    41. .play()
    42. .catch((error) => console.log("Otomatik oynatma engellendi:", error));
    43. // 1 saniye sonra müzik devam etmiyor mu diye kontrol et, devam etmiyorsa tekrar başlat
    44. setInterval(function () {
    45. if (audio.paused) {
    46. audio.play();
    47. }
    48. }, 1000);
    49. // Kullanıcı etkileşimi ile müzik çalmaya başla
    50. document.body.addEventListener("click", function () {
    51. if (audio.paused) {
    52. audio.play().catch((error) => {
    53. console.log("Hala müzik çalmıyor:", error);
    54. });
    55. }
    56. });
    57. </script>
    Display All

    The post was edited 1 time, last by Danter14 ().

  • in my version -look at the link thread/350-style-backgroundmusic/

    i have used a welcome sound wich play's instant, but the music plays only at user's choice.
    sound plays continously while switching through the pages of the game. but it has a button for toggle play / pause...

    maybe important: i don't play mp3 files, only radiostreams.
    Es zählt nicht wie lang man lebt, sondern wie intensiv.Euer Mond ist meine Sonne, Euer Montag - mein Sonntag.Musik ist Leben!

    ⭐Psy Love Is My Love⭐