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

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

本文简介:选择自 thinkeasy 的 blog

   

    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
function wndproc(byval hwnd as long, byval msg as long, byval wparam as long, byval lparam as long) as long
    if msg = &h202 then
    msgbox "ok"
    end if
    wndproc = callwindowproc(prevwndproc, hwnd, msg, wparam, lparam)
end function
'=======================================================
'根据文件名,确定设备
'=======================================================
public function getdriverid(ff as string) as string
    select case ucase(right(ff, 3))
     case "mid", "rmi", "idi"
        getdriverid = "sequencer"
     case "wav"
        getdriverid = "waveaudio"
     case "asf", "asx", "ivf", "lsf", "lsx", "p2v", "wax", "wvx", ".wm", "wma", "wmx", "wmp"
        getdriverid = "mpegvideo2"
     case ".rm", "ram", ".ra"
        getdriverid = "realplayer"
     case else
        getdriverid = "mpegvideo"
     end select
end function

'======================================================
'播放文件
'======================================================
public function playmusic() as boolean
    dim refint as long
    playmusic = false
    refint = mcisendstring("play nowmusic", vbnull, 0, 0)
    if refint = 0 then playmusic = true
end function

'======================================================
'获取媒体的长度
'======================================================
public function getmusiclength() as long
    dim refstr as string * 80
    mcisendstring "status nowmusic length", refstr, 80, 0
    getmusiclength = val(refstr)
end function

'======================================================
'获取当前播放进度
'======================================================
public function getmusicpos() as long
    dim refstr as string * 80
    mcisendstring "status nowmusic position", refstr, 80, 0
    getmusicpos = val(refstr)
end function

'======================================================
'获取媒体的当前进度
'======================================================
public function setmusicpos(position as long) as boolean
    dim refint as long
    setmusicpos = false
    refint = mcisendstring("seek nowmusic to " & position, vbnull, 0, 0)
    if refint = 0 then setmusicpos = true
end function

'======================================================
'暂停播放
'======================================================
public function pausemusic() as boolean
    dim refint as long
    pausemusic = false
    refint = mcisendstring("pause nowmusic", vbnull, 0, 0)
    if refint = 0 then pausemusic = true
end function
'======================================================
'关闭媒体
'======================================================
public function closemusic() as boolean
    dim refint as long
    closemusic = false
    refint = mcisendstring("close nowmusic", vbnull, 0, 0)
    if refint = 0 then closemusic = true
end function

本文关键:MCI
  相关方案
Google
 

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

go top