vb.net axWindowsMediaPlayer 控件使用
生活随笔
收集整理的這篇文章主要介紹了
vb.net axWindowsMediaPlayer 控件使用
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
利用axWindowsMediaPlayer(Windows Media Player)制作MP3播放器 2
在制作mp3播放器之前,我們需要了解axWindowsMediaPlayer 媒體主要方法屬性:
屬性/方法名: 說明:
[基本屬性]
URL:String; 指定媒體位置,本機(jī)或網(wǎng)絡(luò)地址
uiMode:String; 播放器界面模式,可為Full, Mini, None, Invisible
playState:integer; 播放狀態(tài),1=停止,2=暫停,3=播放,6=正在緩沖,9=正在連接,10=準(zhǔn)備就緒
enableContextMenu:Boolean; 啟用/禁用右鍵菜單
fullScreen:boolean; 是否全屏顯示
//播放器基本控制
Ctlcontrols.play; 播放
Ctlcontrols.pause; 暫停
Ctlcontrols.stop; 停止
Ctlcontrols.currentPosition:double; 當(dāng)前進(jìn)度
Ctlcontrols.currentPositionString:string; 當(dāng)前進(jìn)度,字符串格式。如“00:23”
Ctlcontrols.fastForward; 快進(jìn)
Ctlcontrols.fastReverse; 快退
Ctlcontrols.next; 下一曲
Ctlcontrols.previous; 上一曲
[settings] wmp.settings //播放器基本設(shè)置
settings.volume:integer; 音量,0-100
settings.autoStart:Boolean; 是否自動(dòng)播放
settings.mute:Boolean; 是否靜音
settings.playCount:integer; 播放次數(shù)
[currentMedia] wmp.currentMedia //當(dāng)前媒體屬性
currentMedia.duration:double; 媒體總長度
currentMedia.durationString:string; 媒體總長度,字符串格式。如“03:24”
currentMedia.getItemInfo(const string); 獲取當(dāng)前媒體信息"Title"=媒體標(biāo)題,"Author"=藝術(shù)家,"Copyright"=版權(quán)信息,"Description"=媒體內(nèi)容描述, "Duration"=持續(xù)時(shí)間(秒),"FileSize"=文件大小,"FileType"=文件類型,"sourceURL"=原始地址
currentMedia.setItemInfo(const string); 通過屬性名設(shè)置媒體信息
currentMedia.name:string; 同 currentMedia.getItemInfo("Title")
[currentPlaylist] wmp.currentPlaylist //當(dāng)前播放列表屬性
currentPlaylist.count:integer; 當(dāng)前播放列表所包含媒體數(shù)
currentPlaylist.Item[integer]; 獲取或設(shè)置指定項(xiàng)目媒體信息,其子屬性同wmp.currentMedia
axWindowsMediaPlayer1.currentMedia.sourceURL; //獲取正在播放的媒體文件的路徑
axWindowsMediaPlayer1.currentMedia.name; //獲取正在播放的媒體文件的名稱
axWindowsMediaPlayer1.Ctlcontrols.Play 播放
axWindowsMediaPlayer1.Ctlcontrols.Stop 停止
axWindowsMediaPlayer1.Ctlcontrols.Pause 暫停
axWindowsMediaPlayer1.Ctlcontrols.PlayCount 文件播放次數(shù)
axWindowsMediaPlayer1.Ctlcontrols.AutoRewind 是否循環(huán)播放
axWindowsMediaPlayer1.Ctlcontrols.Balance 聲道
axWindowsMediaPlayer1.Ctlcontrols.Volume 音量
axWindowsMediaPlayer1.Ctlcontrols.Mute 靜音
axWindowsMediaPlayer1.Ctlcontrols.EnableContextMenu 是否允許在控件上點(diǎn)擊鼠標(biāo)右鍵時(shí)彈出快捷菜單
axWindowsMediaPlayer1.Ctlcontrols.AnimationAtStart 是否在播放前先播放動(dòng)畫
axWindowsMediaPlayer1.Ctlcontrols.ShowControls 是否顯示控件工具欄
axWindowsMediaPlayer1.Ctlcontrols.ShowAudioControls 是否顯示聲音控制按鈕
axWindowsMediaPlayer1.Ctlcontrols.ShowDisplay 是否顯示數(shù)據(jù)文件的相關(guān)信息
axWindowsMediaPlayer1.Ctlcontrols.ShowGotoBar 是否顯示Goto欄
axWindowsMediaPlayer1.Ctlcontrols.ShowPositionControls 是否顯示位置調(diào)節(jié)按鈕
axWindowsMediaPlayer1.Ctlcontrols.ShowStatusBar 是否顯示狀態(tài)欄
axWindowsMediaPlayer1.Ctlcontrols.ShowTracker 是否顯示進(jìn)度條
axWindowsMediaPlayer1.Ctlcontrols.FastForward 快進(jìn)
axWindowsMediaPlayer1.Ctlcontrols.FastReverse 快退
axWindowsMediaPlayer1.Ctlcontrols.Rate 快進(jìn)/快退速率
axWindowsMediaPlayer1.AllowChangeDisplaySize 是否允許自由設(shè)置播放圖象大小
axWindowsMediaPlayer1.DisplaySize 設(shè)置播放圖象大小 1-MpDefaultSize 原始大小 2-MpHalfSize 原始大小的一半 3-MpDoubleSize 原始大小的兩倍 4-MpFullScreen 全屏 5-MpOneSixteenthScreen 屏幕大小的1/16 6-MpOneFourthScreen 屏幕大小的1/4 7-MpOneHalfScreen 屏幕大小的1/2
axWindowsMediaPlayer1.ClickToPlay 是否允許單擊播放窗口啟動(dòng)Media Player
在視頻播放之后,可以通過如下方式讀取源視頻的寬度和高度,然后設(shè)置其還原為原始的大小.private void ResizeOriginal(){int intWidth = axWindowsMediaPlayer1.currentMedia.imageSourceWidth;int intHeight = axWindowsMediaPlayer1.currentMedia.imageSourceHeight;axWindowsMediaPlayer1.Width = intWidth + 2;axWindowsMediaPlayer1.Height = intHeight + 2;}
打開媒體文件并播放:Dim filePath As StringWith Me.OpenFileDialog1.Title = "打開語音文件".CheckPathExists = True.CheckFileExists = True.Multiselect = False.Filter = "mp3文件(*.mp3)|*.mp3|所有文件(*.*)|*.*"If .ShowDialog = DialogResult.Cancel ThenExit SubEnd IffilePath = .FileNameEnd WithMe.Text = "PC復(fù)讀機(jī)-文件 " & filePathAxWindowsMediaPlayer1.URL = filePathTryMe.AxWindowsMediaPlayer1.Ctlcontrols.play()Catch ex As ExceptionMsgBox("對(duì)不起,不能播放此格式語音文件", MsgBoxStyle.OKOnly, "PC復(fù)讀機(jī)")Exit SubEnd Try
注意:
AxWindowsMediaPlayer1.URL 中URL是表示要播放的文件名,取消了原來的Name屬性.
AxWindowsMediaPlayer1.Ctlcontrols.play()播放,同樣還有Pause,Stop等其他屬性.
AxWindowsMediaPlayer1.settings.balance表示媒體播放的聲道設(shè)置,0表示均衡,-1和1表示左右聲道.
AxWindowsMediaPlayer1.currentMedia.duration 表示要播放的文件的時(shí)間長度.可用它獲取文件長度.
AxWindowsMediaPlayer1.Ctlcontrols.currentPosition表示正在播放的文件的當(dāng)前播放位置,可用這個(gè)屬性來對(duì)媒體文件進(jìn)行前進(jìn)后退等設(shè)置.如
AxWindowsMediaPlayer1.Ctlcontrols.currentPosition+1 表示前進(jìn)1個(gè)時(shí)間單位.
AxWindowsMediaPlayer1.settings.rate播放速率,一般乘以16后再顯示kbps單位.
注意:在上面程序中,如果在后面加上一個(gè):
msgbox(AxWindowsMediaPlayer1.currentMedia.duration.ToString )
則顯示結(jié)果很可能為0,因此,這時(shí)候很可能獲取不到文件的播放時(shí)間長度,容易出錯(cuò)。所以在利用的時(shí)候可以加一個(gè)timer控件:
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.TickEndPoint = AxWindowsMediaPlayer1.currentMedia.durationIf EndPoint = 0 Then Exit Sub '可能因?yàn)槊襟w文件的打開需要一定時(shí)間,這里等待媒體文件的打開msgbox(AxWindowsMediaPlayer1.currentMedia.duration.ToString )
End Sub
此時(shí)msgbox便會(huì)顯示文件播放長度。
2. Ctlcontrols屬性
Ctlcontrols屬性是AxWindowsMediaPlayer的一個(gè)重要屬性, 此控件中有許多常用成員。
(1) 方法play
用于播放多媒體文件,其格式為:
窗體名.控件名.Ctlcontrols.play()
如: AxWindowsMediaPlayer1.Ctlcontrols.play() ‘此處缺省窗體名是Me
(2) 方法pause
用于暫停正在播放的多媒體文件,其格式為:
窗體名.控件名.Ctlcontrols.pause()
如: AxWindowsMediaPlayer1.Ctlcontrols.pause()
(3) 方法stop
用于停止正在播放的多媒體文件,其格式為:
窗體名.控件名.Ctlcontrols.stop()
如: AxWindowsMediaPlayer1.Ctlcontrols.stop()
(4) 方法fastforward
用于將正在播放的多媒體文件快進(jìn),其格式為:
窗體名.控件名.Ctlcontrols.fastforward()
如: AxWindowsMediaPlayer1.Ctlcontrols.forward()
(5) 方法fastreverse
窗體名.控件名.Ctlcontrols.fastreverse()
如: AxWindowsMediaPlayer1.Ctlcontrols.fastreverse()
6. 屬性CurrentPosition
用于獲取多媒體文件當(dāng)前的播放進(jìn)度,其值是數(shù)值類型,使用格式為:
窗體名.控件名.Ctlcontrols.currentPosition
d1 =AxWindowsMediaPlayer1.Ctlcontrols.currentPosition
其中d1 是一個(gè)整型變量。
7. 屬性Duration
用于獲取當(dāng)前多媒體文件的播放的總時(shí)間,其值為數(shù)值類型,其使用格式為:
窗體名.控件名.currentMedia.duration
如:d2 =AxWindowsMediaPlayer1.currentMedia.duration
其中d2是一個(gè)整型變量。
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)
總結(jié)
以上是生活随笔為你收集整理的vb.net axWindowsMediaPlayer 控件使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: golang 字符串操作实例
- 下一篇: Oracle备份文件名获取系统时间的做法