-
Notifications
You must be signed in to change notification settings - Fork 1
/
MainWindow.xaml.cs
43 lines (33 loc) · 1.22 KB
/
MainWindow.xaml.cs
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
using System;
using Microsoft.UI.Xaml;
using Windows.Storage;
using Windows.Storage.Pickers;
using WinUIEx;
namespace FFmpegInteropX_WinUI_UnpackagedDemo;
public sealed partial class MainWindow : Window
{
readonly Windows.Media.Playback.MediaPlayer mediaPlayer = new();
FFmpegInteropX.FFmpegMediaSource mediaSource;
Windows.Storage.Streams.IRandomAccessStream stream;
public MainWindow()
{
InitializeComponent();
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
var picker = new FileOpenPicker();
picker.ViewMode = PickerViewMode.Thumbnail;
picker.SuggestedStartLocation = PickerLocationId.MusicLibrary;
picker.FileTypeFilter.Add("*");
WinRT.Interop.InitializeWithWindow.Initialize(picker, this.GetWindowHandle());
var file = await picker.PickSingleFileAsync();
if (file != null)
{
stream = await file.OpenAsync(FileAccessMode.Read);
mediaSource = await FFmpegInteropX.FFmpegMediaSource.CreateFromStreamAsync(stream);
mediaPlayer.Source = mediaSource.CreateMediaPlaybackItem();
mp.SetMediaPlayer(mediaPlayer);
mediaPlayer.Play();
}
}
}