-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainPage.xaml.cs
More file actions
73 lines (60 loc) · 2.41 KB
/
MainPage.xaml.cs
File metadata and controls
73 lines (60 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Media.Editing;
using Windows.Storage.Pickers;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace FileMerger
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
private MediaComposition composition;
public MainPage()
{
this.InitializeComponent();
}
private async void Select_OnClick(object sender, RoutedEventArgs e)
{
var picker = new FileOpenPicker {SuggestedStartLocation = PickerLocationId.Desktop};
picker.FileTypeFilter.Add(".mp4");
var pickedFiles = await picker.PickMultipleFilesAsync();
if (pickedFiles == null) return;
TextBlock.Text = $"Importing {pickedFiles.Count} files";
composition = new MediaComposition();
var files = pickedFiles.OrderBy(x => x.Name).ToArray();
foreach (var file in files)
{
var clip = await MediaClip.CreateFromFileAsync(file);
composition.Clips.Add(clip);
TextBlock.Text = $"Importing {Path.GetFileName(file.Path)}";
}
TextBlock.Text = $"All files are imported";
}
private async void Merge_OnClick(object sender, RoutedEventArgs e)
{
var pickerSave = new FileSavePicker
{
SuggestedStartLocation = PickerLocationId.VideosLibrary
};
pickerSave.FileTypeChoices.Add("MP4 files", new List<string>() { ".mp4" });
pickerSave.SuggestedFileName = "merged clips.mp4";
var saveFile = await pickerSave.PickSaveFileAsync();
if (saveFile == null) return;
var saveOperation = composition.RenderToFileAsync(saveFile, MediaTrimmingPreference.Precise);
saveOperation.Progress = async (info, progress) =>
{
await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() =>
{
TextBlock.Text = $"Rendering... Progress: {progress:F0}%";
}));
};
}
}
}