Skip to content

Commit

Permalink
Experiment with removing the static MediaPlayer
Browse files Browse the repository at this point in the history
  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.
  • Loading branch information
zadjii-msft committed Nov 16, 2021
1 parent 2eda14c commit fb1ed58
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
32 changes: 16 additions & 16 deletions src/cascadia/TerminalApp/Pane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
// }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/Pane.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class Pane : public std::enable_shared_from_this<Pane>

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;
Expand Down
6 changes: 6 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ namespace winrt::TerminalApp::implementation
_hostingHwnd{}
{
InitializeComponent();

try
{
_bellPlayer = winrt::Windows::Media::Playback::MediaPlayer();
}
CATCH_LOG();
}

// Method Description:
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit fb1ed58

Please sign in to comment.