Новый плеер
This commit is contained in:
@@ -13,8 +13,7 @@ public class AudioPlayerService : IAudioPlayerService
|
||||
private readonly PlayerStorage _playerStorage;
|
||||
|
||||
private string? _currentTrackId;
|
||||
private string? _currentTrackTitle;
|
||||
private string? _currentTrackCoverUrl;
|
||||
private YandexTrack? _currentTrack;
|
||||
private bool _isPlaying;
|
||||
private double _currentVolume = 50;
|
||||
private double _currentProgress;
|
||||
@@ -24,8 +23,7 @@ public class AudioPlayerService : IAudioPlayerService
|
||||
private string _totalTimeString = "0:00";
|
||||
|
||||
public string? CurrentTrackId => _currentTrackId;
|
||||
public string? CurrentTrackTitle => _currentTrackTitle;
|
||||
public string? CurrentTrackCoverUrl => _currentTrackCoverUrl;
|
||||
public YandexTrack? CurrentTrack => _currentTrack;
|
||||
public bool IsPlaying => _isPlaying;
|
||||
public double CurrentVolume
|
||||
{
|
||||
@@ -65,7 +63,7 @@ public class AudioPlayerService : IAudioPlayerService
|
||||
}
|
||||
|
||||
// Внешние команды (вызываются из компонентов)
|
||||
public async Task LoadAndPlayAsync(string trackId, string? accessToken = null, string? playlistShareToken = null, string? title = null, string? coverUrl = null)
|
||||
public async Task LoadAndPlayAsync(string trackId, string? accessToken = null, string? playlistShareToken = null, YandexTrack? track = null)
|
||||
{
|
||||
if (_currentTrackId == trackId)
|
||||
{
|
||||
@@ -88,13 +86,11 @@ public class AudioPlayerService : IAudioPlayerService
|
||||
}
|
||||
|
||||
// Если title и coverUrl не переданы, нужно запросить через API
|
||||
if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(coverUrl))
|
||||
if (track is null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var trackInfo = await GetTrackInfo(trackId, accessToken, playlistShareToken);
|
||||
title = trackInfo?.Title;
|
||||
coverUrl = trackInfo?.CoverUri;
|
||||
track = await GetTrackInfo(trackId, accessToken, playlistShareToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -103,9 +99,7 @@ public class AudioPlayerService : IAudioPlayerService
|
||||
}
|
||||
}
|
||||
|
||||
_currentTrackId = trackId;
|
||||
_currentTrackTitle = title ?? "Неизвестный трек";
|
||||
_currentTrackCoverUrl = coverUrl;
|
||||
_currentTrack = track;
|
||||
_isPlaying = true;
|
||||
OnStateChanged?.Invoke();
|
||||
OnLoadAndPlayRequested?.Invoke(trackId, accessToken, playlistShareToken);
|
||||
@@ -125,10 +119,9 @@ public class AudioPlayerService : IAudioPlayerService
|
||||
OnPauseRequested?.Invoke();
|
||||
}
|
||||
|
||||
public async Task SeekToAsync(double percent)
|
||||
public async Task SeekToAsync(double second)
|
||||
{
|
||||
var newTime = (percent / 100) * _totalTime;
|
||||
OnSeekRequested?.Invoke(newTime);
|
||||
OnSeekRequested?.Invoke(second);
|
||||
}
|
||||
|
||||
public async Task SetVolumeAsync(double volume)
|
||||
@@ -189,7 +182,7 @@ public class AudioPlayerService : IAudioPlayerService
|
||||
/// <param name="accessToken"></param>
|
||||
/// <param name="sharedPlaylistId"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<(string? Title, string? CoverUri)?> GetTrackInfo(string trackId, string? accessToken, string? sharedPlaylistId)
|
||||
private async Task<YandexTrack?> GetTrackInfo(string trackId, string? accessToken, string? sharedPlaylistId)
|
||||
{
|
||||
var url = $"/api/audio/track-info/{trackId}";
|
||||
if (!string.IsNullOrEmpty(accessToken))
|
||||
@@ -200,7 +193,7 @@ public class AudioPlayerService : IAudioPlayerService
|
||||
var response = await _http.GetFromJsonAsync<ApiResponse<YandexTrack>>(url);
|
||||
if (response?.Success == true)
|
||||
{
|
||||
return (response.Data.Title, response.Data.CoverUri);
|
||||
return response.Data;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user