1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【VBA】mciSendString APIを用いた際に音源ファイルの音量がSetAudioで操作できない問題を解消

Last updated at Posted at 2020-05-08

メモとして残します。

mciSendString APIでwavファイルを音量小さく再生したかったのですが、
setaudioコマンドが何故か効かない。
オープンした際にtype mpegvideoがなかったのが原因だった。

■やり方

'APIを使えるように宣言
Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long


Sub test()
    SoundFile = Chr(34) & "C:\Windows\Media\chord.wav" & Chr(34)
       
    rc = mciSendString("Close MySound", "", 0, 0)
    '重量なのはこいつ↓ エイリアスの次に必ず「type mpegvideo」とつけないと音量が操作できない
    rc = mciSendString("Open " & SoundFile & " alias MySound type mpegvideo", "", 0, 0)
    rc = mciSendString("setaudio MySound volume to 1000", "", 0, 0)
    rc = mciSendString("Play MySound", "", 0, 0)
End Sub

■さいごに

本業はwebエンジニアなので、本当はwebのノウハウを蓄積したいが、WEBに関しては自分がめちゃくちゃ苦戦したことって先駆者が遺産を残しているため、なかなかそれを超えるアウトプットをQiitaでできないのがつらみ。
VBAってノウハウがweb関係と違って圧倒的にノウハウがインターネットになくてきつい(;´・ω・)

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?