-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStart-PlayVideoVLC.psm1
90 lines (78 loc) · 3.76 KB
/
Start-PlayVideoVLC.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
function Start-PlayVideoVLC {
Param (
[Parameter(Mandatory=$true, ValueFromPipeline=$false)]
[string]$Uri,
[Parameter(Mandatory=$false, ValueFromPipeline=$false)]
[string]$title = 'VLC Movie Player'
)
Add-Type -AssemblyName System.Windows.Forms
$libPath = "C:\users\Martin\Documents\utils\powershell\VLC\"
$libsPS = ('LibVLCSharp.dll', 'LibVLCSharp.WinForms.dll', 'Microsoft.Threading.Tasks.dll')
$libsPS | foreach {
$path = "$($libPath)$($_)"
try {
Add-Type -Path $path | Out-Null
} catch {
write-Host -ForegroundColor red "WinformsVLC: Could not load $($path)`n$($Error)"
exit
}
}
$libVLC = [LibVLCSharp.Shared.LibVLC]::new()
$media = [LibVLCSharp.Shared.Media]::new($libVLC, $Uri, [LibVLCSharp.Shared.FromType]::FromLocation)
$player = [LibVLCSharp.Shared.MediaPlayer]::new($media)
$margin = 10
$window = [System.Windows.Forms.Form]::new()
$window.Width = 1000
$window.Height = 600
$window.Text = $title
$window | Add-Member NoteProperty -Name returnString -Value "no button" -Force
$butSave = [System.Windows.Forms.Button]::new()
$butSave.Location = [System.Drawing.Point]::new($margin,$window.ClientSize.Height-$margin-$butSave.Height)
$butSave.Text = "Save"
$butSave.Anchor = ([System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Left);
$butSave.Add_Click({
$window.returnString = $butSave.Text
$window.Dispose()
})
$window.Controls.Add($butSave)
$butCancel = [System.Windows.Forms.Button]::new()
$butCancel.Location = [System.Drawing.Point]::new($butSave.Location.X + $butSave.Width + $margin, $butSave.Location.Y)
$butCancel.Text = "Cancel"
$butCancel.Anchor = ([System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Left);
$butCancel.Add_Click({
$window.returnString = $butCancel.Text
$window.Dispose()
})
$window.Controls.Add($butCancel)
$video = [LibVLCSharp.WinForms.VideoView]::new()
$video.MediaPlayer = $player
$video.Location = [System.Drawing.Point]::new($margin,$margin)
$video.Width = $window.ClientSize.Width-2*$margin
$video.Height = $butCancel.Location.Y-2*$margin
$video.Anchor = ([System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Top -bor [System.Windows.Forms.AnchorStyles]::Left -bor [System.Windows.Forms.AnchorStyles]::Right);
$window.Controls.Add($video)
$slidePosition = [System.Windows.Forms.TrackBar]::new()
$slidePosition.Maximum = 100
$slidePosition.SmallChange = 1
$slidePosition.LargeChange = 100
$slidePosition.Location = [System.Drawing.Point]::new($butCancel.Location.X + $butCancel.Width + $margin, $butSave.Location.Y)
$slidePosition.Width = $window.ClientSize.Width - $slidePosition.Location.X
$slidePosition.Anchor = ([System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Left -bor [System.Windows.Forms.AnchorStyles]::Right);
$slidePosition.Add_ValueChanged({
# Write-Host "slider pos: $($slidePosition.Value), duration: $($player.media.Duration), pos: $($player.Position)"
$player.Position = $slidePosition.Value*0.01*0.99
})
$window.Controls.Add($slidePosition)
$timer = [System.Windows.Forms.Timer]::new()
$timer.Interval = 1000
$timer.add_tick({
# write-host "Timer: $(get-date -Format 'HH:mm:ss'), video pos: $($player.Position), slider val: $($slidePosition.Value)"
$slidePosition.Value = $player.Position * $slidePosition.Maximum
})
$player.play() | Out-Null
$timer.Start()
[void]$window.ShowDialog()
$player.Stop()
$timer.stop()
$window.returnString
}