VFP调用Windows Media Player控件播放音乐、视频等

本文介绍如何在Visual FoxPro (VFP) 中利用WindowsMediaPlayer控件播放音乐和视频文件。通过示例代码展示了如何设置播放环境、播放本地及网络资源,并提供了自定义控件以增强用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

*--VFP调用Windows Media Player控件播放音乐、视频等
*--控件名称:Windows Media Player
*--控件文件名:wmp.dll
*--控件ProgID:WMPlayer.OCX
*--运行环境:VFP8及以上


*MyPlayer("F:/test.mp3")
 

*MyPlayer("D:/test.rmvb")
 

Procedure MyPlayer(tcURL, tnDrive)
    Local
loError, loCD
   
If Vartype(tcURL)#"C" Or Empty
(tcURL)
   
    * Sample URL
       
tcURL = "http://radio.livephish.com:8000"
   
Endif
    If Type
("_SCREEN.oWMP")#"O"
       
_Screen.AddObject
("oWMP","WMPContainer")
       
With _Screen
.oWMP
            .
Height = _Screen.
Height
           
.Width = _Screen.
Width
           
.Visible
=.T.
       
Endwith
    Endif
    If Upper
(tcURL)=="CD"
       
If
tnDrive = -1
           
Return
        Endif
       
loCD = _Screen.oWMP.oleWMP.cdromCollection.Item
(tnDrive)
       
_Screen
.oWMP.oleWMP.currentPlaylist = loCD.Playlist
   
Else
        _Screen
.oWMP.oleWMP.url = tcURL
   
Endif
Endproc


*---------- CLASSES ----------------------------------
Define Class WMPContainer
As Container
    oWMPToolBar =
Null
    Add Object
oleWMP As OleControl With OleClass = 'WMPlayer.OCX'
&&用到的文件为wmp.dll,名称Windows Media Player(C:/WINDOWS/system32/)
   
Add Object tmrWMP1 As
tmrWMP
   
Procedure Init
        This
.oleWMP.Width = This.Width
+400
       
This.oleWMP.Height = This.Height
+300
       
This.oWMPToolBar = Newobject('WMPToolBar', Sys(16), Null, This
)
       
This.oWMPToolBar.Visible
= .T.
   
Endproc
    Procedure Release
        _Screen
.LockScreen
= .T.
       
This.RemoveObject
('oleWMP')
       
Release This
        _Screen
.LockScreen
= .F.
   
Endproc
    Procedure
oleWMP.DoubleClick(p1,p2,p3,p4)
       
This.Visible
= .F.
       
This.Parent.Visible
= .F.
       
This.Parent.oWMPToolBar =
Null
        This
.Parent.tmrWMP1.Enabled
= .T.
   
Endproc
Enddefine
*--------------------------------------------
Define Class WMPToolBar
As Toolbar
    ShowTips
= .T.
   
Caption
= 'Fox Media Player'
    WMPContainer =
Null
    Add Object
CmdClose As CommandButton With ToolTipText = 'Close Fox Media Player',;
        Picture = Home() + 'tools/test/close.bmp', SpecialEffect = 2, Height = 22, Width
= 140
   
Procedure Init(WMPContainer As Object
)
       
This
.WMPContainer = WMPContainer
   
Endproc
    Procedure
CmdClose.
Click
        This
.Parent
.WMPContainer.oleWMP.DoubleClick()
   
Endproc
Enddefine
*--------------------------------------------
Define Class tmrWMP
As Timer
    Interval
= 500
   
Enabled
= .F.
   
Procedure Timer
        This
.Parent.Release
()
   
Endproc
Enddefine

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值