mirror of
https://github.com/ZuneDev/ZuneShell.dll.git
synced 2026-07-27 13:11:51 -07:00
[WIP] Use callbacks for async
This commit is contained in:
@@ -15,12 +15,12 @@ public static class AsyncHelper
|
||||
t.Wait();
|
||||
}
|
||||
|
||||
public static TResult Run<TResult>(Func<Task<TResult>> action)
|
||||
{
|
||||
Guard.IsNotNull(action);
|
||||
public static TResult Run<TResult>(Func<Task<TResult>> action) => Run(action());
|
||||
|
||||
var t = Task.Run(action);
|
||||
t.Wait();
|
||||
return t.Result;
|
||||
public static TResult Run<TResult>(Task<TResult> task)
|
||||
{
|
||||
Guard.IsNotNull(task);
|
||||
|
||||
return task.GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1854,40 +1854,47 @@ namespace ZuneUI
|
||||
{
|
||||
try
|
||||
{
|
||||
var stTrack = ((StrixPlaybackTrack)track).Track;
|
||||
|
||||
Application.DeferredInvoke(delegate
|
||||
if (!IsDisposed && myID == _lastKnownSetUriCallID)
|
||||
{
|
||||
if (IsDisposed || myID != _lastKnownSetUriCallID)
|
||||
return;
|
||||
|
||||
var stTrack = ((StrixPlaybackTrack)track).Track;
|
||||
var source = ((StrixMusic.Sdk.AdapterModels.IMerged<StrixMusic.Sdk.CoreModels.ICoreTrack>)stTrack)
|
||||
.Sources[0];
|
||||
var mediaConfig = AsyncHelper.Run(() => source.SourceCore.GetMediaSourceAsync(source));
|
||||
|
||||
// This should set URIs, not necessarily begin playback
|
||||
PlaybackItem playbackItem = new()
|
||||
source.SourceCore.GetMediaSourceAsync(source).ContinueWith(task =>
|
||||
{
|
||||
Track = stTrack,
|
||||
MediaConfig = mediaConfig,
|
||||
};
|
||||
ph.InsertNext(0, playbackItem);
|
||||
ph.PlayFromNext(0);
|
||||
//AsyncHelper.Run(dataRoot.Library.PlayTrackCollectionAsync(stTrack));
|
||||
if (!task.IsCompleted || task.IsFaulted)
|
||||
return;
|
||||
|
||||
if (mediaConfig.FileStreamSource != null)
|
||||
_toDisposeOnEnd.Push(mediaConfig.FileStreamSource);
|
||||
Application.DeferredInvoke(arg =>
|
||||
{
|
||||
var mediaConfig = (IMediaSourceConfig?)arg;
|
||||
|
||||
ReportStreamingAction(PlayerState.Stopped);
|
||||
_tracksSubmittedToPlayer.Remove(track);
|
||||
_tracksSubmittedToPlayer.Add(track);
|
||||
if (nextTrack != null)
|
||||
return;
|
||||
// This should set URIs, not necessarily begin playback
|
||||
PlaybackItem playbackItem = new()
|
||||
{
|
||||
Track = stTrack,
|
||||
MediaConfig = mediaConfig,
|
||||
};
|
||||
ph.InsertNext(0, playbackItem);
|
||||
ph.PlayFromNext(0);
|
||||
//AsyncHelper.Run(dataRoot.Library.PlayTrackCollectionAsync(stTrack));
|
||||
|
||||
// TODO: _playbackWrapper.CancelNext();
|
||||
//ph.ClearNext();
|
||||
UpdatePropertiesAndCommands();
|
||||
}, null);
|
||||
if (mediaConfig.FileStreamSource != null)
|
||||
_toDisposeOnEnd.Push(mediaConfig.FileStreamSource);
|
||||
|
||||
ReportStreamingAction(PlayerState.Stopped);
|
||||
_tracksSubmittedToPlayer.Remove(track);
|
||||
_tracksSubmittedToPlayer.Add(track);
|
||||
if (nextTrack != null)
|
||||
return;
|
||||
|
||||
// TODO: _playbackWrapper.CancelNext();
|
||||
//ph.ClearNext();
|
||||
UpdatePropertiesAndCommands();
|
||||
}, task.Result);
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
+1
-1
Submodule libs/MicrosoftIris updated: 18dba59889...958a1024a1
Reference in New Issue
Block a user