2014-08-31 48 views
0

我在我的Windows Phone 8.1的Silverlight应用程序,并使用C#改变其源使用单一的MediaElement(Silverlight的),我的代码MediaElement的工作不WIndowsPhone8.1

私人无效ButtonNextPage_Click(对象发件人,RoutedEventArgs E) ImageLeftBelow.Style = ImageLeftShown.Style;

alpha += 1; 
    alphaplay.Source = new Uri("///Assets/MP3/" + alpha + ".mp3"); 

    alphaplay.Play(); 
    if (alpha ==26) 
    { 
     next.IsEnabled = false; 
    } 
} 

但我的代码工作不正常,没有播放音频。我也试过 "ms-appx:///Assets/MP3/" + alpha + ".mp3"它也没有工作,但我的代码在window store应用和windows phone 8.1应用中工作正常。 pease告诉我如何在windows phone 8.1(silverlight)中使用单个mediaelement播放多个音频

+0

MP3文件是否将操作设置为内容? – 2014-08-31 13:18:11

+0

我的代码工作正常,不给我任何错误,但我的mediaelement没有给予任何回应,我有windowphone 8.1(silverlight)应用程序的这个问题,但我的代码在windowsphone8.1上成功运行的应用程序 – Danish 2014-08-31 17:19:24

+0

我认为你的uri是错误的。尝试类似这个新的URI(Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path,@“MP3 /”+ alpha +“.mp3”)) – 2014-08-31 20:56:47

回答

4

我有一个类似的问题,因为在同一页面中有3个MediaElement,请确保您只有一个。

如果仍然无法正常工作,这是测试:

Sound.Source = new Uri("Assets/MP3/" + alpha + ".mp3", UriKind.Relative); 

(不.Play(),添加一个MediaOpened事件代替):

<MediaElement x:Name="Sound" AutoPlay="False" 
        MediaOpened="Sound_MediaOpened" 
        MediaFailed="Sound_MediaFailed" /> 

|

private void Sound_MediaOpened(object sender, RoutedEventArgs e) 
    { 
     Sound.Play(); 
    } 

    private void Sound_MediaFailed(object sender, ExceptionRoutedEventArgs e) 
    { 
     System.Diagnostics.Debug.WriteLine(e.ErrorException.Message + " ERROR playing sound " + Sound.Source.ToString()); 

    } 

如果出现错误,您会在输出日志中看到它的详细信息。