-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.php
168 lines (150 loc) · 5.43 KB
/
player.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
if (isset($_GET['feed_url'])) {
$feedUrl = $_GET['feed_url'];
$xml = simplexml_load_file($feedUrl);
$podcast = [
'title' => (string) $xml->channel->title,
'description' => (string) $xml->channel->description,
'artwork' => (string) $xml->channel->image->url,
'episodes' => [],
];
foreach ($xml->channel->item as $item) {
$episode = [
'title' => (string) $item->title,
'description' => (string) $item->description,
'audioUrl' => (string) $item->enclosure['url'],
];
$podcast['episodes'][] = $episode;
}
} else {
header('Location: index.php');
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Podcast Player</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="styles.css?v=1791">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
</head>
<body>
<nav>
<div class="container">
<a href="index.php" class="logo">Podcast Player</a>
<ul class="nav-items">
<li><a href="index.php">Home</a></li>
<li><a href="https://pocketbarista.uk/pod/index.php?search_term=politics">Politics</a></li>
<li><a href="https://pocketbarista.uk/pod/index.php?search_term=music">Music</a></li>
<li><a href="https://pocketbarista.uk/pod/index.php?search_term=comedy">Comedy</a></li>
<li><a href="https://pocketbarista.uk/pod/index.php?search_term=BBC">BBC</a></li>
</ul>
<div class="nav-toggle">
<i class="fas fa-bars"></i>
</div>
</div>
</nav>
<div id="podcast-player">
<div class="container">
<div class="player-info">
<img id="podcast-artwork" src="<?php echo $podcast['artwork']; ?>" alt="Podcast Artwork">
<div class="podcast-details">
<h1 id="podcast-title"><?php echo $podcast['title']; ?></h1>
<p id="podcast-description"><?php echo $podcast['description']; ?></p>
</div>
</div>
<div id="player-container">
<audio id="audio-player" controls></audio>
<div id="player-controls">
<button id="prev-button"><i class="fas fa-step-backward"></i></button>
<button id="play-pause-button"><i class="fas fa-play"></i></button>
<button id="next-button"><i class="fas fa-step-forward"></i></button>
</div>
</div>
<div id="episode-list">
<?php foreach ($podcast['episodes'] as $index => $episode) { ?>
<div class="episode" data-audio-url="<?php echo $episode['audioUrl']; ?>" data-index="<?php echo $index; ?>">
<h3><?php echo $episode['title']; ?></h3>
<p><?php echo $episode['description']; ?></p>
</div>
<?php } ?>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
const episodeElements = document.querySelectorAll('.episode');
const audioPlayer = document.getElementById('audio-player');
const playPauseButton = document.getElementById('play-pause-button');
// Automatically select and play the first episode if no episode is selected
if (!document.querySelector('.episode.active')) {
const firstEpisode = episodeElements[0];
if (firstEpisode) {
const audioUrl = firstEpisode.dataset.audioUrl;
const index = firstEpisode.dataset.index;
playEpisode(audioUrl, index);
}
}
episodeElements.forEach(episode => {
episode.addEventListener('click', () => {
const audioUrl = episode.dataset.audioUrl;
const index = episode.dataset.index;
playEpisode(audioUrl, index);
});
});
function playEpisode(audioUrl, index) {
audioPlayer.src = audioUrl;
audioPlayer.play();
episodeElements.forEach((episode, i) => {
if (i == index) {
episode.classList.add('active');
} else {
episode.classList.remove('active');
}
});
updatePlayPauseButton();
}
function updatePlayPauseButton() {
if (audioPlayer.paused) {
playPauseButton.innerHTML = '<i class="fas fa-play"></i>';
} else {
playPauseButton.innerHTML = '<i class="fas fa-pause"></i>';
}
}
audioPlayer.addEventListener('play', updatePlayPauseButton);
audioPlayer.addEventListener('pause', updatePlayPauseButton);
playPauseButton.addEventListener('click', togglePlayPause);
function togglePlayPause() {
if (audioPlayer.paused) {
audioPlayer.play();
} else {
audioPlayer.pause();
}
}
const prevButton = document.getElementById('prev-button');
const nextButton = document.getElementById('next-button');
prevButton.addEventListener('click', playPrevEpisode);
nextButton.addEventListener('click', playNextEpisode);
function playPrevEpisode() {
const currentEpisode = document.querySelector('.episode.active');
const prevEpisode = currentEpisode.previousElementSibling;
if (prevEpisode) {
const audioUrl = prevEpisode.dataset.audioUrl;
const index = prevEpisode.dataset.index;
playEpisode(audioUrl, index);
}
}
function playNextEpisode() {
const currentEpisode = document.querySelector('.episode.active');
const nextEpisode = currentEpisode.nextElementSibling;
if (nextEpisode) {
const audioUrl = nextEpisode.dataset.audioUrl;
const index = nextEpisode.dataset.index;
playEpisode(audioUrl, index);
}
}
});
</script>
</body>
</html>