如何在 UWP 应用中播放 .mp3(或其他)文件? [英] How play a .mp3 (or other) file in a UWP app?

查看:14
本文介绍了如何在 UWP 应用中播放 .mp3(或其他)文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试试这个:

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

PlayMusic.Source = new Uri(@"C:UsersUserNameDesktopC:UsersuserDesktopKill The Alarm - Begin Again.mp3");
PlayMusic.Play();

显示屏上不再出现错误消息(try catch 运行干净).

No more error messages appear on the display (try catch runs clean through).

对不起,简短的描述...我可以很好地阅读和理解英语,但我很难说和写.

Sorry for the short description... I can read and understand English very well but it is difficult for me to talk and write.

推荐答案

每个 Windows 应用商店应用都有三个文件夹.一个本地文件夹、一个漫游文件夹和一个临时文件夹.每个都以相同的方式访问.本地旨在将资产存储在本地的、特定于应用程序的文件夹中.

Every Windows Store App has three folders. A Local folder, a Roaming folder and a Temp folder. Each is accessed the same way. Local is meant to store assets in a local, application-specific folder.

答案如下:

StorageFolder Folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
                Folder = await Folder.GetFolderAsync("MyFolder");
                StorageFile sf = await Folder.GetFileAsync("MyFile.mp3");
                PlayMusic.SetSource(await sf.OpenAsync(FileAccessMode.Read), sf.ContentType);
                PlayMusic.Play();

制造.

这篇关于如何在 UWP 应用中播放 .mp3(或其他)文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆