如何从窗口1在窗口2中显示视频?

问题描述:

目前我流动的教程,可以显示和播放视频使用窗口通用应用程序,我几乎理解的过程,但我被卡在视频显示在另一个窗口(窗口2),上传从第一个窗口(窗口1)如下图所示:如何从窗口1在窗口2中显示视频?

enter image description here

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

根据您的快照,你看起来就像找到这样一个解决方案:

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.xa中

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

谢谢,它的工作原理。我使用Windows 10 IOT作为操作系统的Raspberry Pi 3进行了测试,视频选择上存在错误,是否有其他协议可以使用树莓上传视频。 –

在Windows通用应用程序(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; 
} 

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

+0

是的,但我想在主窗口外面显示视频:ml.cs

protected override void OnNavigatedTo(NavigationEventArgs e) { var mediaData = (MediaData)e.Parameter; newMedia.SetSource(mediaData.stream, mediaData.file.ContentType); newMedia.Play(); } 

MediaData类。在您的代码中,即使在主窗口中也会显示弹出窗口 –

+0

如果您的要求是要感觉它在另一个窗口上运行,那么您可以使Popup处于全屏状态,并始终将其IsOpen属性设置为true。 – Dash

+0

感谢破折号,我最后的问题是什么可以删除第二个窗口的标题,我想第二个窗口没有调整大小或关闭图标。 –