Oviya
commited on
Commit
·
16002bb
1
Parent(s):
8e4fbd5
add listen
Browse files
src/app/listen/listen.component.ts
CHANGED
|
@@ -78,44 +78,48 @@ export class ListenComponent implements OnInit {
|
|
| 78 |
// }
|
| 79 |
//}
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
setTimeout(() => {
|
| 93 |
-
this.
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
this.popupMessage = '✅ Video uploaded successfully!';
|
| 106 |
-
setTimeout(() => this.popupMessage = '', 7000);
|
| 107 |
-
}, 1000);
|
| 108 |
-
});
|
| 109 |
-
},
|
| 110 |
-
error: (err) => {
|
| 111 |
-
console.error('Upload failed', err);
|
| 112 |
-
alert('❌ Video upload failed.');
|
| 113 |
-
}
|
| 114 |
-
});
|
| 115 |
-
} else {
|
| 116 |
-
alert('Please upload a valid MP4 file.');
|
| 117 |
-
}
|
| 118 |
}
|
|
|
|
|
|
|
| 119 |
|
| 120 |
|
| 121 |
onVideoEnded(): void {
|
|
|
|
| 78 |
// }
|
| 79 |
//}
|
| 80 |
|
| 81 |
+
|
| 82 |
+
onFileSelected(event: any): void {
|
| 83 |
+
const file = event.target.files[0];
|
| 84 |
+
if (file && file.name.toLowerCase().endsWith('.mp4')) {
|
| 85 |
+
this.selectedFile = file;
|
| 86 |
+
const formData = new FormData();
|
| 87 |
+
formData.append('video', file);
|
| 88 |
+
|
| 89 |
+
this.listenService.uploadVideo(formData).subscribe({
|
| 90 |
+
next: (response) => {
|
| 91 |
+
// Use backend /media/videos/<filename> path for preview (works both local & HF)
|
| 92 |
+
const newVideoUrl = this.listenService.getVideoUrl(response.filename);
|
| 93 |
+
|
| 94 |
+
this.videoUrl = ''; // Reset first to force re-binding
|
| 95 |
+
setTimeout(() => {
|
| 96 |
+
this.videoUrl = newVideoUrl;
|
| 97 |
+
|
| 98 |
+
const videoElement = document.getElementById('videoPreview') as HTMLVideoElement;
|
| 99 |
+
if (videoElement) {
|
| 100 |
+
videoElement.load(); // Reload the video player
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
this.uploadSuccess = true;
|
| 104 |
+
this.isGenerateEnabled = false;
|
| 105 |
+
this.isVideoPlaying = false;
|
| 106 |
+
|
| 107 |
setTimeout(() => {
|
| 108 |
+
this.popupMessage = '✅ Video uploaded successfully!';
|
| 109 |
+
setTimeout(() => this.popupMessage = '', 7000);
|
| 110 |
+
}, 1000);
|
| 111 |
+
});
|
| 112 |
+
},
|
| 113 |
+
error: (err) => {
|
| 114 |
+
console.error('Upload failed', err);
|
| 115 |
+
alert('❌ Video upload failed.');
|
| 116 |
+
}
|
| 117 |
+
});
|
| 118 |
+
} else {
|
| 119 |
+
alert('Please upload a valid MP4 file.');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
}
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
|
| 124 |
|
| 125 |
onVideoEnded(): void {
|
src/app/listen/listen.service.ts
CHANGED
|
@@ -12,6 +12,11 @@ export class ListenService {
|
|
| 12 |
|
| 13 |
constructor(private http: HttpClient) { }
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
// Fetch the list of available videos
|
| 16 |
getVideos(): Observable<any[]> {
|
| 17 |
return this.http.get<any[]>(`${this.baseUrl}/videos`);
|
|
|
|
| 12 |
|
| 13 |
constructor(private http: HttpClient) { }
|
| 14 |
|
| 15 |
+
/** Helper to form the full video URL for previews */
|
| 16 |
+
getVideoUrl(filename: string): string {
|
| 17 |
+
return `${this.baseUrl}/videos/${filename}`;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
// Fetch the list of available videos
|
| 21 |
getVideos(): Observable<any[]> {
|
| 22 |
return this.http.get<any[]>(`${this.baseUrl}/videos`);
|