8.1 Windows ストア アプリで再生するビデオがあり、他のページに移動した後もオーディオを再生し続けたい..私は visualTreeHelper を使用してそれを行ったので、app.xaml でメディア要素を宣言し、app.xaml.cs のフレームに追加します。 、そして playingPage でそれを取得します。問題は、メディア要素コントロールがオーディオのみを再生し、ビデオが表示されないことです..ナビゲーション後にオーディオが再生され続けますが、再生ページでビデオが表示されません(オーディオのみ):これが私が入れたものですstandardstyles.xaml :
<Style x:Key="RootFrameStyle" TargetType="Frame">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Frame">
<Grid>
<MediaElement x:Name="player" AudioCategory="BackgroundCapableMedia" />
<Grid>
<ContentPresenter />
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
これはapp.xaml.csにあります
rootFrame.Style = Resources["RootFrameStyle"] as Style;
playingPage.xaml に MediaElement コントロールを追加します。
<ContentControl x:Name="videoContainer" HorizontalAlignment="Stretch" VerticalAlignment="Center"
Grid.Row="0" Grid.Column="1"
KeyUp="VideoContainer_KeyUp" >
<MediaElement x:Name="player" AudioCategory="BackgroundCapableMedia"
Visibility="Visible" Grid.Row="0" Grid.Column="1" AutoPlay="True"
HorizontalAlignment="Center" VerticalAlignment="Center"
MediaOpened="player_Opened"
MediaEnded="player_Ended"
MediaFailed="player_Failed"
Position="10"
CurrentStateChanged="player_CurrentStateChanged" />
</ContentControl>
そしてその背後にあるコードで:
DependencyObject rootGrid = VisualTreeHelper.GetChild(Window.Current.Content, 0);
player = (MediaElement)VisualTreeHelper.GetChild(rootGrid, 0) as MediaElement;
player.Source = video.VideoLink;
`
ナビゲーション後にオーディオを動作させようとしないとすべてうまく機能するので、ビジュアル ツリー ヘルパーを使用しない場合、この状況ではオーディオは期待どおりに動作しますが、再生中のページでビデオを見ることができません (オーディオのみ)