2014-03-28 104 views
0

我想从C#中的.mp3文件中为音频播放器检索详细信息。歌曲信息检索

代码剪断:

[DllImport("winmm.dll")] 

private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback); 

public static void Close() 
{ 
    _command = "close MediaFile"; 
    mciSendString(_command, null, 0, IntPtr.Zero); 
    isOpen = false; 
} 

public static void Open(string sFileName) 
{ 
    _command = "open \"" + sFileName + "\" type mpegvideo alias MediaFile"; 
    mciSendString(_command, null, 0, IntPtr.Zero); 
    isOpen = true; 
} 

public static void Play(bool loop) 
{ 
    if (isOpen) 
    { 
     _command = "play MediaFile"; 
     if (loop) 
      _command += " REPEAT"; 
     mciSendString(_command, null, 0, IntPtr.Zero); 
    } 
} 

我的问题是:

  • 我将如何设定歌曲的音量?
  • 我该如何获得歌曲的比特率/采样率?

我更喜欢使用MCI或NAudio,因为我知道它们的可靠性。

回答

1

要设置体积:

string command = "setaudio MediaFile volume to " + volume.ToString(); 
error = mciSendString(Pcommand, null, 0, IntPtr.Zero); 

其中体积为0和1000

有MCI命令串的整个列表上在MSDN上的多媒体参考之间的int:
set command

CodeProject上还有一个很好的示例项目,它可以完成大多数您正在尝试执行的操作: Simple MCI Player

HTH

保罗