-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
60 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,70 @@ | ||
let isPlaying = false; | ||
let currentSong = null; | ||
let currentSong = null; | ||
|
||
async function loadSongs() { | ||
try { | ||
const response = await fetch('https://raw.githubusercontent.com/emadadel4/Soura/main/assets/db.json'); | ||
if (!response.ok) { | ||
throw new Error(`HTTP error! Status: ${response.status}`); | ||
} | ||
const data = await response.json(); | ||
playSong(data); | ||
} catch (error) { | ||
console.error('Error fetching the song list:', error); | ||
async function loadSoura() { | ||
try { | ||
const response = await fetch('https://raw.githubusercontent.com/emadadel4/Soura/main/assets/db.json'); // Replace with actual URL | ||
if (!response.ok) { | ||
throw new Error(`HTTP error! Status: ${response.status}`); | ||
} | ||
const data = await response.json(); | ||
playSoura(data); | ||
} catch (error) { | ||
console.error('Error fetching the song list:', error); | ||
} | ||
} | ||
|
||
function playSong(data) { | ||
const today = new Date(); | ||
const dayOfYear = Math.floor((today - new Date(today.getFullYear(), 0, 0)) / (1000 * 60 * 60 * 24)); | ||
const selectedSong = data[dayOfYear % data.length]; | ||
const audioPlayer = document.getElementById('audioPlayer'); | ||
const songTitle = document.getElementById('songTitle'); | ||
function playSoura(data) { | ||
const today = new Date(); | ||
const startOfYear = new Date(today.getFullYear(), 0, 1); | ||
const dayOfYear = Math.floor((today - startOfYear) / (1000 * 60 * 60 * 24)); | ||
const songIndex = dayOfYear % data.length; // Ensure the index is within the bounds of the array | ||
const selectedSong = data[songIndex]; | ||
const audioPlayer = document.getElementById('audioPlayer'); | ||
const songTitle = document.getElementById('songTitle'); | ||
|
||
if (selectedSong) { | ||
if (currentSong !== selectedSong.url) { | ||
audioPlayer.src = selectedSong.url; | ||
audioPlayer.load(); | ||
currentSong = selectedSong.url; | ||
} | ||
|
||
songTitle.textContent = `اليوم سورة: ${selectedSong.name}`; | ||
if (selectedSong) { | ||
if (currentSong !== selectedSong.url) { | ||
audioPlayer.src = selectedSong.url; | ||
audioPlayer.load(); | ||
currentSong = selectedSong.url; | ||
} | ||
|
||
// Retrieve and set playback time | ||
const savedTime = localStorage.getItem('audioTime'); | ||
if (savedTime) { | ||
audioPlayer.currentTime = parseFloat(savedTime); | ||
} | ||
songTitle.textContent = `اليوم سورة: ${selectedSong.name}`; | ||
|
||
// Save playback time periodically | ||
audioPlayer.addEventListener('timeupdate', () => { | ||
localStorage.setItem('audioTime', audioPlayer.currentTime); | ||
}); | ||
} else { | ||
songTitle.textContent = 'Song not found'; | ||
console.error('Selected song not found.'); | ||
// Retrieve and set playback time | ||
const savedTime = localStorage.getItem('audioTime'); | ||
if (savedTime) { | ||
audioPlayer.currentTime = parseFloat(savedTime); | ||
} | ||
} | ||
|
||
function togglePlayPause() { | ||
const button = document.getElementById('playPauseButton'); | ||
const audioPlayer = document.getElementById('audioPlayer'); | ||
const icon = button.querySelector('i'); | ||
// Save playback time periodically | ||
audioPlayer.addEventListener('timeupdate', () => { | ||
localStorage.setItem('audioTime', audioPlayer.currentTime); | ||
}); | ||
} else { | ||
songTitle.textContent = 'Song not found'; | ||
console.error('Selected song not found.'); | ||
} | ||
} | ||
|
||
if (isPlaying) { | ||
audioPlayer.pause(); | ||
button.classList.replace('pause', 'play'); | ||
icon.classList.replace('fa-pause', 'fa-play'); | ||
} else { | ||
audioPlayer.play(); | ||
button.classList.replace('play', 'pause'); | ||
icon.classList.replace('fa-play', 'fa-pause'); | ||
} | ||
function togglePlayPause() { | ||
const button = document.getElementById('playPauseButton'); | ||
const audioPlayer = document.getElementById('audioPlayer'); | ||
const icon = button.querySelector('i'); | ||
|
||
isPlaying = !isPlaying; | ||
if (isPlaying) { | ||
audioPlayer.pause(); | ||
button.classList.replace('pause', 'play'); | ||
icon.classList.replace('fa-pause', 'fa-play'); | ||
} else { | ||
audioPlayer.play(); | ||
button.classList.replace('play', 'pause'); | ||
icon.classList.replace('fa-play', 'fa-pause'); | ||
} | ||
|
||
// Initialize and load the song list | ||
loadSongs(); | ||
isPlaying = !isPlaying; | ||
} | ||
|
||
// Initialize and load the song list | ||
loadSoura(); |