简体   繁体   中英

Mediaelement not working WIndowsPhone8.1 (silverlight)

i've used a single mediaelement in my windows phone 8.1 silverlight app and changing its source using C#, my code

private void ButtonNextPage_Click(object sender, RoutedEventArgs e) { ImageLeftBelow.Style = ImageLeftShown.Style;

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

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

but my code is not working fine and not playing audio. I've also tried "ms-appx:///Assets/MP3/" + alpha + ".mp3" its also not working but my code working fine on window store app and windows phone 8.1 app. pease tell me how can i play multiple audio using a single mediaelement in windows phone 8.1 (silverlight)

I had a similar problem caused by having 3 MediaElements in the same page, make sure you only have one.

If it still doesn't work, this is tested:

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

(without the .Play(), add a MediaOpened event instead):

<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());

    }

if there is an error, you'll see its details in the output log.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM