0
votes

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)

1
Are the mp3 files build action set to content?Ken Tucker
my code is working fine, not giving me any error but my mediaelement not giving any response, i have this issue on windowphone 8.1(silverlight)app but my code works successfully on windowsphone8.1 appDanish
I think your uri is wrong. Try something like this new uri(Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, @"MP3/" + alpha + ".mp3")Ken Tucker

1 Answers

4
votes

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.