获得MP3文件长度 [英] Getting mp3 file length
问题描述
我目前正在在C#编写一个音频播放器。我使用的BASS库来处理播放音乐,但现在我有小问题,让歌曲的长度。
I am currently trying to write an Audio Player in C#. I am using BASS library to deal with playing music but now i have small problem with getting length of the song.
嗯,我已经阅读BASS doc和找到了一个方法:
全部我需要做的就是
Well i have read BASS doc and found a way: "All" i need to do is
int stream = Bass.BASS_StreamCreateFile(filepath,....);
int length = Bass.BASS_ChannelBytes2Seconds(stream, Bass.BASS_ChannelGetLength(stream));
和在大多数情况下,我得到的歌曲有效长度。这里的问题开始。据我所知流创建操作是相当昂贵(纠正我,如果我错了),并创建一个流只有拿到这首歌的长度看起来有点傻。
And in most of cases i get valid length of song. And here the problem starts. As far as i know the stream creation operation is quite expensive (correct me if i am mistaken) and creating a stream only to get length of the song looks a little silly.
所以我的问题是:是否有任何其他方式得到它,而无需创建蒸汽文件(不是如此昂贵)。我将在以后考虑阅读的ID3标签。正在创造流邪恶必须不管是什么做的,即使我会尝试用它会做同样的事情其他图书馆得到它?
So my question is: Is there any other way to get it without creating steam file (not being so expensive). I will be thinking later about reading id3 tags. Is creating that stream "evil that must be done no matter what" and even if i would try to get it with other library it would do exactly the same thing?
推荐答案
您可以使用的 Microsoft.WindowsAPICodePack.Shell :
using Microsoft.WindowsAPICodePack.Shell;
然后,像这样的代码:
Then code like so:
string file = "myfile.mp3"
ShellFile so = ShellFile.FromFilePath(file);
double nanoseconds;
double.TryParse(so.Properties.System.Media.Duration.Value.ToString(), out nanoseconds);
有一个的代码项目,可以帮助你以及
这篇关于获得MP3文件长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!