简体   繁体   中英

Xamarin Forms with Windows phone - MediaElement not working

I created Windows Phone 8.1 app with Xamarin Forms. I used MediaElement in MainPage.xaml and I use wav file(path Assets/ring.wav) It is my code:

<forms:WindowsPhonePage 
 ....>

<Grid>
    <MediaElement Name="PlayElement"
                  MediaOpened="PlayElement_OnMediaOpened"
                  MediaFailed="PlayElement_OnMediaFailed"
                  AutoPlay="False"/>
</Grid>

It is code behind :

protected override void OnNavigatedTo(NavigationEventArgs e)
{
   PlayElement.Source = new Uri("ms-appx:///Assets/ring.wav", UriKind.RelativeOrAbsolute);
}

I use DependencyService in Xamarin, but I have not sound. I have not exception - my code worked - and I have silence. My event PlayElement_OnMediaOpened - not working. I create test project for Windows Phone 8.1 and it is work. Any ideas?

I found this post . The author advises to use MediaPlayer(in background). I decided to use toast notification. MediaElement is not working for me.

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