2014-03-28 22 views
0

我有一個包含媒體文件路徑的列表框。當我從列表框中選擇項目(路徑)它應該在媒體元素中播放... 我該怎麼辦?感謝, Sankar。如何使用Windows應用商店C播放存儲在D驅動器中的媒體文件#

private async void btnLoadPlayList_Click(object sender, RoutedEventArgs e) 
{ 
    Windows.Storage.Pickers.FileOpenPicker filePicker = new Windows.Storage.Pickers.FileOpenPicker(); 
    filePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.VideosLibrary; 
    filePicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail; 
    filePicker.FileTypeFilter.Clear(); 
    filePicker.FileTypeFilter.Add(".mpeg"); 
    filePicker.FileTypeFilter.Add(".wmv"); 
    filePicker.FileTypeFilter.Add(".mp4"); 
    filePicker.FileTypeFilter.Add(".mkv"); 
    filePicker.FileTypeFilter.Add(".3gp"); 

    IReadOnlyList<Windows.Storage.StorageFile> fileList = await filePicker.PickMultipleFilesAsync(); 
    if (fileList.Count > 0) 
    { 
     foreach (StorageFile file in fileList) 
     { 
      lstPlayList.Items.Add(file.Path); 
     } 
    } 
} 
private async void lstPlayList_SelectionChanged(object sender, SelectionChangedEventArgs e) 
{ 
     PlayerME2.Source = new Uri(lstPlayList.SelectedItem.ToString()); 
} 

如果我像這樣設置源碼,然後嘗試播放,則會顯示Error E Access Denied Exception。告訴我一些設置來源並播放選定文件的內容。

+0

向我們展示你玩得那麼遠的東西,.. – Kumar

+0

是這使得任何意義@ kumar-我爲嚴重的新本。以某種方式幫助。謝謝 – user3184500

+0

這裏同樣的事情.. [http://stackoverflow.com/questions/18322242/read-the-value-of-an-item-in-a-listbox?answertab=votes#tab-top] – Kumar

回答

0

Here的鏈接,你必須休耕。您必須在appManifest中授予訪問權限。

除了這個,你能我張貼在最新的留言分析樣品中的場景5使用stream

IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read); 

看。

StorageFile file = Playlist.SelectedItem as StorageFile; 

    if (file != null) 
    { 
     // Open the selected file and set it as the MediaElement's source 
     IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read); 
     Scenario5MediaElement.SetSource(stream, file.ContentType); 
    } 

希望這有助於

相關問題