Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
emadadel4 committed Aug 1, 2024
1 parent e7f1683 commit c8bf562
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 54 deletions.
4 changes: 4 additions & 0 deletions assets/db.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[
{
"name": "ألفتحة",
"url": "https://server8.mp3quran.net/afs/002.mp3"
},
{
"name": "البقرة",
"url": "https://server8.mp3quran.net/afs/002.mp3"
Expand Down
110 changes: 56 additions & 54 deletions assets/js/player.js
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();

0 comments on commit c8bf562

Please sign in to comment.