added audio player to portfolio
This commit is contained in:
1 parent
73e35736fb
commit
4b5cb750cf
7 files changed
+157
-2
No files matched your search
@@ -118,7 +118,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
hr.rounded {
|
hr.rounded {
|
||||||
border-top: 4px solid #ffffff;
|
border: 2px solid white;
|
||||||
|
width: 40px;
|
||||||
max-width: 40px;
|
max-width: 40px;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,3 +60,4 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<app-audio-player></app-audio-player>
|
||||||
@@ -3,11 +3,13 @@ import {VantaBackgroundService} from '../shared/services/vanta-background.servic
|
|||||||
import {DeviceDetectorService} from '../shared/services/device-detector.service';
|
import {DeviceDetectorService} from '../shared/services/device-detector.service';
|
||||||
import {isPlatformBrowser, NgStyle} from '@angular/common';
|
import {isPlatformBrowser, NgStyle} from '@angular/common';
|
||||||
import {Title} from '@angular/platform-browser';
|
import {Title} from '@angular/platform-browser';
|
||||||
|
import {AudioPlayerComponent} from '../shared/audio-player/audio-player.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-portfolio',
|
selector: 'app-portfolio',
|
||||||
imports: [
|
imports: [
|
||||||
NgStyle
|
NgStyle,
|
||||||
|
AudioPlayerComponent
|
||||||
],
|
],
|
||||||
templateUrl: './portfolio.component.html',
|
templateUrl: './portfolio.component.html',
|
||||||
styleUrl: './portfolio.component.css'
|
styleUrl: './portfolio.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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<div class="audio-player">
|
||||||
|
<div id="youtube-player"></div>
|
||||||
|
<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>
|
||||||
|
<h3>{{ nowPlayingTitle() }}</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -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<string>('');
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
|
<script src="https://www.youtube.com/iframe_api"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/vanta@latest/dist/vanta.net.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/vanta@latest/dist/vanta.net.min.js"></script>
|
||||||
<title>itzMiney's Home</title>
|
<title>itzMiney's Home</title>
|
||||||
|
|||||||
Reference in new issue
Block a user