From 4b5cb750cffc51a331233246f4c017a417099c38 Mon Sep 17 00:00:00 2001 From: itzMiney Date: Sun, 6 Apr 2025 23:09:08 +0200 Subject: [PATCH] added audio player to portfolio --- src/app/portfolio/portfolio.component.css | 3 +- src/app/portfolio/portfolio.component.html | 1 + src/app/portfolio/portfolio.component.ts | 4 +- .../audio-player/audio-player.component.css | 31 +++++ .../audio-player/audio-player.component.html | 11 ++ .../audio-player/audio-player.component.ts | 108 ++++++++++++++++++ src/index.html | 1 + 7 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 src/app/shared/audio-player/audio-player.component.css create mode 100644 src/app/shared/audio-player/audio-player.component.html create mode 100644 src/app/shared/audio-player/audio-player.component.ts diff --git a/src/app/portfolio/portfolio.component.css b/src/app/portfolio/portfolio.component.css index a2ffcd0..e4493ee 100644 --- a/src/app/portfolio/portfolio.component.css +++ b/src/app/portfolio/portfolio.component.css @@ -118,7 +118,8 @@ } hr.rounded { - border-top: 4px solid #ffffff; + border: 2px solid white; + width: 40px; max-width: 40px; border-radius: 5px; } diff --git a/src/app/portfolio/portfolio.component.html b/src/app/portfolio/portfolio.component.html index c0717cc..e8efad7 100644 --- a/src/app/portfolio/portfolio.component.html +++ b/src/app/portfolio/portfolio.component.html @@ -60,3 +60,4 @@ + diff --git a/src/app/portfolio/portfolio.component.ts b/src/app/portfolio/portfolio.component.ts index fe471c1..b0e4234 100644 --- a/src/app/portfolio/portfolio.component.ts +++ b/src/app/portfolio/portfolio.component.ts @@ -3,11 +3,13 @@ import {VantaBackgroundService} from '../shared/services/vanta-background.servic import {DeviceDetectorService} from '../shared/services/device-detector.service'; import {isPlatformBrowser, NgStyle} from '@angular/common'; import {Title} from '@angular/platform-browser'; +import {AudioPlayerComponent} from '../shared/audio-player/audio-player.component'; @Component({ selector: 'app-portfolio', imports: [ - NgStyle + NgStyle, + AudioPlayerComponent ], templateUrl: './portfolio.component.html', styleUrl: './portfolio.component.css' diff --git a/src/app/shared/audio-player/audio-player.component.css b/src/app/shared/audio-player/audio-player.component.css new file mode 100644 index 0000000..f915a48 --- /dev/null +++ b/src/app/shared/audio-player/audio-player.component.css @@ -0,0 +1,31 @@ +.controls { + display: flex; + align-items: center; + gap: 10px; +} + +.controls button { + font-family: Roboto, sans-serif; + font-size: 1rem; + font-weight: 500; + border: none; + padding: 10px; + height: 42px; + width: 42px; + border-radius: 25px; +} + +.audio-player { + position: fixed; + bottom: 10px; + left: 20px; + z-index: 10; +} + +.audio-player h3 { + margin-left: 15px; + text-align: center; + font-family: Roboto, sans-serif; + font-weight: 500; + color: white; +} diff --git a/src/app/shared/audio-player/audio-player.component.html b/src/app/shared/audio-player/audio-player.component.html new file mode 100644 index 0000000..ee32331 --- /dev/null +++ b/src/app/shared/audio-player/audio-player.component.html @@ -0,0 +1,11 @@ +
+
+
+ + + +

{{ nowPlayingTitle() }}

+
+
diff --git a/src/app/shared/audio-player/audio-player.component.ts b/src/app/shared/audio-player/audio-player.component.ts new file mode 100644 index 0000000..bf05bc4 --- /dev/null +++ b/src/app/shared/audio-player/audio-player.component.ts @@ -0,0 +1,108 @@ +import {Component, AfterViewInit, signal} from '@angular/core'; + +declare global { + interface Window { + onYouTubeIframeAPIReady: () => void; + YT: any; + } +} + +@Component({ + selector: 'app-audio-player', + imports: [], + templateUrl: './audio-player.component.html', + styleUrl: './audio-player.component.css' +}) +export class AudioPlayerComponent implements AfterViewInit { + private player: any; + isPlayerReady = signal(false); + isPlaying = signal(false); + nowPlayingTitle = signal(''); + + ngAfterViewInit() { + if (window.YT && window.YT.Player) { + this.createPlayer(); + } else { + window.onYouTubeIframeAPIReady = () => this.createPlayer(); + } + } + + createPlayer() { + this.player = new window.YT.Player('youtube-player', { + height: '0', // or something minimal + width: '0', + playerVars: { + listType: 'playlist', + list: 'PLukBTTWD2ebbIa_RDec_razIHz6e6Wh8b', + autoplay: 0, + controls: 0, + }, + events: { + onReady: () => { + this.isPlayerReady.set(true); + console.log('YouTube Player Ready'); + + const iframe = document.getElementById('youtube-player') as HTMLIFrameElement | null; + if (iframe) { + iframe.style.width = '0px'; + iframe.style.height = '0px'; + iframe.style.opacity = '0'; + iframe.style.pointerEvents = 'none'; + iframe.style.position = 'absolute'; + iframe.style.zIndex = '-1'; + } + + this.updateNowPlayingTitle(); + }, + onStateChange: (event: any) => { + if (event.data === window.YT.PlayerState.PLAYING) { + this.updateNowPlayingTitle(); + } + } + } + }); + } + + updateNowPlayingTitle() { + if (this.player) { + const videoData = this.player.getVideoData(); + this.nowPlayingTitle.set(videoData.title); + } + } + + playVideo() { + if (this.isPlayerReady() && this.player?.playVideo) { + this.player.playVideo(); + this.isPlaying.set(true); + } + } + + pauseVideo() { + if (this.isPlayerReady() && this.player?.pauseVideo) { + this.player.pauseVideo(); + this.isPlaying.set(false); + } + } + + togglePlayPause() { + if (!this.isPlayerReady()) return; + + if (this.isPlaying()) { + this.pauseVideo(); + } else { + this.playVideo(); + } + } + + nextVideo() { + if (this.isPlayerReady() && this.player?.nextVideo) { + this.player.nextVideo(); + } + } + + previousVideo() { + if (this.isPlayerReady() && this.player?.previousVideo) { + this.player.previousVideo(); + } + } +} diff --git a/src/index.html b/src/index.html index d7eed86..aed78e8 100644 --- a/src/index.html +++ b/src/index.html @@ -1,6 +1,7 @@ + itzMiney's Home