Updated audio player on portfolio page
This commit is contained in:
1 parent
a6edfc9f7e
commit
92d7fba166
3 files changed
+56
-2
No files matched your search
@@ -15,6 +15,34 @@
|
|||||||
border-radius: 25px;
|
border-radius: 25px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.volume-control input[type="range"] {
|
||||||
|
-webkit-appearance: none;
|
||||||
|
width: 150px;
|
||||||
|
background: #43497e;
|
||||||
|
border-radius: 15px;
|
||||||
|
height: 6px;
|
||||||
|
margin-bottom: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.volume-control input[type="range"]::-moz-range-thumb {
|
||||||
|
-webkit-appearance: none;
|
||||||
|
height: 16px;
|
||||||
|
width: 16px;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: #ffffff;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
margin-top: -6px; /* align with track */
|
||||||
|
}
|
||||||
|
|
||||||
|
.volume-control input[type="range"]::-moz-range-progress {
|
||||||
|
width: 150px;
|
||||||
|
background: #818aec;
|
||||||
|
border-radius: 15px;
|
||||||
|
height: 6px;
|
||||||
|
margin-bottom: 3px;;
|
||||||
|
}
|
||||||
|
|
||||||
.audio-player {
|
.audio-player {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 10px;
|
bottom: 10px;
|
||||||
|
|||||||
@@ -1,11 +1,21 @@
|
|||||||
<div class="audio-player">
|
<div class="audio-player">
|
||||||
<div id="youtube-player"></div>
|
<div id="youtube-player"></div>
|
||||||
|
<h3>{{ nowPlayingTitle() }}</h3>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<button (click)="previousVideo()" [disabled]="!isPlayerReady"><i class="fa-solid fa-backward"></i></button>
|
<button (click)="previousVideo()" [disabled]="!isPlayerReady"><i class="fa-solid fa-backward"></i></button>
|
||||||
<button (click)="togglePlayPause()" [disabled]="!isPlayerReady">
|
<button (click)="togglePlayPause()" [disabled]="!isPlayerReady">
|
||||||
<i class="{{ isPlaying() ? 'fa-solid fa-pause' : 'fa-solid fa-play'}}"></i>
|
<i class="{{ isPlaying() ? 'fa-solid fa-pause' : 'fa-solid fa-play'}}"></i>
|
||||||
</button>
|
</button>
|
||||||
<button (click)="nextVideo()" [disabled]="!isPlayerReady"><i class="fa-solid fa-forward"></i></button>
|
<button (click)="nextVideo()" [disabled]="!isPlayerReady"><i class="fa-solid fa-forward"></i></button>
|
||||||
<h3>{{ nowPlayingTitle() }}</h3>
|
<div class="volume-control" *ngIf="isPlayerReady()">
|
||||||
|
<input
|
||||||
|
id="volume"
|
||||||
|
type="range"
|
||||||
|
min="0"
|
||||||
|
max="100"
|
||||||
|
[value]="volume()"
|
||||||
|
(input)="onVolumeChange($event)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import {Component, AfterViewInit, signal} from '@angular/core';
|
import {Component, AfterViewInit, signal} from '@angular/core';
|
||||||
|
import {NgIf} from '@angular/common';
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
@@ -9,7 +10,9 @@ declare global {
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-audio-player',
|
selector: 'app-audio-player',
|
||||||
imports: [],
|
imports: [
|
||||||
|
NgIf
|
||||||
|
],
|
||||||
templateUrl: './audio-player.component.html',
|
templateUrl: './audio-player.component.html',
|
||||||
styleUrl: './audio-player.component.css'
|
styleUrl: './audio-player.component.css'
|
||||||
})
|
})
|
||||||
@@ -40,6 +43,7 @@ export class AudioPlayerComponent implements AfterViewInit {
|
|||||||
events: {
|
events: {
|
||||||
onReady: () => {
|
onReady: () => {
|
||||||
this.isPlayerReady.set(true);
|
this.isPlayerReady.set(true);
|
||||||
|
this.player.setVolume(this.volume());
|
||||||
console.log('YouTube Player Ready');
|
console.log('YouTube Player Ready');
|
||||||
|
|
||||||
const iframe = document.getElementById('youtube-player') as HTMLIFrameElement | null;
|
const iframe = document.getElementById('youtube-player') as HTMLIFrameElement | null;
|
||||||
@@ -105,4 +109,16 @@ export class AudioPlayerComponent implements AfterViewInit {
|
|||||||
this.player.previousVideo();
|
this.player.previousVideo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
volume = signal(50);
|
||||||
|
|
||||||
|
onVolumeChange(event: Event) {
|
||||||
|
const target = event.target as HTMLInputElement;
|
||||||
|
const newVolume = parseInt(target.value, 10);
|
||||||
|
|
||||||
|
if (this.isPlayerReady() && this.player?.setVolume) {
|
||||||
|
this.player.setVolume(newVolume);
|
||||||
|
this.volume.set(newVolume);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user