microsoft-ui-xaml: AnimatedVisualPlayer::PlayAsync should internally wait for the AnimatedVisual to load instead of silently failing
If PlayAsync is called before the AnimatedVisual is loaded, nothing happens, yet the IAsyncAction reports success.
The app developer has to write code like this, whereas it would make more sense for AnimatedVisualPlayer to handle this complexity internally.
`
// We have to wait until the player successfully loads its animation before we can call Play!
auto notifyPropertyChanged = m_animatedVisualSource.as<winrt::Windows::UI::Xaml::Data::INotifyPropertyChanged>();
m_animatedVisualPropertyChangedRegistration = notifyPropertyChanged.PropertyChanged(
[player, loop = m_loop](const auto& sender, const winrt::Windows::UI::Xaml::Data::PropertyChangedEventArgs& args)
{
// If the visual is loaded, we're ready to PlayAsync!
if (winrt::to_string(args.PropertyName()) == "IsImageLoadingCompleted")
{
player.PlayAsync(0, 1.0, loop);
}
});
// Kick off play now if the visuals are already loaded
if (player.IsAnimatedVisualLoaded())
{
player.PlayAsync(0, 1.0, m_loop);
}
`
An interesting additional bug is that calling PlayAsync before a visual is loaded also breaks AutoPlay (nothing plays after the visual finally loads). Not sure if that should be filed as a separate issue.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 20 (3 by maintainers)
@simeoncran as well. Personally I’d expect that if I call PlayAsync the animation should play as soon as possible. If that means waiting for the load then so be it. If you need fine control over the timing then you can still respond to the events however you want right?
I’d expect it to just work too, and for the more advanced case you could monitor events (is there an event)?
What do BitmapImage.Play (aka AniGif) and MediaPlayerElement (MediaPlayer.Play) do?