💄 Added indicator for the song that's currently playing in SongList.
Think about the details...
This commit is contained in:
parent
91a0cdfd57
commit
a476dcdc1a
@ -35,7 +35,7 @@ export class ControlsComponent implements OnInit {
|
|||||||
) { }
|
) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.audio.currentSong.subscribe(async id => {
|
this.audio.currentSong$.subscribe(async id => {
|
||||||
this.currentSong = await this.api.getSong(id);
|
this.currentSong = await this.api.getSong(id);
|
||||||
this.currentArtist = await this.currentSong.getArtist();
|
this.currentArtist = await this.currentSong.getArtist();
|
||||||
this.currentAlbum = await this.currentSong.getAlbum();
|
this.currentAlbum = await this.currentSong.getAlbum();
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
<tbody *ngIf="songsInfo">
|
<tbody *ngIf="songsInfo">
|
||||||
<tr *ngFor="let song of songsInfo; let i = index">
|
<tr *ngFor="let song of songsInfo; let i = index">
|
||||||
<th scope="row">{{ i + 1 }}</th>
|
<th scope="row">{{ i + 1 }}</th>
|
||||||
<th><fa-icon (click)="audio.setSong(songs[i])" [icon]="faPlay"></fa-icon></th>
|
<th><div [class]="song.id === currentSongId ? 'spinning' : ''"><fa-icon (click)="audio.setSong(songs[i])" [icon]="song.id === currentSongId ? faCompactDisc : faPlay"></fa-icon></div></th>
|
||||||
<td>{{ song.name }}</td>
|
<td>{{ song.name }}</td>
|
||||||
<td *ngIf="song.artistInfo">{{ song.artistInfo.name }}</td>
|
<td *ngIf="song.artistInfo">{{ song.artistInfo.name }}</td>
|
||||||
<td *ngIf="song.albumInfo">{{ song.albumInfo.name }}</td>
|
<td *ngIf="song.albumInfo">{{ song.albumInfo.name }}</td>
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
.spinning {
|
||||||
|
width: min-content;
|
||||||
|
height: min-content;
|
||||||
|
animation-name: spin;
|
||||||
|
animation-duration: 3000ms;
|
||||||
|
animation-iteration-count: infinite;
|
||||||
|
animation-timing-function: linear;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
from {
|
||||||
|
transform:rotate(0deg);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
transform:rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
import { Component, OnInit, Input } from '@angular/core';
|
import { Component, OnInit, Input } from '@angular/core';
|
||||||
import { Song, Artist, Album } from '../../classes/entities';
|
import { Song, Artist, Album } from '../../classes/entities';
|
||||||
import { faPlay } from '@fortawesome/free-solid-svg-icons';
|
import { faPlay, faPlayCircle, faCompactDisc } from '@fortawesome/free-solid-svg-icons';
|
||||||
import { AudioService } from 'src/app/services/audio.service';
|
import { AudioService } from 'src/app/services/audio.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -12,13 +12,20 @@ export class SonglistComponent implements OnInit {
|
|||||||
@Input() songs: Song[];
|
@Input() songs: Song[];
|
||||||
|
|
||||||
songsInfo = [];
|
songsInfo = [];
|
||||||
|
currentSongId: number;
|
||||||
|
|
||||||
// ? fontAwesome imports
|
// ? fontAwesome imports
|
||||||
faPlay = faPlay;
|
faPlay = faPlay;
|
||||||
|
faPlayCircle = faPlayCircle;
|
||||||
|
faCompactDisc = faCompactDisc;
|
||||||
|
|
||||||
constructor(public audio: AudioService) { }
|
constructor(public audio: AudioService) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
|
||||||
|
this.currentSongId = this.audio.currentSong;
|
||||||
|
this.audio.currentSong$.subscribe(id => this.currentSongId = id);
|
||||||
|
|
||||||
this.songs.forEach(song => {
|
this.songs.forEach(song => {
|
||||||
const index = this.songsInfo.push({}) - 1;
|
const index = this.songsInfo.push({}) - 1;
|
||||||
const result = {
|
const result = {
|
||||||
|
@ -23,11 +23,15 @@ export class AudioService {
|
|||||||
this.player.addEventListener('timeupdate', () => {
|
this.player.addEventListener('timeupdate', () => {
|
||||||
this.currentTime = this.player.currentTime;
|
this.currentTime = this.player.currentTime;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Make sure that the currentSong property equals the current song id.
|
||||||
|
this.currentSong$.subscribe(id => this.currentSong = id);
|
||||||
}
|
}
|
||||||
|
|
||||||
player = new Audio();
|
player = new Audio();
|
||||||
|
|
||||||
currentSong = new Subject<number>();
|
currentSong$ = new Subject<number>();
|
||||||
|
currentSong: number;
|
||||||
currentTime: number;
|
currentTime: number;
|
||||||
|
|
||||||
// Use audio.time to set the time
|
// Use audio.time to set the time
|
||||||
@ -82,6 +86,6 @@ export class AudioService {
|
|||||||
*/
|
*/
|
||||||
setSong(song: Song) {
|
setSong(song: Song) {
|
||||||
this.player.src = this.data.apiUrl + '/play/' + song.path;
|
this.player.src = this.data.apiUrl + '/play/' + song.path;
|
||||||
this.currentSong.next(song.id);
|
this.currentSong$.next(song.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user