是可以用CreateObject的方式來處理,例如:
<pre class="c" name="code">
Dim mp3url
mp3url="c:\\TestSong.mp3"
playSound mp3url
Function playSound(soundUrl)
Dim wmp,TiShiObj
Set wmp = CreateObject("WMPlayer.OCX")
wmp.URL = soundUrl
Do Until wmp.playState = 1
WSH.sleep 5000
WSH.ECHO "目前正播放時間: " & wmp.controls.currentPositionString & " 音樂總長度: " & wmp.currentMedia.durationString
Loop
End Function
希望合用喔~
試試看...希望有幫助 :)
<pre class="c" name="code">
Dim mp3url
mp3url="c:\\TestSong.mp3"
playSound mp3url
Function playSound(soundUrl)
Dim wmp,timeStr,timeArr
Set wmp = CreateObject("WMPlayer.OCX")
wmp.URL = soundUrl
Do Until wmp.playState = 1
WSH.sleep 10000
timeStr=wmp.controls.currentPosition
timeArr=split(timeStr,".")
WSH.echo CINT(timeArr(0) / 60) & "分" & CINT(timeArr(0) MOD 60) & "秒" & LEFT(timeArr(1),3)
Loop
End Function
感謝ccutmis的分享
但可不可以不播放MP3而是直接取總時間 [2分28秒228]
再次感謝
總時間取得這問題比較小,把 wmp.contrls.currentPosition 改成 wmp.currentMedia.duration 就可以解決。但以本例來說就沒辦法不播放,因為是透過WMPlayer這元件,它不播又怎能知道它現在播的歌曲的資訊呢? 所以折衷方式就是在源碼裡面加上
wmp.settings.mute=true(其實還是會播,但是靜音),以下是參考源碼...
<pre class="c" name="code">
Dim mp3url
mp3url="c:\\TestSong.mp3"
playSound mp3url
Function playSound(soundUrl)
Dim wmp,timeStr,timeArr
Set wmp = CreateObject("WMPlayer.OCX")
wmp.URL = soundUrl
wmp.settings.mute=true '設為靜音
Do Until wmp.playState = 1
WSH.sleep 1000
timeStr=wmp.currentMedia.duration
timeArr=split(timeStr,".")
WSH.echo "總時間:" & CINT(timeArr(0) / 60) & "分" & CINT(timeArr(0) MOD 60) & "秒" & LEFT(timeArr(1),3)
Exit Do '取得總時間就跳出Do迴圈
Loop
Set wmp = NoThing
End Function