打开视频选择随机文件

时间:2016-07-24 17:17:47

标签: c# raspberry-pi2 raspberry-pi3 windowsiot windows-iot-core-10

我试图在运行Windows 10 IoT Core的Raspberry PI上创建可以打开视频选择随机文件的应用程序。但我收到以下错误:

enter image description here

代码:

private async void button1_Click(object sender, RoutedEventArgs e)
    {
        await VideoAc();
    }

    private async Task VideoAc()
    {
        Debug.WriteLine("Video opening");
        RandomVideo();
        video.AutoPlay = true;
        video.Visibility = Visibility.Visible;
        video.Play();

    }


    private void video_MediaEnded(object sender, RoutedEventArgs e)
    {
        video.AutoPlay = false;
        video.Visibility = Visibility.Collapsed;

    }
    private void RandomVideo()
    {
        var random = new Random();

        var fileNames = Directory.GetFiles("ms-appx:///wmv", "*.wmv", SearchOption.AllDirectories);

        var path = fileNames[random.Next(0, fileNames.Length)];

        Debug.WriteLine(path);

        video.Source = new Uri(path);
    }

1 个答案:

答案 0 :(得分:1)

您可能还想尝试替代的UWP API,

  

StorageFolder.GetFilesAsync()

here中查找更多详情。您还可以使用此API

应用自定义查询/过滤器
  

StorageFolder.GetFilesAsync(CommonFileQuery)

来自here的更多详情。

  

Directory.GetFiles()

另一方面,仅在legacy .NET框架中可用。我认为你不应该在你的UWP应用程序中使用它。