private void Btn_pause_Click(object sender, RoutedEventArgs e) { Media_element.Pause(); Btn_play.Visibility = Visibility.Visible; Btn_pause.Visibility = Visibility.Collapsed; }
// set metadata by creating a new object and setting grid's datacontext for different file extensions private void Dg_files_SelectionChanged(object sender, SelectionChangedEventArgs e) { Img_preview.Source = null; Media_element.Source = null; try { DataGridBox dataGridFile = Dg_files.SelectedItem as DataGridBox; string pathfile = dataGridFile.fileitemPath; string filterExtension; FileInfo fileInfo = new FileInfo(pathfile); filterExtension = Path.GetExtension(pathfile).ToLower(); var metaData = new MetaData() { fileCreation = fileInfo.CreationTime, fileModified = fileInfo.LastWriteTime, fileName = Path.GetFileNameWithoutExtension(pathfile), fileLoc = fileInfo.FullName, fileLength = string.Concat((fileInfo.Length / 1024).ToString(), " KB"), fileType = filterExtension }; Grid_metadata.DataContext = metaData; if (filterExtension == ".png" || filterExtension == ".jpg" || filterExtension == ".jpeg" || filterExtension == ".ico" || filterExtension == ".bmp" || filterExtension == ".jpe" || filterExtension == ".jfif") { if (Img_preview.Visibility == Visibility.Collapsed) { Img_preview.Visibility = Visibility.Visible; Tblk_preview.Visibility = Visibility.Collapsed; Media_preview.Visibility = Visibility.Collapsed; } ImageSource imageSource = new BitmapImage(new Uri(pathfile)); Img_preview.Source = imageSource; Media_element.Stop(); } else if (filterExtension == ".wmv" || filterExtension == ".mp4" || filterExtension == ".avi" || filterExtension == ".mp3" || filterExtension == ".3gp" || filterExtension == ".flv" || filterExtension == ".mkv") { if (Media_preview.Visibility == Visibility.Collapsed) { Img_preview.Visibility = Visibility.Collapsed; Tblk_preview.Visibility = Visibility.Collapsed; Media_preview.Visibility = Visibility.Visible; } Btn_play.Visibility = Visibility.Visible; Btn_pause.Visibility = Visibility.Collapsed; Media_element.ScrubbingEnabled = true; Media_element.Source = new Uri(pathfile); Media_element.Position = TimeSpan.FromSeconds(0); Media_element.Pause(); } else { Media_element.Stop(); Img_preview.Visibility = Visibility.Collapsed; Tblk_preview.Visibility = Visibility.Visible; Media_preview.Visibility = Visibility.Collapsed; } } catch (Exception x) { Img_preview.Visibility = Visibility.Collapsed; Tblk_preview.Visibility = Visibility.Visible; Media_preview.Visibility = Visibility.Collapsed; } }