如何在Windows Phone中获取wav文件的长度
我想获取波形文件的长度。目前我正在使用以下代码
using (IsolatedStorageFile isofile = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isostream = new IsolatedStorageFileStream(FilePath, System.IO.FileMode.Open,System.IO.FileAccess.Read, isofile))
{
me = new MediaElement();
me.SetSource(isostream);
}
}
embedVoiceLength = me.NaturalDuration.TimeSpan.TotalSeconds;
但是,它不会返回 naturalduration.timespan.totalseconds
的长度,因为 me
未打开;
I jwant to get length of wave file. Currently I'm using following code
using (IsolatedStorageFile isofile = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isostream = new IsolatedStorageFileStream(FilePath, System.IO.FileMode.Open,System.IO.FileAccess.Read, isofile))
{
me = new MediaElement();
me.SetSource(isostream);
}
}
embedVoiceLength = me.NaturalDuration.TimeSpan.TotalSeconds;
However, it doesn't return the length from naturalduration.timespan.totalseconds
, because me
is not opened;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果在打开文件之前无法获取长度,请尝试打开它。
如果您想要的只是长度而不是实际播放它,请处理 MediaOpened 事件,并在触发该事件时获取长度,然后停止播放。
If you can't get the length until the file is opened then try opening it.
If all you want is the length and to not actually play it then handle the
MediaOpened
event and when it is triggered get the length and then stop the playback.您可以使用如下内容:
我从一篇有关在 WP7 上处理音频的有趣文章中挑选了此示例代码。 在这里,代码也可供下载。希望这有帮助! :)
You can use something like this:
I picked this sample code from an interesting article on working with audio on WP7. Here it is, code is also available for download. Hope this helps! :)