2012-09-25 17 views
0

對於Windows 8應用程序,在C#/ Xaml中我想用計算機上的媒體播放器使用Launcher.LaunchFileAsync啓動視頻。無法使用LaunchFileAsync從uri啓動視頻

我從URL的視頻文件,我使用此代碼:

 var uri = new Uri(myUrl,UriKind.RelativeOrAbsolute); 

      var file = await StorageFile.CreateStreamedFileFromUriAsync("aaa", uri, RandomAccessStreamReference.CreateFromUri(uri)); 

      if (file != null) 
      { 
       // Launch the retrieved file 
       var success = await Windows.System.Launcher.LaunchFileAsync(file); 

       if (success) 
       { 
        // File launched 
       } 
       else 
       { 
        // File launch failed 
       } 
      } 
      else 
      { 
       // Could not find file 
      } 

這實際上是從LaunchFileAsync的文檔,示例代碼。對我來說這似乎很好,但成功永遠是錯誤的。 你知道爲什麼嗎? 是否有可能在一個url中使用LaunchFileAsync視頻? 還有另一種方法可以做到嗎?

回答

0

我很困惑你的代碼說什麼。

var file = await StorageFile.CreateStreamedFileFromUriAsync("aaa", uri, RandomAccessStreamReference.CreateFromUri(uri)); 

「文件」得到函數的返回,但什麼函數的返回是StorageFile的一個對象,你可以參考Window.Storage.StorageFile。

我認爲這可能是問題,但我不知道如何糾正它。

此外,函數「LaunchFileAsync()」對它可以啓動的文件類型有限制,這也可能導致此問題。

對不起,我沒有回答的建議。就這樣。

1

我有同樣的問題,我試圖從特定的文件路徑位置播放.mp3文件。我無法使用StorageFile.CreateStreamedFileFromUriAsync打開文件。我收到無效的參數例外或未經授權的訪問錯誤。

嘗試更換變線:

  String myUrl = @"ms-appx:///sources/sounds/ffd19.mp3";   
      var file = await StorageFile.GetFileFromApplicationUriAsync(uri); 

唯一的缺陷是,該文件必須臨時用戶作爲該項目的資源。

對我而言,.mp3位於解決方案資源管理器中的sources/sounds /文件夾中,位於與應用程序文件相同的文件夾中。