Skip to content

Commit cc61452

Browse files
committed
fix: fix audio player
1 parent 88b9153 commit cc61452

2 files changed

Lines changed: 83 additions & 48 deletions

File tree

TelegramDownloader/Pages/Modals/AudioPlayerModal.razor

Lines changed: 69 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -357,63 +357,60 @@
357357
gap: 0.25rem;
358358
}
359359
360-
.audio-progress-bar {
360+
.audio-seek-slider {
361361
width: 100%;
362362
height: 6px;
363+
-webkit-appearance: none;
364+
appearance: none;
363365
background: rgba(255, 255, 255, 0.1);
364366
border-radius: 3px;
365367
cursor: pointer;
366-
position: relative;
367-
}
368-
369-
.audio-progress-buffer {
370-
position: absolute;
371-
top: 0;
372-
left: 0;
373-
height: 100%;
374-
background: rgba(255, 255, 255, 0.2);
375-
border-radius: 3px;
376-
transition: width 0.3s ease;
368+
outline: none;
377369
}
378370
379-
.audio-progress-fill {
380-
position: absolute;
381-
top: 0;
382-
left: 0;
383-
height: 100%;
384-
background: linear-gradient(90deg, #e94560 0%, #ff6b6b 100%);
371+
.audio-seek-slider::-webkit-slider-runnable-track {
372+
height: 6px;
373+
background: transparent;
385374
border-radius: 3px;
386-
transition: width 0.1s linear;
387375
}
388376
389-
.audio-progress-thumb {
390-
position: absolute;
391-
top: 50%;
392-
transform: translate(-50%, -50%);
377+
.audio-seek-slider::-webkit-slider-thumb {
378+
-webkit-appearance: none;
379+
appearance: none;
393380
width: 14px;
394381
height: 14px;
395382
background: #fff;
396383
border-radius: 50%;
397384
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
385+
cursor: pointer;
386+
margin-top: -4px;
398387
transition: transform 0.1s ease, box-shadow 0.2s ease;
399-
z-index: 2;
400388
}
401389
402-
.audio-progress-bar:hover .audio-progress-thumb {
403-
transform: translate(-50%, -50%) scale(1.2);
390+
.audio-seek-slider::-webkit-slider-thumb:hover {
391+
transform: scale(1.2);
404392
box-shadow: 0 2px 10px rgba(233, 69, 96, 0.5);
405393
}
406394
407-
.audio-progress-thumb::after {
408-
content: '';
409-
position: absolute;
410-
top: 50%;
411-
left: 50%;
412-
transform: translate(-50%, -50%);
413-
width: 6px;
395+
.audio-seek-slider::-moz-range-track {
414396
height: 6px;
415-
background: #e94560;
397+
background: transparent;
398+
border-radius: 3px;
399+
}
400+
401+
.audio-seek-slider::-moz-range-thumb {
402+
width: 14px;
403+
height: 14px;
404+
background: #fff;
416405
border-radius: 50%;
406+
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
407+
cursor: pointer;
408+
border: none;
409+
}
410+
411+
.audio-seek-slider::-moz-range-thumb:hover {
412+
transform: scale(1.2);
413+
box-shadow: 0 2px 10px rgba(233, 69, 96, 0.5);
417414
}
418415
419416
.audio-time {
@@ -765,11 +762,11 @@
765762
</div>
766763
<div class="audio-controls-row">
767764
<div class="audio-progress-container">
768-
<div class="audio-progress-bar" @onclick="SeekAudio">
769-
<div class="audio-progress-buffer" style="width: @(bufferPercent.ToString("F1", System.Globalization.CultureInfo.InvariantCulture))%"></div>
770-
<div class="audio-progress-fill" style="width: @(progressPercent.ToString("F1", System.Globalization.CultureInfo.InvariantCulture))%"></div>
771-
<div class="audio-progress-thumb" style="left: @(progressPercent.ToString("F1", System.Globalization.CultureInfo.InvariantCulture))%"></div>
772-
</div>
765+
<input type="range" class="audio-seek-slider" min="0" max="100" step="0.1"
766+
value="@progressPercent.ToString("F1", System.Globalization.CultureInfo.InvariantCulture)"
767+
style="background: linear-gradient(to right, #e94560 0%, #e94560 @(progressPercent.ToString("F1", System.Globalization.CultureInfo.InvariantCulture))%, rgba(255,255,255,0.1) @(progressPercent.ToString("F1", System.Globalization.CultureInfo.InvariantCulture))%, rgba(255,255,255,0.1) 100%);"
768+
@oninput="SeekAudioInput"
769+
@onchange="SeekAudioChange" />
773770
<div class="audio-time">
774771
<span>@currentTimeDisplay</span>
775772
<span>@durationDisplay</span>
@@ -780,6 +777,8 @@
780777
<i class="bi @(isMuted ? "bi-volume-mute-fill" : "bi-volume-up-fill")"></i>
781778
</button>
782779
<input type="range" class="audio-volume-slider" min="0" max="100" value="@volume"
780+
style="background: linear-gradient(to right, #e94560 0%, #e94560 @(volume)%, rgba(255,255,255,0.1) @(volume)%, rgba(255,255,255,0.1) 100%);"
781+
@oninput="ChangeVolumeInput"
783782
@onchange="ChangeVolume" />
784783
</div>
785784
<button class="audio-btn-visualizer @(enableVisualizer ? "active" : "")" @onclick="ToggleVisualizer" title="@(enableVisualizer ? "Disable visualizer" : "Enable visualizer")">
@@ -1019,13 +1018,38 @@
10191018
}
10201019
}
10211020

1022-
private async Task SeekAudio(MouseEventArgs e)
1021+
private async Task SeekAudioInput(Microsoft.AspNetCore.Components.ChangeEventArgs e)
1022+
{
1023+
// Preview while dragging (updates display but doesn't commit)
1024+
if (double.TryParse(e.Value?.ToString(), System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out double percent))
1025+
{
1026+
progressPercent = percent;
1027+
await InvokeAsync(StateHasChanged);
1028+
}
1029+
}
1030+
1031+
private async Task SeekAudioChange(Microsoft.AspNetCore.Components.ChangeEventArgs e)
10231032
{
1024-
var percent = e.OffsetX / 200.0 * 100;
1025-
if (percent < 0) percent = 0;
1026-
if (percent > 100) percent = 100;
1027-
await JSRuntime.InvokeVoidAsync("seekAudioPlayer", percent);
1028-
await UpdateProgress();
1033+
// Commit the seek when user releases
1034+
if (double.TryParse(e.Value?.ToString(), System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out double percent))
1035+
{
1036+
if (percent < 0) percent = 0;
1037+
if (percent > 100) percent = 100;
1038+
await JSRuntime.InvokeVoidAsync("seekAudioPlayer", percent);
1039+
await UpdateProgress();
1040+
}
1041+
}
1042+
1043+
private async Task ChangeVolumeInput(Microsoft.AspNetCore.Components.ChangeEventArgs e)
1044+
{
1045+
// Update volume in real-time while dragging
1046+
if (int.TryParse(e.Value?.ToString(), out int newVolume))
1047+
{
1048+
volume = newVolume;
1049+
isMuted = volume == 0;
1050+
await JSRuntime.InvokeVoidAsync("setAudioVolume", volume / 100.0);
1051+
await InvokeAsync(StateHasChanged);
1052+
}
10291053
}
10301054

10311055
private async Task ChangeVolume(Microsoft.AspNetCore.Components.ChangeEventArgs e)

TelegramDownloader/wwwroot/js/fileUploadVue.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -871,29 +871,40 @@ window.extractAudioArtwork = (audioUrl) => {
871871
return;
872872
}
873873

874+
const urlLower = audioUrl.toLowerCase();
875+
874876
// Skip artwork extraction for FLAC files - jsmediatags has issues with them
875877
// and they require downloading too much data
876-
const urlLower = audioUrl.toLowerCase();
877878
if (urlLower.includes('.flac') || urlLower.includes('flac')) {
878879
console.log('Skipping artwork extraction for FLAC file');
879880
window._artworkCache[audioUrl] = null;
880881
resolve(null);
881882
return;
882883
}
883884

885+
// Skip artwork extraction for local files (not from API)
886+
// jsmediatags tries to download the entire file which can hang the connection
887+
const isLocalFile = !audioUrl.includes('/api/file/');
888+
if (isLocalFile) {
889+
console.log('Skipping artwork extraction for local file');
890+
window._artworkCache[audioUrl] = null;
891+
resolve(null);
892+
return;
893+
}
894+
884895
// Check if jsmediatags is available
885896
if (typeof jsmediatags === 'undefined') {
886897
console.log('jsmediatags library not loaded');
887898
resolve(null);
888899
return;
889900
}
890901

891-
// Add timeout to prevent hanging
902+
// Add timeout to prevent hanging (reduced from 10s to 5s)
892903
const timeoutId = setTimeout(() => {
893904
console.log('Artwork extraction timed out');
894905
window._artworkCache[audioUrl] = null;
895906
resolve(null);
896-
}, 10000); // 10 second timeout
907+
}, 5000); // 5 second timeout
897908

898909
try {
899910
jsmediatags.read(audioUrl, {

0 commit comments

Comments
 (0)