gpt4 book ai didi

c# - UWP MediaPlaybackList 添加 MediaSource 工作太慢

转载 作者:行者123 更新时间:2023-11-30 14:26:06 26 4
gpt4 key购买 nike

MediaPlaybackList 有问题,如下所示:

playbackList = new MediaPlaybackList();
playbackList.AutoRepeatEnabled = true;
for (int i = 0; i < songs.Count();i++)
{
var song = songs.ElementAt(i);
var source = MediaSource.CreateFromStorageFile(
await StorageFile.GetFileFromPathAsync(song.File));
source.CustomProperties[TrackIdKey] = null;
source.CustomProperties[TitleKey] = song.Title;
source.CustomProperties[AlbumArtKey] = song.AlbumArtUri;
source.CustomProperties[AuthorKey] = song.Author;
source.CustomProperties[TrackNumber] = (uint)(i+1);
playbackList.Items.Add(new MediaPlaybackItem(source));
}

当我尝试将 MediaSource 添加到我的播放列表时,它花费了太多时间。 700 首歌曲大约需要 3 分钟才能开始播放。也许还有另一种方法可以将 MediaSource 添加到 MediaPlaybackList 中,这样效果更快?

最佳答案

使用 IRandomAccessStreamReference。这样它只需要在到达 Item 时加载文件,速度要快得多。

不过您必须编写自己的抽象类。可能看起来有点像这样:

public class MyStreamReference : IRandomAccessStreamReference
{
private string path;

public MyStreamReference(string path)
{
this.path = path;
}

public IAsyncOperation<IRandomAccessStreamWithContentType> OpenReadAsync()
=> Open().AsAsyncOperation();

// private async helper task that is necessary if you need to use await.
private async Task<IRandomAccessStreamWithContentType> Open()
=> await (await StorageFile.GetFileFromPathAsync(path)).OpenReadAsync();
}

关于c# - UWP MediaPlaybackList 添加 MediaSource 工作太慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36383747/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com