【发布时间】:2016-09-08 10:50:00
【问题描述】:
我需要通过 Windows Media Player 播放视频。并跟踪它播放的持续时间。 假设我在 5 秒内关闭视频,它应该给出持续时间 5。下面是我编写的脚本。但这有问题。由于视频无法启动,我也无法启动应用程序。我只能在这里播放音频。
Add-Type -AssemblyName presentationCore
$filepath = [uri] "C:\Temp\test\Wildlife.wmv"
$wmplayer = New-Object System.Windows.Media.MediaPlayer
$wmplayer.Open($filepath)
Start-Sleep 2 # This allows the $wmplayer time to load the audio file
$duration = $wmplayer.NaturalDuration.TimeSpan.Seconds
$wmplayer.Play()
Start-Sleep $duration
$wmplayer.Stop()
$wmplayer.Close()
Write-Host $duration
请帮忙... 问候, 苏曼溃败
【问题讨论】: