我想问一下如何在应用程序中获取音频文件的长度。
我正在像这样加载曲目
var installFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
var resourcesFolder = await installFolder.GetFolderAsync("Resources");
var mp3FilesFolder = await resourcesFolder.GetFolderAsync("mp3Files");
var audioFile = await mp3FilesFolder.GetFileAsync("sound.mp3");
var stream = await audioFile.OpenAsync(Windows.Storage.FileAccessMode.Read);
mediaplayer.SetSource(stream, audioFile.ContentType);
mediaplayer.Play();
但我不知道如何获得曲目的持续时间?
有两种方法可以获取曲目的持续时间:
- 首先是直接从文件中读取它音乐属性 http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.fileproperties.musicproperties通过使用GetMusicPropertiesAsync() http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.fileproperties.storageitemcontentproperties.getmusicpropertiesasync:
var audioFile = await mp3FilesFolder.GetFileAsync("sound.mp3");
MusicProperties properties = await audioFile.Properties.GetMusicPropertiesAsync();
TimeSpan myTrackDuration = properties.Duration;
- 第二个选项是获取它的自然持续时间 from 媒体元素 or 背景媒体播放器
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)