-
Notifications
You must be signed in to change notification settings - Fork 10
Replace Radioplayer button with an in-page player #356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
ashhhleyyy
wants to merge
18
commits into
development
Choose a base branch
from
ash/new-player
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
eafa102
fix: make the currentAndNext script use the correct headings
ashhhleyyy 8938520
feat: add the URY Player(tm)
ashhhleyyy aefccfd
feat: link to radioplayer
ashhhleyyy ec4fcd6
fix: make start/stop not resume where it was paused off
ashhhleyyy fde5eef
feat: make the send message box not refresh the page
ashhhleyyy e0ecc5e
feat: warn user before closing tab while listening
ashhhleyyy 0bda210
fix: various style improvements on mobile
ashhhleyyy 8b0a941
fix: don't restart player when play button is repeatedly clicked
ashhhleyyy d82b3df
feat: more fixes for responsiveness
ashhhleyyy 181d820
fix: continue refreshing now playing after pause
ashhhleyyy 1e85427
Update error messages in case of no config
ColinRoitt 411a24d
update layout of player
ColinRoitt eaf4a2c
Balance controls to left and right, always show a now playing default…
ColinRoitt f1e3e6b
remove unused const
ColinRoitt bcd837d
add close button
ColinRoitt d5d78ef
adjust padding
ColinRoitt cc2fb9c
fix: final tweaks for accessibility and layout
ashhhleyyy 0068c96
feat: final fixes to JS i think
ashhhleyyy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| export function makePlayer(config) { | ||
| const { idPrefix, audioUrl, icecastStatusUrl } = config; | ||
| let player = new Audio(); | ||
| player.preload = 'none'; | ||
| const playPause = document.getElementById(`${idPrefix}-play`); | ||
| const volume = document.getElementById(`${idPrefix}-volume`); | ||
| const currentTrackTitle = document.getElementById(`${idPrefix}-track-title`); | ||
| const currentTrackArtist = document.getElementById(`${idPrefix}-track-artist`); | ||
| const currentTrackArtistContainer = document.getElementById(`${idPrefix}-track-artist-container`); | ||
| const closeButton = document.getElementById(`${idPrefix}-close`); | ||
|
|
||
| closeButton.addEventListener('click', () => { | ||
| playbackControls.pause(); | ||
| document.querySelector('.current-and-next-player').classList.add('closed'); | ||
| document.querySelectorAll('.listen-btn').forEach((ele) => ele.style.display = ''); | ||
| }); | ||
|
|
||
| function updateButton() { | ||
| if (player.paused) { | ||
| playPause.innerHTML = '<i class="fa fa-play"></i>'; | ||
| } else { | ||
| playPause.innerHTML = '<i class="fa fa-stop"></i>'; | ||
| } | ||
| } | ||
|
|
||
| let playbackError = false; | ||
|
|
||
| function markLoading() { | ||
| playPause.innerHTML = '<span class="player-load-dots" title="loading"><span>•</span><span>•</span><span>•</span></span>'; | ||
| } | ||
|
|
||
| function markError() { | ||
| playbackError = true; | ||
| playPause.disabled = true; | ||
| playPause.innerHTML = '<i class="fa fa-exclamation-triangle"></i>'; | ||
| } | ||
|
|
||
| function setNowPlaying(title, artist) { | ||
| currentTrackTitle.innerText = title; | ||
| currentTrackArtist.innerText = artist; | ||
| currentTrackArtistContainer.style.display = 'inline'; | ||
| if (artist === null) { | ||
| currentTrackTitle.innerText = "University Radio York" | ||
| currentTrackArtistContainer.style.display = 'none'; | ||
| } | ||
| } | ||
|
|
||
| let nowPlayingUpdate = null; | ||
|
|
||
| function fetchNowPlaying() { | ||
| fetch(icecastStatusUrl) | ||
| .then((resp) => { | ||
| if (!resp.ok) { | ||
| console.error('failed to fetch current track, has the icecastStatus been added to config?', resp.status, resp.statusText); | ||
| nowPlayingUpdate = setTimeout(fetchNowPlaying, 10_000); | ||
| return; | ||
| } else { | ||
| return resp.json(); | ||
| } | ||
| }) | ||
| .then((resp) => { | ||
| const stream = resp.icestats.source.filter((s) => s.listenurl.indexOf('/live-high-ogg') !== -1)[0]; | ||
| const { artist, title } = stream; | ||
|
|
||
| setNowPlaying(title, artist); | ||
|
|
||
| // Update every 10s | ||
| nowPlayingUpdate = setTimeout(fetchNowPlaying, 10_000); | ||
| }).catch((e) => { | ||
| console.error('failed to fetch now playing, has the icecastStatus been added to config?', e); | ||
| }); | ||
| } | ||
|
|
||
| const playbackControls = { | ||
| play() { | ||
| if (playbackError) { | ||
| console.log('playback error, has the audioUrl been set in config?'); | ||
| return; | ||
| } | ||
| if (!nowPlayingUpdate) { | ||
| fetchNowPlaying(); | ||
| } | ||
|
|
||
| if (!this.playing) { | ||
| player.src = audioUrl; | ||
| player.play(); | ||
| } | ||
| }, | ||
|
|
||
| pause() { | ||
| if (playbackError) { | ||
| console.error('playback error'); | ||
| return; | ||
| } | ||
| if (nowPlayingUpdate) { | ||
| clearTimeout(nowPlayingUpdate); | ||
| nowPlayingUpdate = null; | ||
| } | ||
|
|
||
| player.src = null; | ||
| player.srcObject = null; | ||
|
|
||
| updateButton(); | ||
| }, | ||
|
|
||
| setVolume(level) { | ||
| player.volume = level; | ||
| }, | ||
|
|
||
| get playing() { | ||
| return player.src !== null && !player.paused; | ||
| } | ||
| }; | ||
|
|
||
| player.addEventListener('waiting', () => { | ||
| if (playbackError) return; | ||
| markLoading(); | ||
| }) | ||
|
|
||
| player.addEventListener('pause', () => { | ||
| if (playbackError) return; | ||
| updateButton(); | ||
| }); | ||
|
|
||
| player.addEventListener('play', () => { | ||
| if (playbackError) return; | ||
| updateButton(); | ||
| }); | ||
|
|
||
| player.addEventListener('playing', () => { | ||
| if (playbackError) return; | ||
| updateButton(); | ||
| }); | ||
|
|
||
| player.addEventListener('ended', () => { | ||
| if (playbackError) return; | ||
| console.log('retrying load'); | ||
| player.load(); | ||
| }); | ||
|
|
||
| player.addEventListener('error', (ev) => { | ||
| console.log(ev); | ||
| markError(); | ||
| }); | ||
|
|
||
| playPause.addEventListener('click', () => { | ||
| if (player.paused) { | ||
| playbackControls.play(); | ||
| } else { | ||
| playbackControls.pause(); | ||
| } | ||
| }); | ||
|
|
||
| playbackControls.setVolume(parseInt(volume.value) / 11.0); | ||
| volume.addEventListener('input', () => { | ||
| playbackControls.setVolume(parseInt(volume.value) / 11.0); | ||
| }); | ||
|
|
||
| window.onbeforeunload = () => { | ||
| console.log('before unload'); | ||
| if (playbackControls.playing) { | ||
| return ''; | ||
| } | ||
| }; | ||
|
|
||
| return playbackControls; | ||
| } | ||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -10,3 +10,4 @@ | |
| @import "aprilFools"; | ||
| @import "show"; | ||
| @import "faq"; | ||
| @import "livePlayer"; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops