Плеер
This commit is contained in:
@@ -143,7 +143,12 @@
|
||||
<MudTd>
|
||||
@if (!string.IsNullOrEmpty(context.CoverUri))
|
||||
{
|
||||
<MudImage Src="@FormatCoverUrl(context.CoverUri, "50x50")" Height="50" Width="50" Class="rounded" />
|
||||
<TrackCoverWithPlay CoverUrl="@context.CoverUri"
|
||||
TrackId="@context.Id"
|
||||
Width="50"
|
||||
Height="50"
|
||||
IsPlaying="@(_currentTrackId == context.Id && _isPlaying)"
|
||||
OnPlay="PlayTrack" />
|
||||
}
|
||||
</MudTd>
|
||||
<MudTd>
|
||||
@@ -165,15 +170,20 @@
|
||||
}
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
<AudioPlayer @ref="_audioPlayer" OnTrackEnded="OnTrackEnded" />
|
||||
}
|
||||
</MudCardContent>
|
||||
</MudCard>
|
||||
}
|
||||
</MudContainer>
|
||||
|
||||
@code {
|
||||
@code {
|
||||
[Parameter] public string Token { get; set; }
|
||||
|
||||
private AudioPlayer? _audioPlayer;
|
||||
private string? _currentTrackId { get; set; }
|
||||
private bool _isPlaying = false;
|
||||
|
||||
private SharedPlaylistDto? _playlist;
|
||||
private bool _loading = true;
|
||||
private bool _isAuthenticated;
|
||||
@@ -215,7 +225,7 @@
|
||||
_canRemove = _isCreator
|
||||
|| _playlist.RemovePermission == EditPermission.Everyone
|
||||
|| (_playlist.RemovePermission == EditPermission.AuthorizedOnly && _isAuthenticated);
|
||||
|
||||
|
||||
if (_isCreator && _isAuthenticated)
|
||||
{
|
||||
_editPermissions = new UpdatePermissionsDto
|
||||
@@ -402,4 +412,36 @@
|
||||
{
|
||||
public int Index { get; set; }
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OnTrackEnded()
|
||||
{
|
||||
_currentTrackId = null;
|
||||
_isPlaying = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user