2016-07-18 56 views
0

我有这个小片的C#代码C#MediaPlayer.MediaEnded事件不触发

//Creates a MediaPlayer with the sound you want to play 
    public static void PlaySound (Stream wavStream, string wavName, bool loop) 
    { 
     //Get the path for the file to play 
     var path = GetFilePath(wavStream, wavName); 

     var player = new MediaPlayer(); 
     player.Open(new Uri(path)); 
     player.MediaEnded += loop ? new EventHandler(MediaEndedLoop) : new EventHandler(MediaEndedDestroy); 
     player.Play(); 

     players.Add(player); 
     names.Add(wavName); 
    } 

我不知道为什么,但MediaEndedLoop和MediaEndedDestroy从来不被称为

任何想法?

回答

0

我也有这个问题。我找不到解决方案,但是如果媒体存在于循环应用程序或线程中,我确实想出了一个解决方法。您可以在某个点后手动重置位置。

if (media.Position > new TimeSpan(0, 2, 25)) 
     { 
      media.Position = new TimeSpan(0, 0, 00); 
     } 

这是我现在可以提供的最好的。