protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            var videoFile = e.Parameter as StorageFile;

            if (videoFile != null)
            {
                StatusTextBlock.Text = videoFile.DisplayName;

                // Create a MediaClip from the file
                var clip = await MediaClip.CreateFromFileAsync(videoFile);

                // Set the End Trim slider's maximum value so that the user can trim from the end
                // You can also do this from the start
                EndTrimSlider.Maximum = clip.OriginalDuration.TotalMilliseconds;

                // Create a MediaComposition containing the clip and set it on the MediaElement.
                composition = new MediaComposition();
                composition.Clips.Add(clip);

                // start the MediaElement at the beginning
                EditorMediaElement.Position = TimeSpan.Zero;

                // Create the media source and assign it to the media player
                mediaStreamSource = composition.GeneratePreviewMediaStreamSource((int)EditorMediaElement.ActualWidth, (int)EditorMediaElement.ActualHeight);

                // Set the MediaElement's source
                EditorMediaElement.SetMediaStreamSource(mediaStreamSource);

                TrimClipButton.IsEnabled = true;
            }
        }
示例#2
0
        private void TrimClip_Click(object sender, RoutedEventArgs e)
        {
            // Get the first clip in the MediaComposition
            // We know this beforehand because it's the only clip in the composition
            // that we created from the passed video file
            MediaClip clip = composition.Clips.FirstOrDefault();

            // Trim the end of the clip (you can use TrimTimeFromStart to trim from the beginning)
            clip.TrimTimeFromEnd = TimeSpan.FromMilliseconds((long)EndTrimSlider.Value);

            // Rewind the MediaElement
            EditorMediaElement.Position = TimeSpan.Zero;

            // Update the video source with the trimmed clip
            mediaStreamSource = composition.GeneratePreviewMediaStreamSource((int)EditorMediaElement.ActualWidth, (int)EditorMediaElement.ActualHeight);

            // Set the MediaElement's source
            EditorMediaElement.SetMediaStreamSource(mediaStreamSource);

            // Update the UI
            EndTrimSlider.Value        = 0;
            StatusTextBlock.Text       = "Clip trimmed! Trim again or click Save.";
            StatusTextBlock.Foreground = new SolidColorBrush(Colors.LawnGreen);
            SaveButton.IsEnabled       = true;
        }
        private void TrimClip_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Show the overlay that contains the ProgressBar
                BusyOverlay.Visibility         = Visibility.Visible;
                EncodingProgressTextBlock.Text = "trimming...";

                // Get the first clip in the MediaComposition
                // We know this beforehand because it's the only clip in the composition
                // that we created from the passed video file
                MediaClip clip = composition.Clips.FirstOrDefault();

                // Trim the end of the clip (you can use TrimTimeFromStart to trim from the beginning)
                clip.TrimTimeFromEnd = TimeSpan.FromMilliseconds((long)EndTrimSlider.Value);

                // Rewind the MediaElement
                EditorMediaElement.Position = TimeSpan.Zero;

                // Update the video source with the trimmed clip
                mediaStreamSource = composition.GeneratePreviewMediaStreamSource((int)EditorMediaElement.ActualWidth, (int)EditorMediaElement.ActualHeight);

                // Set the MediaElement's source
                EditorMediaElement.SetMediaStreamSource(mediaStreamSource);

                // Update the UI
                EndTrimSlider.Value        = 0;
                StatusTextBlock.Text       = "Trim Successful! Trim again or click the SAVE button to keep.";
                StatusTextBlock.Foreground = new SolidColorBrush(Colors.Green);
                SaveButton.IsEnabled       = true;
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception);
                throw;
            }
            finally
            {
                BusyOverlay.Visibility         = Visibility.Collapsed;
                EncodingProgressTextBlock.Text = "";
            }
        }