如何在 window 2 中显示来自 window 1 的视频?

How to display a video in window 2 from window 1?

目前我正在使用 window 通用应用程序显示和播放视频的教程,我几乎理解了这个过程,但我卡在另一个 window 中的视频显示上(window2),从第window开始上传(window1)如下图:

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();
}

在Windows Universal Application(我相信Windows 8/8.1 环境)中,您可以使用弹出窗口来实现此功能。使用"Media Element"实现视频播放

怎么做? -

<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;
} 

我想这是根据您的要求最简单和最好的解决方案。

根据您的快照,您似乎找到了这样的解决方案:

A music player app that lets users see what's playing while browsing through a list of other available music.

如果我的理解是正确的,你可以利用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();
    }

媒体数据class:

public class MediaData
{
    public IRandomAccessStream stream { get; set; }
    public StorageFile file { get; set; }
}