2017-09-15 7 views
0

現在、私はウィンドウユニバーサルアプリケーションを使用してビデオを表示して再生できるチュートリアルを流しています。プロセスをほとんど理解していますが、別のウィンドウ(window2)でビデオ表示に固執しています。下図:Windowsの汎用アプリケーション(私は信じているのWindows 8/8.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(); 
} 

答えて

0

あなたのスナップショットに基づいて、あなたはこのような解決策を見つけるように見える:

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

私の理解が正しければ、あなたはCoreApplication.CreateNewView()を利用することができます。 NewWindowPage.xaml

<MediaElement Name="newMedia"/> 

で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.xaでml.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; } 
} 
+0

ありがとう、それは動作します。私はWindows 10のIOTをオペレーティングシステムとして使用するRaspberry Pi 3でテストしました。ビデオの選択にバグがあり、ラズベリーでビデオをアップロードするための他のプロトコルがあります。 –

0

は、あなたがこれを達成するために、ポップアップを使用することができます機能性。ビデオの再生を実現するには、「メディア要素」を使用します。

どうすればよいですか? -

<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

はい、私は、メインウィンドウの外にビデオを表示したいと思います。あなたのコードでは、メインウィンドウにもポップアップが表示されます –

+0

別のウィンドウで実行されていると感じるようにするには、ポップアップを全画面にして、常にIsOpenプロパティをtrueに設定します。 – Dash

+0

ありがとうダッシュ、私の最後の質問は、2番目のウィンドウのヘッダーを削除することが可能ですが、私は2番目のウィンドウのサイズが変更されていないか、アイコンで閉じることです。 –

関連する問題