How play a .mp3 (or other) file in a UWP app?

后端 未结 4 1134
眼角桃花
眼角桃花 2021-01-02 08:17

I try this:

PlayMusic = new MediaElement();
PlayMusic.AudioCategory = Windows.UI.Xaml.Media.AudioCategory.Media;

PlayMusic.Source = new Uri(@\"C:\\Users\\Us         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-02 08:29

    Put mySong.mp3 in your Assets folder. Then in Visual Studio, right click on your Assets folder and select "add existing item". Add mySong.mp3 FROM your Assets folder. In XAML, add a player:

     
    

    In c#, mySong.mp3 will play when you set the source:

     Uri newuri = new Uri("ms-appx:///Assets/mySong.mp3");
     myPlayer.Source = newuri;
    

提交回复
热议问题