目前我发布了一个可以使用窗口通用应用程序显示和播放视频的教程,我几乎理解了这个过程,但我被困在另一个窗口(window2)的视频显示中,从第一个窗口(窗口1)上传为如下图所示:
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();
}
窗口1
//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();
}
答案 0 :(得分:0)
在Windows Universal Application(我相信的Windows 8 / 8.1环境)中,您可以使用弹出窗口来实现此功能。使用“媒体元素”实现视频播放。
怎么做? -
<Popup x:Name="popupMediaPlay" IsOpen="false">
<MediaElement x:Name="mediaPlayer"
Width="400" Height="300"
AutoPlay="True"/>
</Popup>
public async void GetMedia()
{
var openPicker = new FileOpenPicker();
openPicker.SuggestedStartLocation = PickerLocationId.VideosLibrary;
openPicker.FileTypeFilter.Add(".wmv");
openPicker.FileTypeFilter.Add(".mp`enter code here`4");
var file = await openPicker.PickSingleFileAsync();
var stream = await file.OpenAsync(FileAccessMode.Read);
//While assigning the source you may need to provide the path/url of the
video.
mediaPlayer.Source = stream;
popupMediaPlay.IsOpen = true;
}
我想根据您的要求,这将是最简单和最佳的解决方案。
答案 1 :(得分:0)
根据您的快照,您看起来像找到这样的解决方案:
如果我的理解是正确的,您可以使用CoreApplication.CreateNewView()
。
这是一个示例代码:
在MainPage.xaml
中 <Button Content="Select media file" Click="Button_Click_1"/>
<Button Content="PlayInNewWindow" Click="Button_Click" />
在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();
}
在NewWindowPage.xaml
<MediaElement Name="newMedia"/>
在NewWindowPage.xaml.cs
中 protected override void OnNavigatedTo(NavigationEventArgs e)
{
var mediaData = (MediaData)e.Parameter;
newMedia.SetSource(mediaData.stream, mediaData.file.ContentType);
newMedia.Play();
}
MediaData类:
public class MediaData
{
public IRandomAccessStream stream { get; set; }
public StorageFile file { get; set; }
}