Windows runtime WinRT MediaElement在播放大约60个视频后挂起

Windows runtime WinRT MediaElement在播放大约60个视频后挂起,windows-runtime,windows-store-apps,winrt-xaml,Windows Runtime,Windows Store Apps,Winrt Xaml,我正在制作一个连续播放大量视频的应用程序。然而,似乎每当我点击60个视频(有时更少,有时更多)时,我的应用程序就会挂起。我制作了一个小的示例应用程序,它也可以做到这一点,所以对我来说,问题似乎在MediaElement控件内或更深的地方 以下是示例应用程序的代码: MainPage.xaml: <Page x:Class="App2.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentat

我正在制作一个连续播放大量视频的应用程序。然而,似乎每当我点击60个视频(有时更少,有时更多)时,我的应用程序就会挂起。我制作了一个小的示例应用程序,它也可以做到这一点,所以对我来说,问题似乎在MediaElement控件内或更深的地方

以下是示例应用程序的代码:

MainPage.xaml:

<Page
    x:Class="App2.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App2"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <MediaElement x:Name="player" AutoPlay="False" MediaOpened="player_MediaOpened" MediaEnded="player_MediaEnded" Volume="0.01" />
        <TextBlock x:Name="txtDebug" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="40" FontSize="20" Text="Videos played: 0" Foreground="Yellow" />
        <Button Content="Test" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="40,100,0,0" Click="Button_Click" />
    </Grid>
</Page>

代码隐藏:

namespace App2
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
    }

    protected override async void OnNavigatedTo(NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);
        await SetPlayerVideo();
    }

    private async System.Threading.Tasks.Task SetPlayerVideo()
    {
        // get next video file, open it and set it to MediaElement.
        var nextVideo = await this.SelectNextVideo();
        var videoStream = await nextVideo.OpenAsync(Windows.Storage.FileAccessMode.Read);
        this.player.SetSource(videoStream, "");
    }

    private void player_MediaOpened(object sender, RoutedEventArgs e)
    {
        // When MediaElement.SetSource finishes, begin play.
        MediaElement elem = sender as MediaElement;
        elem.Play();
    }

    private async void player_MediaEnded(object sender, RoutedEventArgs e)
    {
        // Update debug text and start next video when one ends.
        this.txtDebug.Text = string.Format("Videos played: {0}", this.videoIndex);
        await SetPlayerVideo();
    }

    private int videoIndex = 0; // Index used to loop through files in temp folder in case there are multiple video files

    private async System.Threading.Tasks.Task<Windows.Storage.StorageFile> SelectNextVideo()
    {
        var files = await Windows.Storage.ApplicationData.Current.TemporaryFolder.GetFilesAsync();
        var file = files.ElementAt(this.videoIndex % files.Count);
        videoIndex++;
        return file;
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        txtDebug.Text = "button click";
    }
}
}
名称空间App2
{
/// 
///可以单独使用或在框架内导航到的空页。
/// 
公共密封部分类主页面:第页
{
公共主页()
{
this.InitializeComponent();
}
受保护的覆盖异步无效OnNavigatedTo(NavigationEventArgs e)
{
基地。导航到(e);
等待SetPlayerVideo();
}
专用异步System.Threading.Tasks.Task SetPlayerVideo()系统
{
//获取下一个视频文件,打开它并将其设置为MediaElement。
var nextVideo=等待。选择nextVideo();
var videoStream=wait nextVideo.OpenAsync(Windows.Storage.FileAccessMode.Read);
this.player.SetSource(videoStream,“”);
}
私有void player_media已打开(对象发送器,路由目标e)
{
//MediaElement.SetSource完成后,开始播放。
MediaElement elem=发送方作为MediaElement;
元素Play();
}
专用异步void player_mediated(对象发送方,路由目标)
{
//更新调试文本,并在视频结束时开始下一个视频。
this.txtDebug.Text=string.Format(“播放的视频:{0}”,this.videoIndex);
等待SetPlayerVideo();
}
private int videoIndex=0;//用于在有多个视频文件的情况下循环临时文件夹中的文件的索引
专用异步System.Threading.Tasks.Task SelectNextVideo()
{
var files=wait Windows.Storage.ApplicationData.Current.TemporaryFolder.getfileasync();
var file=files.ElementAt(this.videoIndex%files.Count);
videoIndex++;
返回文件;
}
私有无效按钮\u单击(对象发送者,路由目标e)
{
txtDebug.Text=“单击按钮”;
}
}
}
要进行测试,请将一个wmv文件放入TempState文件夹。最好是短视频,因为它需要运行数十次才能重现问题。我使用了这个网站的倒计时剪辑:

我从Windows应用商店下载了一些具有播放列表功能的应用程序,添加了大约100 x 10秒的剪辑并点击播放。他们都有同样的问题,在播放了大约60段视频后被绞死

有什么建议或想法来回避这个问题吗?每次视频结束时,我都会尝试创建新的MediaElement,但没有效果


接下来我可能会研究一下VLC播放器,因为它们似乎不使用默认的MediaElement来播放视频。但我还没有真正检查他们的许可证是否允许在我的应用程序中使用他们的DLL,或者我是否可以编译源代码。

这个问题似乎与AMD图形卡有关,并且似乎在将驱动程序更新到最新版本后得到了修复