some cleanup n stuff ig

This commit is contained in:
itzMiney committed 2026-03-21 23:41:03 +01:00
1 parent aaa1468a15
commit 62eaea0182
8 files changed
+74 -38

No files matched your search

+4
View File
@@ -18,6 +18,10 @@
.title h2 {
margin: 10px;
background: linear-gradient(to top, #a0eddb 0%, #ffffff 100%);
-webkit-background-clip: text;
background-clip: text;
color: transparent;
}
.logo {
+1 -1
View File
@@ -18,7 +18,7 @@
<div class="main-separator"></div>
<div class="article-input-box">
<form #articleForm="ngForm" (ngSubmit)="submitArticle()">
<form (ngSubmit)="submitArticle()">
<div class="action-bar" [class.mobile]="isNarrow">
<input
id="editTitle"
@@ -54,6 +54,12 @@
align-items: center;
justify-content: center;
z-index: 10;
opacity: 0;
transition: all ease-in-out 0.2s;
}
.audio-player.visible {
opacity: 1;
}
.audio-player.mobile {
@@ -62,9 +68,8 @@
}
.audio-player h3 {
margin-left: 15px;
text-align: center;
font-family: Roboto, sans-serif;
text-align: center;
font-weight: 500;
color: white;
}
@@ -1,21 +1,21 @@
<div class="audio-player" [ngClass]="{ mobile: isNarrow }">
<div id="youtube-player"></div>
<h3>{{ nowPlayingTitle() }}</h3>
<div class="controls">
<button (click)="previousVideo()" [disabled]="!isPlayerReady()"><i class="fa-solid fa-backward"></i></button>
<button (click)="togglePlayPause()" [disabled]="!isPlayerReady()">
<i class="{{ isPlaying() ? 'fa-solid fa-pause' : 'fa-solid fa-play'}}"></i>
</button>
<button (click)="nextVideo()" [disabled]="!isPlayerReady()"><i class="fa-solid fa-forward"></i></button>
@if (isPlayerReady()) {
<div class="volume-control">
<input
id="volume"
type="range"
min="0"
max="100"
[value]="volume()"
(input)="onVolumeChange($event)"
<div class="audio-player" [ngClass]="{ mobile: isNarrow }" [class.visible]="isPlayerReady()">
<div id="youtube-player"></div>
<h3>{{ nowPlayingTitle() }}</h3>
<div class="controls">
<button (click)="previousVideo()" [disabled]="!isPlayerReady()"><i class="fa-solid fa-backward"></i></button>
<button (click)="togglePlayPause()" [disabled]="!isPlayerReady()">
<i class="{{ isPlaying() ? 'fa-solid fa-pause' : 'fa-solid fa-play'}}"></i>
</button>
<button (click)="nextVideo()" [disabled]="!isPlayerReady()"><i class="fa-solid fa-forward"></i></button>
@if (isPlayerReady()) {
<div class="volume-control">
<input
id="volume"
type="range"
min="0"
max="100"
[value]="volume()"
(input)="onVolumeChange($event)"
/>
</div>
}
@@ -25,6 +25,7 @@ export class AudioPlayerComponent implements AfterViewInit, OnInit {
isPlayerReady = signal(false);
isPlaying = signal(false);
nowPlayingTitle = signal<string>('');
volume = signal(50)
constructor(private deviceService: ViewportService) {}
@@ -33,16 +34,40 @@ export class AudioPlayerComponent implements AfterViewInit, OnInit {
}
ngAfterViewInit() {
if (window.YT && window.YT.Player) {
void this.loadYouTubeApi().then(() => {
this.createPlayer();
} else {
window.onYouTubeIframeAPIReady = () => this.createPlayer();
}
});
}
private loadYouTubeApi(): Promise<void> {
return new Promise((resolve) => {
if (window.YT?.Player) {
resolve();
return;
}
const existingScript = document.querySelector(
'script[src="https://www.youtube.com/iframe_api"]'
);
if (existingScript) {
window.onYouTubeIframeAPIReady = () => resolve();
return;
}
const script = document.createElement('script');
script.src = 'https://www.youtube.com/iframe_api';
script.async = true;
window.onYouTubeIframeAPIReady = () => resolve();
document.head.appendChild(script);
});
}
createPlayer() {
this.player = new window.YT.Player('youtube-player', {
height: '0', // or something minimal
height: '0',
width: '0',
playerVars: {
listType: 'playlist',
@@ -54,7 +79,6 @@ export class AudioPlayerComponent implements AfterViewInit, OnInit {
onReady: () => {
this.isPlayerReady.set(true);
this.player.setVolume(this.volume());
console.log('YouTube Player Ready');
const iframe = document.getElementById('youtube-player') as HTMLIFrameElement | null;
if (iframe) {
@@ -70,7 +94,13 @@ export class AudioPlayerComponent implements AfterViewInit, OnInit {
},
onStateChange: (event: any) => {
if (event.data === window.YT.PlayerState.PLAYING) {
this.isPlaying.set(true);
this.updateNowPlayingTitle();
} else if (
event.data === window.YT.PlayerState.PAUSED ||
event.data === window.YT.PlayerState.ENDED
) {
this.isPlaying.set(false);
}
}
}
@@ -120,15 +150,14 @@ export class AudioPlayerComponent implements AfterViewInit, OnInit {
}
}
volume = signal(50);
onVolumeChange(event: Event) {
const target = event.target as HTMLInputElement;
const newVolume = parseInt(target.value, 10);
this.volume.set(newVolume);
if (this.isPlayerReady() && this.player?.setVolume) {
this.player.setVolume(newVolume);
this.volume.set(newVolume);
}
}
}