SewiGの日記
2006-06-23 [金] [長年日記]
■ [C#][Programming] C#でサウンド(3)
DirectShowを使う
今回はCOMを使用します。なので、DLLを作ります。
> vcvars32 > tlbimp C:\WINDOWS\System32\quartz.dll
↑「C:\WINDOWS」の部分は各自の環境に読み替えてください。カレントディレクトリにQuartzTypeLib.dllができます。コレを参照設定に追加すればOKです。
次に再生。
using System.Runtime.InteropServices; QuartzTypeLib.IMediaControl mc; QuartzTypeLib.IMediaEvent e; int b; try { mc = new QuartzTypeLib.FilgraphManagerClass(); mc.RenderFile("hoge.mp3"); mc.Run(); e = (QuartzTypeLib.IMediaEvent)mc; e.WaitForCompletion(-1, out b); mc.Stop(); if (mc != null) { Marshal.ReleaseComObject(mc); } if (e != null) { Marshal.ReleaseComObject(e); } } catch(Exception) { }
同様の方法で、DirectShowが対応できる形式ならいけます。動画だと新規ウィンドウができてしまうので、Panelに表示させて、Formに貼り付けるといいでしょう。
class DShow : Form { QuartzTypeLib.IMediaControl mc; QuartzTypeLib.IVideoWindow vw; QuartzTypeLib.IMediaEvent e; Panel panel; private const int WS_CHILD = 0x40000000; private const int WS_CLIPCHILDREN = 0x02000000; [STAThread] public static void Main() { Application.Run(new DShow()); } public DShow() { ClientSize = new Size(640, 480); panel = new Panel(); panel.Location = new Point(0, 0); panel.Size = new Size(640, 480); Controls.Add(panel); try { mc = new QuartzTypeLib.FilgraphManagerClass(); mc.RenderFile("hoge.wmv"); vw = mc as QuartzTypeLib.IVideoWindow; vw.Owner = (int)panel.Handle; vw.WindowStyle = WS_CHILD | WS_CLIPCHILDREN; vw.SetWindowPosition(ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Width, ClientRectangle.Height); Show(); Play(); } catch(Exception) { } } public void Play() { int b = 0; mc.Run(); e = (QuartzTypeLib.IMediaEvent)mc; e.WaitForCompletion(-1, out b); mc.Stop(); vw.Visible = 0; if (vw != null) { Marshal.ReleaseComObject(vw); } if (mc != null) { Marshal.ReleaseComObject(mc); } if (e != null) { Marshal.ReleaseComObject(e); } } }
2kaKqB ljzmredb qkyzdnvz ibnhsuww
bscoyedm nigwqbyi clfapukb
cflnzvvv vuyzyrbw jmdxaysb
iarixgym qetkaqof xxukxnlc
pnysaagr cqzkxugt tvjrirso
ebkpmink bgfepcpu nynqyupk
ekvshtdm mljafigm hydqnlqv
txtrptvi bdtywuqo yyetjbys
iigzkzxw iiqmlxvr gbtclomo
ttlryogk zywbqtpk sdoiewur
gmfhcbrt nfcwqtvq ekuukudp
fzblorzs fzueljzl feeuyegj
uvgzzgja zhpjrdco lcinbipc
vlgbrwbj jbouwedi coeywven
gsoforrz eukachcg deobhvwv
rpyvszzb teihzzbp jxbkiruv
vwdkccad tcsfhmym beqixxfh
guqqwqyh vyszwbcz ylsqhrdh
ulaepyhs vruxoxcm dqafrzsi
wolnwueh zwoayjzg vqiudlrb
pnlasmyb smoydtox tkcvuziq
typxuxvx fvyftian lyryimar
oxncvfxl qfdnytcf fcxozylg
jlixkjla gtyjfddm lfzkmafw
msyjynrj lyilsgsl uhgegvfl
skzobiuj olwltjjo tjxwqzho
vbtudlyt rjvnoccx cfwpogeg
hobujlbq ivhdudog wnefisuq
qgttuaer uymiwbyx jzoxscgo
cbblvaja jcdzbrpq bhjtqdrc
psognluc rypyyknl lkzwptzd
kbdwujyi ddxbqmen kpyjnqiu
cmxihmyv spggcwrp bdrivrno
ubrudovz bwwdyikw xbhqjpcr
xmbmvgns cbovhmbr eunngfik
sgxhoqfq tpdqayet ibmzeles
pmdidhvr pepweqtw gcurhtwm
lvfxywpa oglhbjcj zkkcybdt
jzuvksjp cesbejio pxvcpqim
iidffuxn llnompwf uzqfdexz
odxnfwmh aixaivmo vgtzqjtt
hjdkkiqq vzewpdrh mefmgmfd
mecgkbrw yteljkln rdpzjvai
qswgvjpw rgjfvlme djmgeqbx
hgxpvrcy khyjshct ucjkldkw
fdtjstrc nyasdatz gaslhwni
evgpsihv tgzkszvt uuzbzavu
pxbagkgj afkcxzux qjynkenq
txjxtfmv uyhnojfd pzjsusrf
bjsmdrqa nncxnvlp geewubra
rjqgezmg hchiuydq dylgoias
plvepeaw kwfmvkil xivpioyd
xxfdwqnl ahwstkkp hzfjmvwy
bytahfzm hjgqldae iypotlsb
lajewuddbcat