Uwp 关于Media Player为何会阻止用户界面输入30秒的任何信息
我正在我的UWP应用程序中运行一个短视频,同时在后台完成许多其他任务。如果用户不想观看视频,则会为他们提供一个跳过视频按钮。但是,该按钮在视频播放约30秒后不会激活 我想可能是我的后台任务阻塞了UI,但它们在5-7秒内就完成了。我还认为可能是视频加载导致了问题,但它只有3分钟长,所以我不认为缓冲需要那么长的时间 以下是我用于页面的XAML:Uwp 关于Media Player为何会阻止用户界面输入30秒的任何信息,uwp,Uwp,我正在我的UWP应用程序中运行一个短视频,同时在后台完成许多其他任务。如果用户不想观看视频,则会为他们提供一个跳过视频按钮。但是,该按钮在视频播放约30秒后不会激活 我想可能是我的后台任务阻塞了UI,但它们在5-7秒内就完成了。我还认为可能是视频加载导致了问题,但它只有3分钟长,所以我不认为缓冲需要那么长的时间 以下是我用于页面的XAML: <Page x:Class="Cgs.Ux.Views.MainMenu" xmlns="http://schemas.microso
<Page
x:Class="Cgs.Ux.Views.MainMenu"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Cgs.Ux"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:userControls="using:Cgs.Ux.UserControls"
xmlns:help="using:Cgs.Ux.UserControls.Help"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<RelativePanel RequestedTheme="Light">
<Image Source="{x:Bind Vm.PlainBackgroundImage, Mode=OneWay, Converter={StaticResource ImageConverter}}"
Stretch="Fill"/>
<Viewbox RelativePanel.AlignBottomWithPanel="True" RelativePanel.AlignTopWithPanel="True"
RelativePanel.AlignLeftWithPanel="True" RelativePanel.AlignRightWithPanel="True">
<Grid>
<Image Source="{x:Bind Vm.BackgroundImage, Mode=OneWay, Converter={StaticResource ImageConverter}}"
RelativePanel.AlignVerticalCenterWithPanel="True" RelativePanel.AlignHorizontalCenterWithPanel="True"
Height="1080" Width="1920" Opacity=".5"/>
<!--Media Player-->
<MediaPlayerElement
Name="MediaSimple"
Source="ms-appx:///Assets/Videos/Transfer Items Alpha 2.mp4"
Width="1920" Height="1080" AutoPlay="False" Visibility="Collapsed">
</MediaPlayerElement>
<Button
Name="SkipVideo"
VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="30"
Content="Skip Video" Height="100" Width="400" Background="White"
Visibility="{x:Bind Vm.SkipVideoVisible, Mode=OneWay}"
PointerEntered="OnPointerEntered"
Click="{x:Bind Vm.SkipVideo}"/>
</Grid>
</Viewbox>
<ProgressRing
RelativePanel.AlignHorizontalCenterWithPanel="True" RelativePanel.AlignVerticalCenterWithPanel="True"
Width="100" Height="100" Foreground="NavajoWhite" IsActive="{x:Bind Vm.IsBusy, Mode=OneWay}" />
</RelativePanel>
</Page>
我希望按钮应该立即可用,或者几乎立即可用。我试图创建一个独立的项目来复制这个问题。不幸的是,我的独立项目都工作得很好。我的独立项目和失败项目之间的区别在于视频启动时我启动的后台任务 我最初认为后台任务阻塞了UI的想法是正确的。我将后台任务修改为在单独的线程上运行,媒体播放器和跳过视频按钮工作得非常好 将后台任务移动到自己的线程后,应用程序在整理错误时开始失败,因为后台任务正在尝试与UI对话。这解释了为什么后台任务阻塞UI长达30秒,而我预期它将在5-7秒内完成
故事的寓意是,不要在UI线程上运行后台任务,并期望UI正常运行。您的代码不完整。请提供更多的诊断。我已经更新了原来的帖子,包括更多的代码。OnPointerEntered事件处理程序仅用于标识按钮何时变为活动状态。抱歉,我无法为您提供更多帮助。你仍然没有提供一份报告。我试图将您的代码复制到我的新空白项目中进行测试。但是有很多错误。我甚至不能调试它。如果你想从社区成员那里得到帮助,你需要改进你的问题。请先阅读。我以前从来没有在这里提供过一个完整的工作项目。我不知道你在找什么。
public void PlayMedia()
{
MediaSimple.MediaPlayer.Play();
MediaSimple.Visibility = Visibility.Visible;
}
public void SkipVideo()
{
View.StopVideo();
_introVideoFinished = true;
if (_soloGameLoaded && _introVideoFinished) GotoGame();
}
private void OnPointerEntered(object sender, PointerRoutedEventArgs e)
{
Debug.WriteLine("Pointer Entered");
}