Вынесен глобальный плеер
This commit is contained in:
@@ -34,9 +34,7 @@
|
||||
{
|
||||
<AddTrackSection ShareToken="@Token"
|
||||
OnTrackAdded="LoadTracks"
|
||||
OnPlayTrack="PlayTrack"
|
||||
CurrentPlayingTrackId="_currentTrackId"
|
||||
IsPlaying="_isPlaying" />
|
||||
/>
|
||||
}
|
||||
|
||||
<!-- Список треков -->
|
||||
@@ -50,16 +48,10 @@
|
||||
CanPlay="@_canPlay"
|
||||
CanRemove="@_canRemove"
|
||||
CurrentPlayingTrackId="_currentTrackId"
|
||||
IsPlaying="_isPlaying"
|
||||
OnPlayTrack="PlayTrack" />
|
||||
/>
|
||||
</MudCardContent>
|
||||
</MudCard>
|
||||
}
|
||||
|
||||
<!-- Фиксированный плеер внизу -->
|
||||
<div class="fixed-player" style="display: @(_isPlayerVisible ? "block" : "none");">
|
||||
<AudioPlayer @ref="_audioPlayer" OnTrackEnded="OnTrackEnded" RequireAuth="false" SharedPlaylistId="@Token" />
|
||||
</div>
|
||||
</MudContainer>
|
||||
|
||||
|
||||
@@ -68,11 +60,7 @@
|
||||
|
||||
private int _addTrackTabIndex = 0; // 0 - ссылка, 1 - поиск
|
||||
|
||||
private AudioPlayer? _audioPlayer;
|
||||
private TracksTable? _tracksTableRef;
|
||||
private string? _currentTrackId { get; set; }
|
||||
private bool _isPlaying = false;
|
||||
private bool _isPlayerVisible = false;
|
||||
|
||||
private SharedPlaylistDto? _playlist;
|
||||
private bool _loading = true;
|
||||
@@ -180,38 +168,4 @@
|
||||
_tracksLoading = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task PlayTrack(string trackId)
|
||||
{
|
||||
if (_audioPlayer == null) return;
|
||||
|
||||
if (_currentTrackId == trackId && _isPlaying)
|
||||
{
|
||||
await _audioPlayer.PauseAsync();
|
||||
_isPlaying = false;
|
||||
}
|
||||
else if (_currentTrackId == trackId && !_isPlaying)
|
||||
{
|
||||
await _audioPlayer.PlayAsync();
|
||||
_isPlaying = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_currentTrackId) && _isPlaying)
|
||||
await _audioPlayer.StopAsync();
|
||||
|
||||
_currentTrackId = trackId;
|
||||
await _audioPlayer.LoadAndPlayAsync(trackId);
|
||||
_isPlaying = true;
|
||||
}
|
||||
|
||||
_isPlayerVisible = true;
|
||||
}
|
||||
|
||||
private async Task OnTrackEnded()
|
||||
{
|
||||
_currentTrackId = null;
|
||||
_isPlaying = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user