我需要通过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请帮帮我。向您致敬,苏曼路由
发布于 2016-09-08 20:11:17
您需要创建一个显示的表单,然后创建一个VideoDrawing,然后创建一个DrawingBrush,然后将其应用于表单的某个部分的背景。据我所知,MediaElement更容易使用-但不管你在这里没有启动媒体播放器,你正在使用Windows media对象,而没有创建一个窗体来在上面显示它们。
如果您只是想打开并关闭视频,请尝试启动Windows Media Player应用程序。我使用了你的代码,做了一些你可能想做的事情:
Add-Type -AssemblyName presentationCore
$filepath = "C:\Temp\test\Wildlife.wmv"
#Here we use your code to get the duration of the video
$wmplayer = New-Object System.Windows.Media.MediaPlayer
$wmplayer.Open($filepath)
Start-Sleep 2
$duration = $wmplayer.NaturalDuration.TimeSpan.Seconds
$wmplayer.Close()
#Here we just open media player and play the file, with an extra second for it to start playing
$proc = Start-process -FilePath wmplayer.exe -ArgumentList $filepath -PassThru
Start-Sleep ($duration + 1)
#Here we kill the media player
Stop-Process $proc.Id -force
Write-Host $durationhttps://stackoverflow.com/questions/39388995
复制相似问题