Currently I flow a tutorial that can display and play a video using window universal application and I almost understand the process but I am stuck on the video display in another window (window2),Upload from the first window (window 1) as in the figure below:
public async void GetMedia()
{
var openPicker = new FileOpenPicker();
openPicker.SuggestedStartLocation = PickerLocationId.VideosLibrary;
openPicker.FileTypeFilter.Add(".wmv");
openPicker.FileTypeFilter.Add(".mp4");
var file = await openPicker.PickSingleFileAsync();
var stream = await file.OpenAsync(FileAccessMode.Read);
media.SetSource(stream, file.ContentType);
media.Play();
}
Window1
//Click boutton for upload video
private void b_Click_1(object sender, RoutedEventArgs e)
{
Screen s=new Screen(); // window 2
//display and play video to window 2
s.GetMedia();
}
Based on your snapshot, you look like finding a solution like this:
If my understanding is correct, you can utilize CoreApplication.CreateNewView()
.
And here is a sample code:
In MainPage.xaml
<Button Content="Select media file" Click="Button_Click_1"/>
<Button Content="PlayInNewWindow" Click="Button_Click" />
In MainPage.xaml.cs
public static IRandomAccessStream stream = null;
public StorageFile file = null;
public async void GetMedia()
{
var openPicker = new FileOpenPicker();
openPicker.SuggestedStartLocation = PickerLocationId.VideosLibrary;
openPicker.FileTypeFilter.Add(".wmv");
openPicker.FileTypeFilter.Add(".mp4");
file = await openPicker.PickSingleFileAsync();
stream = await file.OpenAsync(FileAccessMode.Read);
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
CoreApplicationView newView = CoreApplication.CreateNewView();
int newViewId = 0;
await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
Frame frame = new Frame();
MediaData mediaData = new MediaData();
mediaData.stream = stream;
mediaData.file = file;
frame.Navigate(typeof(NewWindowPage), mediaData);
Window.Current.Content = frame;
Window.Current.Activate();
newViewId = ApplicationView.GetForCurrentView().Id;
});
bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
GetMedia();
}
In NewWindowPage.xaml
<MediaElement Name="newMedia"/>
In NewWindowPage.xaml.cs
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var mediaData = (MediaData)e.Parameter;
newMedia.SetSource(mediaData.stream, mediaData.file.ContentType);
newMedia.Play();
}
MediaData class:
public class MediaData
{
public IRandomAccessStream stream { get; set; }
public StorageFile file { get; set; }
}