DispatcherTimer timer2 = new DispatcherTimer();
timer2.Interval = TimeSpan.FromMilliseconds(33);
timer2.Tick += delegate { try { FrameworkDispatcher.Update(); } catch { } };
timer2.Start();
private void playSound()
{
// SongCollection mySongCollection;
Song sound = Song.FromUri("music", new Uri("/sound/welcome.mp3", UriKind.RelativeOrAbsolute));
MediaPlayer.Play(sound);
MediaPlayer.MediaStateChanged += new EventHandler<EventArgs>(MediaPlayer_MediaStateChanged);
}
void MediaPlayer_MediaStateChanged(object sender, EventArgs e)
{
if (
MediaPlayer.State == MediaState.Paused) //而不是 MediaState.Stop
{
Song sound = Song.FromUri("music", new Uri("/sound/olderHomepage2.mp3", UriKind.RelativeOrAbsolute));
MediaPlayer.Play(sound);
}
}
或者
Song sound = Song.FromUri("music", new Uri("/sound/welcome.mp3", UriKind.RelativeOrAbsolute));
FrameworkDispatcher.Update();
MediaPlayer.Play(sound);