用MCI命令做一个播放器[1]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 thinkeasy 的 blog

'用mci命令来实现多媒体的播放功能
'下面的内容几乎有播放器软件的各种功能,你只是引用这些函数就能做出一个播放器来
'
'
'
'
'

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

public declare function mcigetdeviceid lib "winmm.dll" alias "mcigetdeviceida" (byval lpstrname as string) as long

public declare function waveoutgetvolume lib "winmm.dll" (byval udeviceid as long, lpdwvolume as long) as long

public declare function getwindowlong lib "user32" alias "getwindowlonga" (byval hwnd as long, byval nindex as long) as long

public declare function callwindowproc lib "user32" alias "callwindowproca" (byval lpprevwndfunc as long, byval hwnd as long, byval msg as long, byval wparam as long, byval lparam as long) as long

public declare function setwindowlong lib "user32" alias "setwindowlonga" (byval hwnd as long, byval nindex as long, byval dwnewlong as long) as long

public declare function getshortpathname lib "kernel32" alias "getshortpathnamea" (byval lpszlongpath as string, byval lpszshortpath as string, byval cchbuffer as long) as long

enum playtypename
    file = 1
    cdaudio = 2
    vcd = 3
    realplay = 4
end enum
dim playtype as playtypename
enum audiosource
    audiostereo = 0 ' "stereo"
    audioleft = 1 '"left"
    audioright = 2 '"right"
end enum
dim hwndmusic as long
dim prevwndproc as long

'=======================================================
'打开mci设备,urlstr为网址,传值代表成功与否
'=======================================================
public function openurl(urlstr as string, optional hwnd as long) as boolean
    openmusic = false
    dim mcicommand as string
    dim driverid as string
   
    closemusic
     'mci命令
    driverid = getdriverid(urlstr)
    if driverid = "realplayer" then
        playtype = realplay
        exit function
    end if
    mcicommand = "open " & urlstr & " type " & driverid & " alias nowmusic"
   

    if driverid = "avivideo" or driverid = "mpegvideo" or driverid = "mpegvideo2" then
        if hwnd <> 0 then
            mcicommand = mcicommand + " parent " & hwnd & " style child"
            hwndmusic = getwindowhandle
            prevwndproc = getwindowlong(hwndmusic, -4)
            setwindowlong hwndmusic, -4, addressof wndproc
           
        else
            mcicommand = mcicommand + " style overlapped "
        end if
    end if
   
    refint = mcisendstring(mcicommand, vbnull, 0, 0)
    mcisendstring "set nowmusic time format milliseconds", vbnullstring, 0, 0
    if refint = 0 then openmusic = true

end function
'=======================================================
'打开mci设备,filename为文件名,传值代表成功与否
'=======================================================
public function openmusic(filename as string, optional hwnd as long) as boolean
    openmusic = false
    dim shortpathname as string * 255
    dim refshortname as string
    dim refint as long
    dim mcicommand as string
    dim driverid as string
   
    closemusic
    '获取短文件名
    getshortpathname filename, shortpathname, 255
    refshortname = left(shortpathname, instr(1, shortpathname, chr(0)) - 1)
    'mci命令
    driverid = getdriverid(refshortname)
    if driverid = "realplayer" then
        playtype = realplay
        exit function
    end if
    mcicommand = "open " & refshortname & " type " & driverid & " alias nowmusic"

本文关键:MCI
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top