ページ間で音楽を再生するために使用する MediaElement があります。したがって、App.xaml のリソースとして保持する必要がありました。
WPでWindowsボタンを押すまで、物事は期待どおりに機能します。アプリケーションが廃棄され、MediaElement が期待どおりに再生を停止します。Application_Deactivated で、Player.Stop() を明示的に呼び出します。
アプリケーションを復元すると問題が発生します。他のすべての状態が復元されますが、メディア要素は音楽を再生しません。音楽を担当するコードがヒットしていることがわかりますが、MediaElement の MediaOpened は起動されていません。明らかな何かが欠けていますか?
編集 [KeyboardP の質問を明確にするため]
<Application.Resources>
<MediaElement x:Name="ME" MediaEnded="RepeatMedia" Volume="1" AutoPlay="False" Height="0" Source="/Sounds/mywave.wav" />
</Application.Resources>
私の App.XAML.CS には、... というメソッドがあります。
public MediaElement player = null;
private void InitializeMusic()
{
if (App.Current.Resources.Contains("ME"))
{
player = App.Current.Resources["ME"] as MediaElement;
}
player.MediaOpened += player_MediaOpened;
}
私はそれを再び初期化しています...
// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{
InitializeMusic();
}