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?
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.
-
-
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⭐ -
There is no pause while switching pages, right?
-
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
- <script type="text/javascript">
- const playlist = [
- "music1.mp3",
- "music2.mp3",
- "music3.mp3",
- "music4.mp3",
- "music5.mp3",
- "music6.mp3",
- "music7.mp3",
- "music8.mp3",
- "music9.mp3",
- "music10.mp3",
- ];
- // Şu anda çalan şarkıyı ve süreyi sessionStorage'dan al
- let currentTrackIndex = sessionStorage.getItem("currentTrackIndex")
- ? parseInt(sessionStorage.getItem("currentTrackIndex"))
- : 0;
- let currentTime = sessionStorage.getItem("currentTime")
- ? parseFloat(sessionStorage.getItem("currentTime"))
- : 0;
- // Şarkıyı başlat
- const audio = new Audio();
- audio.src = playlist[currentTrackIndex];
- audio.currentTime = currentTime;
- audio.volume = 0.5;
- // Sayfa değişiminde müzik durmadan devam etmesi için event listener
- window.addEventListener("beforeunload", function () {
- sessionStorage.setItem("currentTime", audio.currentTime);
- sessionStorage.setItem("currentTrackIndex", currentTrackIndex);
- });
- // Eğer şarkı bitmişse bir sonraki şarkıya geç, döngüye girsin
- audio.addEventListener("ended", function () {
- currentTrackIndex = (currentTrackIndex + 1) % playlist.length;
- sessionStorage.setItem("currentTrackIndex", currentTrackIndex);
- sessionStorage.setItem("currentTime", 0);
- audio.src = playlist[currentTrackIndex];
- audio.play();
- });
- // Müzik çalmaya başla
- audio
- .play()
- .catch((error) => console.log("Otomatik oynatma engellendi:", error));
- // 1 saniye sonra müzik devam etmiyor mu diye kontrol et, devam etmiyorsa tekrar başlat
- setInterval(function () {
- if (audio.paused) {
- audio.play();
- }
- }, 1000);
- // Kullanıcı etkileşimi ile müzik çalmaya başla
- document.body.addEventListener("click", function () {
- if (audio.paused) {
- audio.play().catch((error) => {
- console.log("Hala müzik çalmıyor:", error);
- });
- }
- });
- </script>
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⭐
-
Share
- Facebook 0
- Twitter 0
- Google Plus 0
- Reddit 0
-
Users Online 2
2 Guests