2010-11-12 70 views
2

我在做什麼錯了,請打?的Windows Phone 7使用Silverlight - MediaElement的不使用此代碼

它不顯示任何錯誤,不玩了。

MediaElement song = new MediaElement(); 
     song.Source = new Uri(@"\WP7_aaa\WP7_aaa\GameSounds\MenuScreen.mp3", UriKind.Relative); 
     LayoutRoot.Children.Add(song); 
     song.AutoPlay = false; 
     song.Play(); 
+0

哦,我只需要改變LayoutRoot的網格內,例如:ContentPanel.children ... 。=) – Fulano 2010-11-12 19:45:01

回答

1

在項目中,爲MP3文件,有你 -

  1. 設置Build Action屬性Content
  2. 設置Copy To Output DirectoryCopy Always

如果你還沒有完成上述項目,嘗試出來。

HTH,indyfromoz

0

您必須指定一種開放的作爲RelativeOrAbsolute。

MediaElement song = new MediaElement(); 
song.Source = new Uri(@"\WP7_aaa\WP7_aaa\GameSounds\MenuScreen.mp3", UriKind.RelativeOrAbsolute); 
LayoutRoot.Children.Add(song); 
song.AutoPlay = false; 
song.Play(); 
1

您需要等待歌曲加載後才能調用Play方法。

你想要的是:

MediaElement song = new MediaElement(); 
song.Source = new Uri("Audio/background.mp3", UriKind.Relative); 
song.MediaOpened += MediaElement_MediaOpened; 

然後在事件處理程序:

private void MediaElement_MediaOpened(object sender, RoutedEventArgs e) 
    { 
     (sender as MediaElement).Play(); 
    } 

See this thread for more details。 (編輯:不知道在哪裏,現在發現這個線索,他們將它分成WP和Xbox論壇...)

相關問題