如何从手机图库中选择视频后设置MediaElement的来源?
当调试到达指令时(使用(var isfs = new IsolatedStorageFileStream(video.Path,FileMode.Open,FileAccess.Read,FileShare.Read,isf)生成异常“IsolatedStorageFileStream上不允许操作”,i无法理解为什么。
这是代码:
private void btn_Crea_Click(object sender, RoutedEventArgs e)
{
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.VideosLibrary;
openPicker.ContinuationData["Operation"] = "UpdateVideo";//"UpdateProfilePicture";
openPicker.FileTypeFilter.Add(".3GP");
openPicker.FileTypeFilter.Add(".MP4");
openPicker.FileTypeFilter.Add(".WMV");
openPicker.FileTypeFilter.Add(".AVI");
openPicker.FileTypeFilter.Add(".MOV");
openPicker.FileTypeFilter.Add(".3G2");
openPicker.PickSingleFileAndContinue();
}
public void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args)
{
if ((args.ContinuationData["Operation"] as string) == "UpdateVideo" &&
args.Files != null &&
args.Files.Count > 0)
{
StorageFile file = args.Files[0];
Singleton.Instance.video = file;
}
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
private void addVideo()
{
this.video = Singleton.Instance.video;
Dispatcher.BeginInvoke(() =>
{
using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var isfs = new IsolatedStorageFileStream(video.Path, FileMode.Open, FileAccess.Read, FileShare.Read, isf))
{
this.videoBox.SetSource(isfs);
}
}
});
}