Skip to content

Commit 270555f

Browse files
committed
update
1 parent dc3046c commit 270555f

3 files changed

Lines changed: 24 additions & 10 deletions

File tree

25.9 KB
Loading

src/app/features/music/music.component.html

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<!-- Songs List -->
1313
<div *ngFor="let song of songs()"
1414
class="flex items-center gap-4 py-4 px-2 rounded-md hover:bg-[var(--list-hover)] transition-all cursor-pointer"
15-
[class.bg-[var(--list-hover)]]="currentSong?.url === getSongUrl(song)">
16-
<div class="relative w-12 h-12 rounded-md overflow-hidden group" (click)="playSong(getSongUrl(song), song)">
15+
(click)="playSong(getSongUrl(song), song)">
16+
<div class="relative w-12 h-12 rounded-md overflow-hidden group">
1717
<img [src]="song.image?.[2]?.url || 'assets/img/music_icon/icons8-airpods-pro-max-100.png'" alt="{{ song.name }}"
1818
class="w-full h-full object-cover group-hover:brightness-75 transition-all duration-300 ease-in-out"
1919
[class.brightness-75]="currentSong?.url === getSongUrl(song)" />
@@ -22,14 +22,21 @@
2222
class="absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity duration-300"
2323
[class.opacity-100]="currentSong?.url === getSongUrl(song)">
2424
<img
25-
[src]="currentSong?.url === getSongUrl(song)? 'assets/img/music_icon/icons8-pause-50.png' :'assets/img/music_icon/icons8-play-50.png'"
25+
[src]="((audio?.paused)) ? 'assets/img/music_icon/icons8-play-50.png' : currentSong?.url === getSongUrl(song) ?'assets/img/music_icon/icons8-pause-50.png' : 'assets/img/music_icon/icons8-play-50.png'"
2626
alt="Play" class="w-6 h-6 object-contain" style="filter: invert(100%);" />
2727
</div>
2828
</div>
2929

3030
<div class="flex-1">
31-
<div class="font-medium text-[var(--color-text)]">{{ song.name }}</div>
32-
<div class="text-sm text-[var(--color-gray-500)]">{{ song.artists.primary[0]?.name || 'Unknown Artist' }}</div>
31+
<div class="flex items-center space-x-2 font-medium"
32+
[ngClass]="currentSong?.url === getSongUrl(song) ? 'text-[var(--theme-color)]' : 'text-[var(--color-text)]'">
33+
<img *ngIf="currentSong?.url === getSongUrl(song)" src="assets/img/music_icon/waves.gif"
34+
alt="playing animation" class="w-5 h-5" />
35+
<span>{{ song.name }}</span>
36+
</div>
37+
<div class="text-sm text-[var(--color-gray-500)]">
38+
{{ song.artists.primary[0]?.name || 'Unknown Artist' }}
39+
</div>
3340
</div>
3441

3542
<div class="text-sm text-[var(--color-gray-500)]">{{ formatTime(song.duration) }}</div>
@@ -43,7 +50,8 @@
4350
[ngStyle]="{'background-color': 'var(--color-surface)', 'color': 'var(--color-text)', 'z-index': '70'}">
4451

4552
<!-- Song Image -->
46-
<img (click)="openPlayerModal()" [src]="currentSong.image?.[2]?.url || 'assets/img/music_icon/icons8-airpods-pro-max-100.png'" alt="Cover"
53+
<img (click)="openPlayerModal()"
54+
[src]="currentSong.image?.[2]?.url || 'assets/img/music_icon/icons8-airpods-pro-max-100.png'" alt="Cover"
4755
class="w-12 h-12 rounded-md shadow-md shrink-0" />
4856

4957
<!-- Song Info + Progress -->
@@ -62,7 +70,7 @@
6270
</div>
6371

6472
<!-- Play/Pause Button -->
65-
<button (click)="playSong(currentSong.url, currentSong); $event.stopPropagation();"
73+
<button (click)="playSong(currentSong.url, currentSong, true); $event.stopPropagation();"
6674
class="w-8 h-8 flex items-center justify-center rounded-full hover:bg-[var(--list-hover)] active:scale-90 transition-transform">
6775
<img
6876
[src]="audio?.paused ? 'assets/img/music_icon/icons8-play-50.png' : 'assets/img/music_icon/icons8-pause-50.png'"
@@ -159,7 +167,7 @@ <h2 class="text-xl md:text-2xl font-semibold text-[var(--color-text)] truncate">
159167
</button>
160168

161169
<!-- Play/Pause -->
162-
<button (click)="playSong(currentSong.url, currentSong)"
170+
<button (click)="playSong(currentSong.url, currentSong, true)"
163171
class="bg-[var(--theme-color)] p-4 rounded-full active:scale-90 transition-transform">
164172
<img [src]="audio?.paused
165173
? 'assets/img/music_icon/icons8-play-50.png'

src/app/features/music/music.component.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,19 @@ export class MusicComponent implements OnDestroy {
9999
*
100100
* @param url URL of the song to play
101101
* @param song Song object
102+
* @param isbuttonClick Indicates if the play/pause was triggered by a button click
102103
*/
103-
playSong(url: string, song: any): void {
104+
playSong(url: string, song: any, isbuttonClick: boolean = false): void {
104105
if (!this.isBrowser) return;
105106
if (!this.audio) this.audio = new Audio();
106107

107108
if (this.currentSong?.url === url) {
108-
this.audio.paused ? this.audio.play() : this.audio.pause();
109+
if (isbuttonClick) {
110+
this.audio.paused ? this.audio.play() : this.audio.pause();
111+
}
112+
else {
113+
this.audio.play();
114+
}
109115
} else {
110116
this.audio.src = url;
111117
this.audio.play();

0 commit comments

Comments
 (0)