Experiment with removing the static MediaPlayer

Somehow, this also causes an exception on teardown north of
  `Windows.Media.MediaControl.dll!AudioStateMonitorImpl::remove_SoundLevelChanged()`,
  which is in OS code somewhere. Not sure there's anything we can actually do
  about this. There are piles of bugs on that function in the OS repo.

  I think we're going to have to just end up avoiding this entirely.
This commit is contained in:
Mike Griese 2021-11-16 09:38:40 -06:00
parent 2eda14cc1b
commit fb1ed58d37
4 changed files with 25 additions and 17 deletions

View file

@ -33,7 +33,7 @@ static const Duration AnimationDuration = DurationHelper::FromTimeSpan(winrt::Wi
winrt::Windows::UI::Xaml::Media::SolidColorBrush Pane::s_focusedBorderBrush = { nullptr };
winrt::Windows::UI::Xaml::Media::SolidColorBrush Pane::s_unfocusedBorderBrush = { nullptr };
winrt::Windows::Media::Playback::MediaPlayer Pane::s_bellPlayer = { nullptr };
// winrt::Windows::Media::Playback::MediaPlayer Pane::s_bellPlayer = { nullptr };
Pane::Pane(const Profile& profile, const TermControl& control, const bool lastFocused) :
_control{ control },
@ -71,14 +71,14 @@ Pane::Pane(const Profile& profile, const TermControl& control, const bool lastFo
e.Handled(true);
});
if (!s_bellPlayer)
{
try
{
s_bellPlayer = winrt::Windows::Media::Playback::MediaPlayer();
}
CATCH_LOG();
}
// if (!s_bellPlayer)
// {
// try
// {
// s_bellPlayer = winrt::Windows::Media::Playback::MediaPlayer();
// }
// CATCH_LOG();
// }
}
Pane::Pane(std::shared_ptr<Pane> first,
@ -1125,13 +1125,13 @@ winrt::fire_and_forget Pane::_playBellSound(winrt::Windows::Foundation::Uri uri)
co_await winrt::resume_foreground(_root.Dispatcher());
if (auto pane{ weakThis.get() })
{
if (s_bellPlayer)
{
auto source{ winrt::Windows::Media::Core::MediaSource::CreateFromUri(uri) };
auto item{ winrt::Windows::Media::Playback::MediaPlaybackItem(source) };
s_bellPlayer.Source(item);
s_bellPlayer.Play();
}
// if (s_bellPlayer)
// {
// auto source{ winrt::Windows::Media::Core::MediaSource::CreateFromUri(uri) };
// auto item{ winrt::Windows::Media::Playback::MediaPlaybackItem(source) };
// s_bellPlayer.Source(item);
// s_bellPlayer.Play();
// }
}
}

View file

@ -229,7 +229,7 @@ private:
bool _zoomed{ false };
static winrt::Windows::Media::Playback::MediaPlayer s_bellPlayer;
// static winrt::Windows::Media::Playback::MediaPlayer s_bellPlayer;
bool _IsLeaf() const noexcept;
bool _HasFocusedChild() const noexcept;

View file

@ -56,6 +56,12 @@ namespace winrt::TerminalApp::implementation
_hostingHwnd{}
{
InitializeComponent();
try
{
_bellPlayer = winrt::Windows::Media::Playback::MediaPlayer();
}
CATCH_LOG();
}
// Method Description:

View file

@ -201,6 +201,8 @@ namespace winrt::TerminalApp::implementation
std::shared_ptr<Toast> _windowIdToast{ nullptr };
std::shared_ptr<Toast> _windowRenameFailedToast{ nullptr };
winrt::Windows::Media::Playback::MediaPlayer _bellPlayer{ nullptr };
void _ShowAboutDialog();
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> _ShowQuitDialog();
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> _ShowCloseWarningDialog();