How to use `MediaElement` to play sound in Android?

♀尐吖头ヾ 提交于 2020-01-14 04:00:31

问题


I'm using MediaElement to play sound in an Uno-Platform project.

It plays well in the UWP project but doesn't work in the Android project.

The audio file is located in the shared project as Exclude from project, and is linked in the UWP project as Content and in the Droid project as AndroidAsset.

XAML:

<MediaElement Source="/Assets/MySound.wav"/> 

I've also tried accessing it programmatically set the Source to ms-appx:///Assets/MySound.wav with no success.


回答1:


MediaPlayerElement is now available in Uno (See MediaPlayerElement documentation)




回答2:


As of today, local resources are not supported for iOS in the the Windows.Media.Playback.MediaPlayer class, but adding support for it should be relatively easy.

On Android, it should work, but there's probably another issue, related to the name of the asset, such as casing (android is lower case) or hyphens (transformed to '_' by android).



来源:https://stackoverflow.com/questions/52919882/how-to-use-mediaelement-to-play-sound-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!