From 9386a3f970d6bc96e3a98295a992a5df6d27e679 Mon Sep 17 00:00:00 2001 From: Brett Sanderson Date: Tue, 3 May 2022 13:31:32 -0400 Subject: [PATCH] Allow to play more than 1 segment --- OpenpilotSdk/Hardware/OpenpilotDevice.cs | 14 +- OpenpilotSdk/OpenpilotSdk.csproj | 2 +- .../Controls/Media/VideoPlayer.Designer.cs | 166 +++++++++++++-- .../Controls/Media/VideoPlayer.cs | 195 ++++++++++++++++-- OpenpilotToolkit/OpenpilotToolkit.csproj | 28 +-- OpenpilotToolkit/OpenpilotToolkitForm.cs | 49 +++-- OpenpilotToolkit/OpenpilotToolkitForm.resx | 2 +- 7 files changed, 363 insertions(+), 93 deletions(-) diff --git a/OpenpilotSdk/Hardware/OpenpilotDevice.cs b/OpenpilotSdk/Hardware/OpenpilotDevice.cs index 5948640..f4a9418 100644 --- a/OpenpilotSdk/Hardware/OpenpilotDevice.cs +++ b/OpenpilotSdk/Hardware/OpenpilotDevice.cs @@ -380,7 +380,8 @@ public async Task GetThumbnailAsync(DriveSegment driveSegment) await ConnectAsync(); Bitmap thumbnail = null; - var drive = new DirectoryInfo(Path.GetDirectoryName(driveSegment.FrontVideo.File.FullName)).Name; + var videoFile = driveSegment.FrontVideoQuick ?? driveSegment.FrontVideo; + var drive = new DirectoryInfo(Path.GetDirectoryName(videoFile.File.FullName)).Name; var cachedThumbnail = Path.Combine(TempDirectory, drive + ".jpg"); @@ -389,7 +390,6 @@ public async Task GetThumbnailAsync(DriveSegment driveSegment) bool quickVideo = driveSegment.FrontVideoQuick != null; var offset = 0; - var videoFile = driveSegment.FrontVideoQuick ?? driveSegment.FrontVideo; var imageBuffer = quickVideo ? new byte[10000] : new byte[200000]; await using (var sftpFileStream = SftpClient.OpenRead(videoFile.File.FullName)) @@ -407,7 +407,7 @@ public async Task GetThumbnailAsync(DriveSegment driveSegment) try { await FFMpegArguments - .FromPipeInput(new StreamPipeSource(msInput), options => options.WithFramerate(20).ForceFormat(quickVideo ? "mpegts" : "rawvideo")) + .FromPipeInput(new StreamPipeSource(msInput), options => options.WithFramerate(20)) .OutputToPipe(new StreamPipeSink(msOutput), options => options.WithVideoCodec(VideoCodec.Png) .WithFrameOutputCount(1) @@ -591,9 +591,7 @@ public async Task> GetFirmwareVersions(IProgress prog var firmwares = new List(); - var drives = GetDrives(); - - foreach (var drive in drives) + await foreach (var drive in GetDrivesAsync()) { foreach (var driveSegment in drive.Segments.OrderBy(segment => segment.Index)) { @@ -668,7 +666,7 @@ public async Task GenerateGpxFileAsync(Drive drive, IProgress prog public async IAsyncEnumerable GetDrivesAsync([EnumeratorCancellation]CancellationToken cancellationToken = default(CancellationToken)) { - await ConnectAsync(); + await ConnectAsync(cancellationToken); IOrderedEnumerable> directoryListing; @@ -680,7 +678,7 @@ public async Task GenerateGpxFileAsync(Drive drive, IProgress prog { return DateTime.ParseExact(dir.Name.AsSpan().Slice(0, 20), "yyyy-MM-dd--HH-mm-ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime(); }) - .OrderBy(dir => + .OrderByDescending(dir => { var date = dir.Key; return date; diff --git a/OpenpilotSdk/OpenpilotSdk.csproj b/OpenpilotSdk/OpenpilotSdk.csproj index ea1e8a9..b30886f 100644 --- a/OpenpilotSdk/OpenpilotSdk.csproj +++ b/OpenpilotSdk/OpenpilotSdk.csproj @@ -41,7 +41,7 @@ - + diff --git a/OpenpilotToolkit/Controls/Media/VideoPlayer.Designer.cs b/OpenpilotToolkit/Controls/Media/VideoPlayer.Designer.cs index 1060c26..84a3ce9 100644 --- a/OpenpilotToolkit/Controls/Media/VideoPlayer.Designer.cs +++ b/OpenpilotToolkit/Controls/Media/VideoPlayer.Designer.cs @@ -16,10 +16,16 @@ protected override void Dispose(bool disposing) { if (disposing && (components != null)) { - if (vlcVideoView.MediaPlayer != null) + if (vlcVideoView1.MediaPlayer != null) { - vlcVideoView.MediaPlayer.Stop(); - vlcVideoView.MediaPlayer.Dispose(); + vlcVideoView1.MediaPlayer.Stop(); + vlcVideoView1.MediaPlayer.Dispose(); + } + + if (vlcVideoView2.MediaPlayer != null) + { + vlcVideoView2.MediaPlayer.Stop(); + vlcVideoView2.MediaPlayer.Dispose(); } components.Dispose(); } @@ -35,18 +41,27 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); - this.vlcVideoView = new LibVLCSharp.WinForms.VideoView(); + this.panel2 = new System.Windows.Forms.Panel(); + this.vlcVideoView1 = new LibVLCSharp.WinForms.VideoView(); + this.vlcVideoView2 = new LibVLCSharp.WinForms.VideoView(); + this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); + this.btnPreviousSegment = new MaterialSkin.Controls.MaterialButton(); this.timeScale = new MaterialSkin.Controls.MaterialSlider(); + this.btnNextSegment = new MaterialSkin.Controls.MaterialButton(); + this.lblSegment = new System.Windows.Forms.Label(); this.tableLayoutPanel1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.vlcVideoView)).BeginInit(); + this.panel2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.vlcVideoView1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.vlcVideoView2)).BeginInit(); + this.tableLayoutPanel2.SuspendLayout(); this.SuspendLayout(); // // tableLayoutPanel1 // this.tableLayoutPanel1.ColumnCount = 1; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel1.Controls.Add(this.vlcVideoView, 0, 0); - this.tableLayoutPanel1.Controls.Add(this.timeScale, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.panel2, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel2, 0, 1); this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; @@ -58,36 +73,135 @@ private void InitializeComponent() this.tableLayoutPanel1.TabIndex = 0; this.tableLayoutPanel1.Paint += new System.Windows.Forms.PaintEventHandler(this.tableLayoutPanel1_Paint); // - // vlcVideoView + // panel2 + // + this.panel2.Controls.Add(this.vlcVideoView1); + this.panel2.Controls.Add(this.vlcVideoView2); + this.panel2.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel2.Location = new System.Drawing.Point(3, 3); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(457, 299); + this.panel2.TabIndex = 69; + // + // vlcVideoView1 + // + this.vlcVideoView1.BackColor = System.Drawing.Color.Black; + this.vlcVideoView1.Dock = System.Windows.Forms.DockStyle.Fill; + this.vlcVideoView1.Location = new System.Drawing.Point(0, 0); + this.vlcVideoView1.MediaPlayer = null; + this.vlcVideoView1.Name = "vlcVideoView1"; + this.vlcVideoView1.Size = new System.Drawing.Size(457, 299); + this.vlcVideoView1.TabIndex = 0; + this.vlcVideoView1.Text = "videoView1"; + this.vlcVideoView1.Click += new System.EventHandler(this.vlcVideoView_Click); + // + // vlcVideoView2 + // + this.vlcVideoView2.BackColor = System.Drawing.Color.Black; + this.vlcVideoView2.Dock = System.Windows.Forms.DockStyle.Fill; + this.vlcVideoView2.Location = new System.Drawing.Point(0, 0); + this.vlcVideoView2.MediaPlayer = null; + this.vlcVideoView2.Name = "vlcVideoView2"; + this.vlcVideoView2.Size = new System.Drawing.Size(457, 299); + this.vlcVideoView2.TabIndex = 1; + this.vlcVideoView2.Text = "videoView1"; // - this.vlcVideoView.BackColor = System.Drawing.Color.Black; - this.vlcVideoView.Dock = System.Windows.Forms.DockStyle.Fill; - this.vlcVideoView.Location = new System.Drawing.Point(3, 3); - this.vlcVideoView.MediaPlayer = null; - this.vlcVideoView.Name = "vlcVideoView"; - this.vlcVideoView.Size = new System.Drawing.Size(457, 299); - this.vlcVideoView.TabIndex = 0; - this.vlcVideoView.Text = "videoView1"; - this.vlcVideoView.Click += new System.EventHandler(this.vlcVideoView_Click); + // tableLayoutPanel2 + // + this.tableLayoutPanel2.ColumnCount = 4; + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F)); + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F)); + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F)); + this.tableLayoutPanel2.Controls.Add(this.btnPreviousSegment, 0, 0); + this.tableLayoutPanel2.Controls.Add(this.timeScale, 1, 0); + this.tableLayoutPanel2.Controls.Add(this.btnNextSegment, 3, 0); + this.tableLayoutPanel2.Controls.Add(this.lblSegment, 2, 0); + this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayoutPanel2.Location = new System.Drawing.Point(3, 308); + this.tableLayoutPanel2.Name = "tableLayoutPanel2"; + this.tableLayoutPanel2.RowCount = 1; + this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel2.Size = new System.Drawing.Size(457, 39); + this.tableLayoutPanel2.TabIndex = 70; + // + // btnPreviousSegment + // + this.btnPreviousSegment.AccentTextColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(64)))), ((int)(((byte)(129))))); + this.btnPreviousSegment.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.btnPreviousSegment.AutoSize = false; + this.btnPreviousSegment.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btnPreviousSegment.Density = MaterialSkin.Controls.MaterialButton.MaterialButtonDensity.Default; + this.btnPreviousSegment.Depth = 0; + this.btnPreviousSegment.HighEmphasis = true; + this.btnPreviousSegment.Icon = null; + this.btnPreviousSegment.Location = new System.Drawing.Point(4, 6); + this.btnPreviousSegment.Margin = new System.Windows.Forms.Padding(4, 6, 4, 6); + this.btnPreviousSegment.MouseState = MaterialSkin.MouseState.HOVER; + this.btnPreviousSegment.Name = "btnPreviousSegment"; + this.btnPreviousSegment.NoAccentTextColor = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(81)))), ((int)(((byte)(181))))); + this.btnPreviousSegment.Size = new System.Drawing.Size(32, 27); + this.btnPreviousSegment.TabIndex = 67; + this.btnPreviousSegment.Text = "<"; + this.btnPreviousSegment.Type = MaterialSkin.Controls.MaterialButton.MaterialButtonType.Contained; + this.btnPreviousSegment.UseAccentColor = true; + this.btnPreviousSegment.UseVisualStyleBackColor = true; + this.btnPreviousSegment.Click += new System.EventHandler(this.btnPreviousSegment_Click); // // timeScale // this.timeScale.Depth = 0; this.timeScale.Dock = System.Windows.Forms.DockStyle.Fill; this.timeScale.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(222)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); - this.timeScale.Location = new System.Drawing.Point(3, 308); + this.timeScale.Location = new System.Drawing.Point(43, 3); this.timeScale.MouseState = MaterialSkin.MouseState.HOVER; this.timeScale.Name = "timeScale"; this.timeScale.RangeMax = 100000; this.timeScale.ShowText = false; this.timeScale.ShowValue = false; - this.timeScale.Size = new System.Drawing.Size(457, 40); + this.timeScale.Size = new System.Drawing.Size(331, 40); this.timeScale.TabIndex = 66; this.timeScale.Text = ""; this.timeScale.UseAccentColor = true; this.timeScale.Value = 0; this.timeScale.onValueChanged += new MaterialSkin.Controls.MaterialSlider.ValueChanged(this.timeScale_onValueChanged); // + // btnNextSegment + // + this.btnNextSegment.AccentTextColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(64)))), ((int)(((byte)(129))))); + this.btnNextSegment.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.btnNextSegment.AutoSize = false; + this.btnNextSegment.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btnNextSegment.Density = MaterialSkin.Controls.MaterialButton.MaterialButtonDensity.Default; + this.btnNextSegment.Depth = 0; + this.btnNextSegment.HighEmphasis = true; + this.btnNextSegment.Icon = null; + this.btnNextSegment.Location = new System.Drawing.Point(421, 6); + this.btnNextSegment.Margin = new System.Windows.Forms.Padding(4, 6, 4, 6); + this.btnNextSegment.MouseState = MaterialSkin.MouseState.HOVER; + this.btnNextSegment.Name = "btnNextSegment"; + this.btnNextSegment.NoAccentTextColor = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(81)))), ((int)(((byte)(181))))); + this.btnNextSegment.Size = new System.Drawing.Size(32, 27); + this.btnNextSegment.TabIndex = 68; + this.btnNextSegment.Text = ">"; + this.btnNextSegment.Type = MaterialSkin.Controls.MaterialButton.MaterialButtonType.Contained; + this.btnNextSegment.UseAccentColor = true; + this.btnNextSegment.UseVisualStyleBackColor = true; + this.btnNextSegment.Click += new System.EventHandler(this.btnNextSegment_Click); + // + // lblSegment + // + this.lblSegment.AutoSize = true; + this.lblSegment.Dock = System.Windows.Forms.DockStyle.Fill; + this.lblSegment.Location = new System.Drawing.Point(380, 0); + this.lblSegment.Name = "lblSegment"; + this.lblSegment.Size = new System.Drawing.Size(34, 39); + this.lblSegment.TabIndex = 69; + this.lblSegment.Text = "0"; + this.lblSegment.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // // VideoPlayer // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -96,7 +210,11 @@ private void InitializeComponent() this.Name = "VideoPlayer"; this.Size = new System.Drawing.Size(463, 350); this.tableLayoutPanel1.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.vlcVideoView)).EndInit(); + this.panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.vlcVideoView1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.vlcVideoView2)).EndInit(); + this.tableLayoutPanel2.ResumeLayout(false); + this.tableLayoutPanel2.PerformLayout(); this.ResumeLayout(false); } @@ -105,6 +223,12 @@ private void InitializeComponent() private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; private MaterialSkin.Controls.MaterialSlider timeScale; - public LibVLCSharp.WinForms.VideoView vlcVideoView; + public LibVLCSharp.WinForms.VideoView vlcVideoView1; + private System.Windows.Forms.Panel panel2; + public LibVLCSharp.WinForms.VideoView vlcVideoView2; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2; + private MaterialSkin.Controls.MaterialButton btnNextSegment; + private MaterialSkin.Controls.MaterialButton btnPreviousSegment; + private System.Windows.Forms.Label lblSegment; } } diff --git a/OpenpilotToolkit/Controls/Media/VideoPlayer.cs b/OpenpilotToolkit/Controls/Media/VideoPlayer.cs index fb682d9..9f602fd 100644 --- a/OpenpilotToolkit/Controls/Media/VideoPlayer.cs +++ b/OpenpilotToolkit/Controls/Media/VideoPlayer.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using System.Windows.Forms; using LibVLCSharp.Shared; +using LibVLCSharp.WinForms; using Renci.SshNet.Sftp; @@ -17,6 +18,11 @@ public partial class VideoPlayer : UserControl { private LibVLC _libVlc; private SftpFileStream _currentStream; + + private int _currentSegment = 0; + private MediaList _mediaList; + + private int _currentPlayer = 1; public VideoPlayer() { @@ -26,22 +32,101 @@ public VideoPlayer() public void Initialize(LibVLC libVlc) { _libVlc = libVlc; - vlcVideoView.MediaPlayer = new MediaPlayer(libVlc); - if (vlcVideoView.MediaPlayer != null) + vlcVideoView1.MediaPlayer = new MediaPlayer(libVlc); + vlcVideoView2.MediaPlayer = new MediaPlayer(libVlc); + if (vlcVideoView1.MediaPlayer != null) { - vlcVideoView.MediaPlayer.TimeChanged += MediaPlayerOnTimeChanged; - vlcVideoView.MediaPlayer.PositionChanged += MediaPlayerOnPositionChanged; - vlcVideoView.MediaPlayer.Playing += MediaPlayerOnPlaying; + vlcVideoView1.MediaPlayer.PositionChanged += MediaPlayerOnPositionChanged; + vlcVideoView1.MediaPlayer.Playing += MediaPlayerOnPlaying; + vlcVideoView1.MediaPlayer.EndReached += MediaPlayerOnEndReached; } - vlcVideoView.MediaPlayer.EnableMouseInput = false; + if (vlcVideoView2.MediaPlayer != null) + { + vlcVideoView2.MediaPlayer.PositionChanged += MediaPlayerOnPositionChanged2; + vlcVideoView2.MediaPlayer.Playing += MediaPlayerOnPlaying2; + vlcVideoView2.MediaPlayer.EndReached += MediaPlayerOnEndReached2; + } + + vlcVideoView1.MediaPlayer.EnableMouseInput = false; + vlcVideoView2.MediaPlayer.EnableMouseInput = false; } - private void MediaPlayerOnPlaying(object sender, EventArgs e) + private void MediaPlayerOnEndReached2(object sender, EventArgs e) + { + NextSegment(); + } + + private void MediaPlayerOnEndReached(object sender, EventArgs e) + { + NextSegment(); + } + + private void NextSegment() + { + VideoView videoView = _currentPlayer == 1 ? vlcVideoView2 : vlcVideoView1; + + if (_currentSegment+1 < _mediaList.Count) + { + _currentSegment++; + + this.BeginInvoke(() => + { + videoView.BringToFront(); + videoView.MediaPlayer.SetPause(false); + lblSegment.Text = _currentSegment.ToString(); + }); + + + _currentPlayer = _currentPlayer == 1 ? 2 : 1; + + BufferSegment(_currentSegment+1); + } + } + + private void PreviousSegment() + { + VideoView videoView = _currentPlayer == 1 ? vlcVideoView2 : vlcVideoView1; + + if (_currentSegment - 1 >= 0) + { + _currentSegment--; + this.BeginInvoke(() => + { + lblSegment.Text = _currentSegment.ToString(); + videoView.MediaPlayer.Play(_mediaList[_currentSegment]); + videoView.BringToFront(); + }); + + _currentPlayer = _currentPlayer == 1 ? 2 : 1; + + BufferSegment(_currentSegment+1); + } + } + + private void BufferSegment(int segment) { - vlcVideoView.MediaPlayer.EnableKeyInput = false; - vlcVideoView.MediaPlayer.EnableMouseInput = false; + VideoView videoView = _currentPlayer == 1 ? vlcVideoView2 : vlcVideoView1; + if (segment < _mediaList.Count) + { + this.BeginInvoke(() => + { + videoView.MediaPlayer.Play(_mediaList[segment]); + }); + } + } + + private void MediaPlayerOnPlaying2(object sender, EventArgs e) + { + vlcVideoView2.MediaPlayer.EnableKeyInput = false; + vlcVideoView2.MediaPlayer.EnableMouseInput = false; + } + + private void MediaPlayerOnPlaying(object sender, EventArgs e) + { + vlcVideoView1.MediaPlayer.EnableKeyInput = false; + vlcVideoView1.MediaPlayer.EnableMouseInput = false; } public void Play(SftpFileStream fs) @@ -49,45 +134,111 @@ public void Play(SftpFileStream fs) _currentStream = fs; using (var media = new LibVLCSharp.Shared.Media(_libVlc, new StreamMediaInput(_currentStream))) { - vlcVideoView.MediaPlayer.Play(media); + vlcVideoView1.MediaPlayer.Play(media); } } - private void MediaPlayerOnPositionChanged(object sender, MediaPlayerPositionChangedEventArgs e) + public void Play(List fs) { - timeScale.Value = (int)(vlcVideoView.MediaPlayer.Position * timeScale.RangeMax); + _currentSegment = 0; + _currentPlayer = 1; + + + this.BeginInvoke(() => { lblSegment.Text = _currentSegment.ToString(); }); + + _mediaList = new MediaList(_libVlc); + foreach (var sftpFileStream in fs) + { + var media = new LibVLCSharp.Shared.Media(_libVlc, new StreamMediaInput(sftpFileStream)); + _mediaList.AddMedia(media); + } + + this.BeginInvoke(() => { vlcVideoView1.BringToFront(); }); + vlcVideoView1.MediaPlayer.Play(_mediaList[0]); + + BufferSegment(1); } + - private void MediaPlayerOnTimeChanged(object sender, MediaPlayerTimeChangedEventArgs e) + private void MediaPlayerOnPositionChanged2(object sender, MediaPlayerPositionChangedEventArgs e) { - //timeScale.Value = (int)(vlcVideoView.MediaPlayer.Position * timeScale.RangeMax); + if (_currentPlayer == 1) + { + vlcVideoView2.MediaPlayer.SetPause(true); + vlcVideoView2.MediaPlayer.Position = 0; + } + else + { + timeScale.Value = (int)(vlcVideoView2.MediaPlayer.Position * timeScale.RangeMax); + } + } + + + private void MediaPlayerOnPositionChanged(object sender, MediaPlayerPositionChangedEventArgs e) + { + if (_currentPlayer == 2) + { + + vlcVideoView1.MediaPlayer.SetPause(true); + vlcVideoView1.MediaPlayer.Position = 0; + } + else + { + timeScale.Value = (int)(vlcVideoView1.MediaPlayer.Position * timeScale.RangeMax); + } } private void timeScale_onValueChanged(object sender, int newValue) { - if (!vlcVideoView.MediaPlayer.WillPlay) + if (_currentPlayer == 1) { - using (var media = new LibVLCSharp.Shared.Media(_libVlc, new StreamMediaInput(_currentStream))) + if (!vlcVideoView1.MediaPlayer.WillPlay) { - vlcVideoView.MediaPlayer.Play(media); + vlcVideoView1.MediaPlayer.Play(_mediaList[_currentSegment]); } + + vlcVideoView1.MediaPlayer.Position = ((float)newValue / timeScale.RangeMax); + } + else + { + if (!vlcVideoView2.MediaPlayer.WillPlay) + { + vlcVideoView2.MediaPlayer.Play(_mediaList[_currentSegment]); + } + + vlcVideoView2.MediaPlayer.Position = ((float)newValue / timeScale.RangeMax); } - vlcVideoView.MediaPlayer.Position = ((float)newValue / timeScale.RangeMax); } private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e) { - + } private void vlcVideoView_Click(object sender, EventArgs e) { - - vlcVideoView.MediaPlayer.Pause(); + if (_currentPlayer == 2) + { + vlcVideoView2.MediaPlayer.Pause(); + } + else + { + vlcVideoView1.MediaPlayer.Pause(); + } + } + private void btnNextSegment_Click(object sender, EventArgs e) + { + Task.Run(() => { NextSegment(); }); + + } - + private void btnPreviousSegment_Click(object sender, EventArgs e) + { + Task.Run(() => { PreviousSegment(); }); + + } } } diff --git a/OpenpilotToolkit/OpenpilotToolkit.csproj b/OpenpilotToolkit/OpenpilotToolkit.csproj index 0777b74..46c902e 100644 --- a/OpenpilotToolkit/OpenpilotToolkit.csproj +++ b/OpenpilotToolkit/OpenpilotToolkit.csproj @@ -620,30 +620,30 @@ - - + + - + - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + - - + + - + @@ -724,7 +724,7 @@ - + \ No newline at end of file diff --git a/OpenpilotToolkit/OpenpilotToolkitForm.cs b/OpenpilotToolkit/OpenpilotToolkitForm.cs index 1750848..e93b198 100644 --- a/OpenpilotToolkit/OpenpilotToolkitForm.cs +++ b/OpenpilotToolkit/OpenpilotToolkitForm.cs @@ -30,6 +30,7 @@ using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; +using Renci.SshNet.Sftp; using Exception = System.Exception; using OpenpilotDevice = OpenpilotSdk.Hardware.OpenpilotDevice; @@ -121,7 +122,7 @@ private async void Form1_Load(object sender, EventArgs e) _libVlc = new LibVLC(); vlcVideoPlayer.Initialize(_libVlc); - vlcVideoPlayer.vlcVideoView.MediaPlayer.TimeChanged += MediaPlayerOnTimeChanged; + vlcVideoPlayer.vlcVideoView1.MediaPlayer.TimeChanged += MediaPlayerOnTimeChanged; cbCombineSegments.Checked = Properties.Settings.Default.CombineSegments; @@ -324,7 +325,11 @@ private async Task ScanDevices() { _devices.Clear(); lbDrives.Items.Clear(); - Task.Run(() => { vlcVideoPlayer.vlcVideoView.MediaPlayer.Stop(); }); + Task.Run(() => + { + vlcVideoPlayer.vlcVideoView1.MediaPlayer.Stop(); + vlcVideoPlayer.vlcVideoView2.MediaPlayer.Stop(); + }); dgvDriveInfo.DataSource = null; pbPreview.Image = null; pbPreview.BringToFront(); @@ -522,7 +527,11 @@ private async void lbDrives_SelectedIndexChanged(object sender, EventArgs e) cmbDevices.Enabled = false; dgvDriveInfo.DataSource = null; - Task.Run(() => { vlcVideoPlayer.vlcVideoView.MediaPlayer.Stop(); }); + Task.Run(() => + { + vlcVideoPlayer.vlcVideoView1.MediaPlayer.Stop(); + vlcVideoPlayer.vlcVideoView2.MediaPlayer.Stop(); + }); pbPreview.Image = null; pbPreview.BringToFront(); @@ -550,37 +559,25 @@ private async void lbDrives_SelectedIndexChanged(object sender, EventArgs e) { await Task.Run(async () => { - var thumbnailTask = openpilotDevice.GetThumbnailAsync(drive); Task videoStreamTask = null; - - if (firstSegment.FrontVideoQuick != null && videoFile == firstSegment.FrontVideoQuick) + List videoStreams; + if (firstSegment.FrontVideoQuick != null) { - videoStreamTask = openpilotDevice.OpenReadAsync(videoFile.File.FullName); + videoStreams = drive.Segments.Select(async (segment) => + await openpilotDevice.OpenReadAsync(segment.FrontVideoQuick.File + .FullName)).Select(t => t.Result).ToList(); } else { - videoStreamTask = openpilotDevice.OpenReadAsync(videoFile.File.FullName); - } - - var tasks = new List { thumbnailTask, videoStreamTask }; - - while (tasks.Any()) - { - var completedTask = await Task.WhenAny(tasks); - tasks.Remove(completedTask); - if (completedTask is Task videoStreamResult) - { - vlcVideoPlayer.Play(await videoStreamResult); - - } - else if(completedTask is Task thumbnailTaskResult) - { - System.Drawing.Bitmap thumbnail = await thumbnailTaskResult; - BeginInvoke(new MethodInvoker(() => { pbPreview.Image = thumbnail; })); - } + videoStreams = drive.Segments.Select(async (segment) => + await openpilotDevice.OpenReadAsync(segment.FrontVideo.File + .FullName)).Select(t => t.Result).ToList(); } + vlcVideoPlayer.Play(videoStreams); + System.Drawing.Bitmap thumbnail = await thumbnailTask; + BeginInvoke(new MethodInvoker(() => { pbPreview.Image = thumbnail; })); }); } } diff --git a/OpenpilotToolkit/OpenpilotToolkitForm.resx b/OpenpilotToolkit/OpenpilotToolkitForm.resx index 5d46ddc..4965f36 100644 --- a/OpenpilotToolkit/OpenpilotToolkitForm.resx +++ b/OpenpilotToolkit/OpenpilotToolkitForm.resx @@ -68,7 +68,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAEZTeXN0ZW0uV2luZG93cy5Gb3JtcywgQ3VsdHVyZT1uZXV0cmFs LCBQdWJsaWNLZXlUb2tlbj1iNzdhNWM1NjE5MzRlMDg5BQEAAAAmU3lzdGVtLldpbmRvd3MuRm9ybXMu SW1hZ2VMaXN0U3RyZWFtZXIBAAAABERhdGEHAgIAAAAJAwAAAA8DAAAA8B4AAAJNU0Z0AUkBTAIBAQ0B - AAHYAQgB2AEIARgBAAEYAQAE/wEhAQAI/wFCAU0BNgcAATYDAAEoAwABYAMAAWADAAEBAQABIAYAAZD/ + AAHgAQgB4AEIARgBAAEYAQAE/wEhAQAI/wFCAU0BNgcAATYDAAEoAwABYAMAAWADAAEBAQABIAYAAZD/ AP8A/wA5ABj//wBpABj//wBpAAj/CAAI//8AaQAI/wgACP//AGkACP8DCgENAwoBDQj//wBpAANjAd8E /wNdAcUDXQHFBP8DYwHf/wBpAAMYASADYwHfCP8DYwHfAxgBIP8ATQAU/wNjAd8DGAEgBAADGAEgA2MB 3wNjAd8DGAEgBAADGAEgA2MB3xT//wAxABj/A2MB3wMYASAEAAMYASADGAEgBAADGAEgA2MB3xj//wAx