【问题标题】:How can I play sound file (mp3,wav,etc) directly with no associated application?如何在没有关联应用程序的情况下直接播放声音文件(mp3、wav 等)?
【发布时间】:2009-07-17 09:21:17
【问题描述】:

我还需要能够控制它的音量。 另外,如何控制系统音量,以检测低音量或静音状态?

【问题讨论】:

    标签: delphi winapi audio


    【解决方案1】:

    使用 Shoban 的链接了解如何播放声音。

    以下是控制设备音量的方法:

    uses MMSystem;
    
    type
       TVolumeRec = record
         case Integer of
           0: (LongVolume: Longint) ;
           1: (LeftVolume, RightVolume : Word) ;
         end;
    
    const DeviceIndex=5
           {0:Wave
            1:MIDI
            2:CDAudio
            3:Line-In
            4:Microphone
            5:Master
            6:PC-loudspeaker}
    
    procedure SetVolume(aVolume:Byte) ;
    var 
      Vol: TVolumeRec;
    begin
       Vol.LeftVolume := aVolume shl 8;
       Vol.RightVolume:= Vol.LeftVolume;
       auxSetVolume(UINT(DeviceIndex), Vol.LongVolume) ;
    end;
    
    function GetVolume:Cardinal;
    var 
      Vol: TVolumeRec;
    begin
       AuxGetVolume(UINT(DeviceIndex),@Vol.LongVolume) ;
       Result:=(Vol.LeftVolume + Vol.RightVolume) shr 9;
    end;
    

    【讨论】:

      【解决方案2】:

      如果这是用于非商业用途,BASS 库是免费的,可为您提供所需的控制。

      3DBuzz 上有免费的视频教程,其中之一是创建自己的 MP3 播放器。它们位于首页的视频类别列表中。

      【讨论】:

        【解决方案3】:

        看看这篇文章:Your first MP3 Delphi player。它使用 TMediaPlayer 来播放 mp3 文件。不完全是你想要的,但是一个很好的起点。

        【讨论】:

          【解决方案4】:

          只需使用 MM api(MSDN 和 google 上的大量示例)

          【讨论】:

            【解决方案5】:
            char *mp3FilePath    = ...   ;
            char *workingDirPath = ...   ;
            ShellExecute(hwnd, "open", mp3FilePath, NULL, workingDirPath, SW_SHOWNORMAL);
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2014-04-10
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2010-11-24
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多