This commit is contained in:
2026-03-20 11:30:15 +00:00
parent bde579e515
commit 831a9aa163
5 changed files with 43 additions and 33 deletions
+3 -3
View File
@@ -27,9 +27,9 @@ export class Analyser implements AfterViewInit {
this.canvas.style.height = `${this.height}px`; this.canvas.style.height = `${this.height}px`;
this.canvas.style.top = `-${this.height}px`; this.canvas.style.top = `-${this.height}px`;
document.onmousemove = (e: MouseEvent) => { document.onmousemove = (e: MouseEvent) => {
const cursorDistancefromBottom = document.documentElement.clientHeight - (e.clientY || 0); const cursorDistanceFromBottom = document.documentElement.clientHeight - (e.clientY || 0);
let offset = cursorDistancefromBottom - (this.bottomOffset + this.offsetBuffer); let offset = cursorDistanceFromBottom - (this.bottomOffset + this.offsetBuffer);
if (cursorDistancefromBottom < this.bottomOffset || cursorDistancefromBottom > (this.bottomOffset + this.height + this.offsetBuffer)) { if (cursorDistanceFromBottom < this.bottomOffset || cursorDistanceFromBottom > (this.bottomOffset + this.height + this.offsetBuffer)) {
offset = this.height; offset = this.height;
} }
this.canvas.style.height = `${offset}px`; this.canvas.style.height = `${offset}px`;
+3 -2
View File
@@ -1,9 +1,10 @@
export class FileSystemFile { export class FileSystemFile {
public filename: string;
constructor( constructor(
public filename: string,
public filepath: string, public filepath: string,
public size: number, public size: number,
) { ) {
this.filename = filepath.substring((filepath.lastIndexOf('/') || 0) + 1);
} }
} }
+11 -3
View File
@@ -14,11 +14,19 @@ Home<br/>
<button (click)="add($event)">Add</button> <button (click)="add($event)">Add</button>
<button (click)="remove($event)">Remove</button> <button (click)="remove($event)">Remove</button>
Files:
@for (item of files; track item) {
<div>
<a (click)="audio.addItem(item)">{{ item.file.filename }}</a>
</div>
}
Playlist:
@for (item of audio.list(); track item) { @for (item of audio.list(); track item) {
<div> <div>
@if ($index === audio.index()) { @if ($index === audio.index()) {
* *
} }
<a (click)="setIndex($index)">{{ item.track.file.filename }}</a> <a (click)="setIndex($index)">{{ item.track.file.filename }}</a>
</div> </div>
} }
+26 -1
View File
@@ -14,8 +14,33 @@ export class HomePage implements AfterViewInit{
@ViewChild('range') rangeRef!: ElementRef<HTMLInputElement>; @ViewChild('range') rangeRef!: ElementRef<HTMLInputElement>;
protected input!: HTMLInputElement; protected input!: HTMLInputElement;
protected audio: AudioService = inject(AudioService); protected audio: AudioService = inject(AudioService);
protected files: Track[] = [];
constructor() { constructor() {
this.files = [
new Track(
new FileSystemFile('audio/1.mp3', 0),
new TrackMeta(),
0,
'mp3',
0
),
new Track(
new FileSystemFile('audio/2.mp3', 0),
new TrackMeta(),
0,
'mp3',
0
),
new Track(
new FileSystemFile('audio/3.mp3', 0),
new TrackMeta(),
0,
'mp3',
0
),
];
effect(() => { effect(() => {
const progress = (this.audio.progress() || 0) * 100; const progress = (this.audio.progress() || 0) * 100;
if (this.input) this.input.value = `${progress}`; if (this.input) this.input.value = `${progress}`;
@@ -56,7 +81,7 @@ export class HomePage implements AfterViewInit{
add(event: Event): void { add(event: Event): void {
this.audio.addItem(new Track( this.audio.addItem(new Track(
new FileSystemFile('3.mp3', 'audio/3.mp3', 0), new FileSystemFile('3.mp3', 0),
new TrackMeta(), new TrackMeta(),
0, 0,
'mp3', 'mp3',
-24
View File
@@ -20,30 +20,6 @@ export class AudioService {
return current.currentTime() / current.duration(); return current.currentTime() / current.duration();
}) })
constructor() {
this.addItem(new Track(
new FileSystemFile('1.mp3', 'audio/1.mp3', 0),
new TrackMeta(),
0,
'mp3',
128
));
this.addItem(new Track(
new FileSystemFile('2.mp3', 'audio/2.mp3', 0),
new TrackMeta(),
0,
'mp3',
128
));
this.addItem(new Track(
new FileSystemFile('3.mp3', 'audio/3.mp3', 0),
new TrackMeta(),
0,
'mp3',
128
));
}
addItem(track: Track) { addItem(track: Track) {
const item = new PlaylistItem(track, this); const item = new PlaylistItem(track, this);
this.analyser.connectAudio(item); this.analyser.connectAudio(item);