瀏覽代碼

data URI Support

Coder 8 月之前
父節點
當前提交
16f50c3f1c

+ 38 - 0
Bmp.Core/Playback/Inputs/InputSourceProvider.cs

@@ -179,6 +179,25 @@ namespace Bmp.Core.Playback.Inputs
                 var fileInfo = new FileInfo(urlOrPath);
                 size = fileInfo.Length;
             }
+            else if (uri.IsAbsoluteUri && uri.Scheme.ToLower() == "data")
+            {
+
+                var base64 = urlOrPath.Split(",").LastOrDefault();
+                if (base64 != null)
+                {
+                    try
+                    {
+                        var bytes = Convert.FromBase64String(base64);
+                        exists = true;
+                        return (exists, bytes.Length);
+                    }
+                    catch (Exception e)
+                    {
+                        //TODO: Event Bus?
+                        Console.WriteLine(e);
+                    }
+                }
+            }
             else
             {
                 using var client = new HttpClient();
@@ -227,6 +246,25 @@ namespace Bmp.Core.Playback.Inputs
                 return File.OpenRead(urlOrPath);
             }
 
+            if (uri.IsAbsoluteUri && uri.Scheme.ToLower() == "data")
+            {
+                var base64 = urlOrPath.Split(",").LastOrDefault();
+                if (base64 != null)
+                {
+                    try
+                    {
+                        var bytes = Convert.FromBase64String(base64);
+                        return new MemoryStream(bytes);
+                    }
+                    catch (Exception e)
+                    {
+                        //TODO: Event Bus?
+                        Console.WriteLine(e);
+                        throw;
+                    }
+                }
+            }
+
             return new SeekableHttpStream(urlOrPath);
         }
     }

+ 6 - 6
Bmp.WinForms/MainForm.Designer.cs

@@ -51,7 +51,7 @@
             StatusBarLabel = new ToolStripStatusLabel();
             SettingButtonToolTip = new ToolTip(components);
             MainPanel = new Panel();
-            TrackBarToolTip = new ToolTip(components);
+            SeekTrackBarToolTip = new ToolTip(components);
             ((System.ComponentModel.ISupportInitialize)SeekTrackBar).BeginInit();
             MainStatusBar.SuspendLayout();
             MainPanel.SuspendLayout();
@@ -63,7 +63,7 @@
             SeekTrackBar.LargeChange = 1;
             SeekTrackBar.Location = new Point(407, 12);
             SeekTrackBar.Name = "SeekTrackBar";
-            SeekTrackBar.Size = new Size(508, 69);
+            SeekTrackBar.Size = new Size(517, 69);
             SeekTrackBar.TabIndex = 5;
             SeekTrackBar.TickFrequency = 0;
             SeekTrackBar.TickStyle = TickStyle.Both;
@@ -188,7 +188,7 @@
             // 
             SettingButton.Anchor = AnchorStyles.Top | AnchorStyles.Right;
             SettingButton.Font = new Font("Microsoft YaHei UI", 19F);
-            SettingButton.Location = new Point(921, 12);
+            SettingButton.Location = new Point(930, 12);
             SettingButton.Name = "SettingButton";
             SettingButton.Size = new Size(73, 69);
             SettingButton.TabIndex = 6;
@@ -238,9 +238,9 @@
             MainPanel.Size = new Size(1006, 518);
             MainPanel.TabIndex = 8;
             // 
-            // TrackBarToolTip
+            // SeekTrackBarToolTip
             // 
-            TrackBarToolTip.ShowAlways = true;
+            SeekTrackBarToolTip.ShowAlways = true;
             // 
             // MainForm
             // 
@@ -282,6 +282,6 @@
         private ToolTip SettingButtonToolTip;
         private Panel panel1;
         private Panel MainPanel;
-        private ToolTip TrackBarToolTip;
+        private ToolTip SeekTrackBarToolTip;
     }
 }

+ 6 - 5
Bmp.WinForms/MainForm.cs

@@ -478,7 +478,7 @@ namespace Bmp.WinForms
                     var localVarPath = path;
                     if (Uri.TryCreate(path, UriKind.RelativeOrAbsolute, out var uri) && uri.IsFile == false) localVarPath = uri.ToString();
 
-                    item.Text = Path.GetFileName(localVarPath);
+                    item.Text = Uri.UnescapeDataString(Path.GetFileName(localVarPath));
                     if (string.IsNullOrWhiteSpace(item.Text)) item.Text = localVarPath;
 
                     for (var i = 0; i < MainListView.Columns.Count - 1; i++) item.SubItems.Add("");
@@ -1092,12 +1092,15 @@ namespace Bmp.WinForms
         private void SeekTrackBar_ValueChanged(object sender, EventArgs e)
         {
             if (_trackBarHolding == false) return;
-            TrackBarToolTip.Show(TimeSpan.FromMilliseconds(SeekTrackBar.Value).ToString(), SeekTrackBar,0,-32);
+            var timeSpan = TimeSpan.FromMilliseconds(SeekTrackBar.Value);
+            var text = $"{timeSpan.Hours:00}:{timeSpan.Minutes:00}:{timeSpan.Seconds:00}.{timeSpan.Milliseconds:000}";
+            SeekTrackBarToolTip.Show(text, SeekTrackBar, 0, -SeekTrackBar.Height / 2);
         }
 
         private async void SeekTrackBar_MouseUp(object sender, MouseEventArgs e)
         {
-            TrackBarToolTip.Hide(SeekTrackBar);
+            SeekTrackBarToolTip.Hide(SeekTrackBar);
+            SeekTrackBarToolTip.RemoveAll();
 
             MainPanel.Enabled = false;
             if (_inputSource != null)
@@ -1143,8 +1146,6 @@ namespace Bmp.WinForms
             MainPanel.Enabled = true;
             _trackBarHolding = false;
         }
-
-
     }
 
     internal enum UIPlaybackState

+ 1 - 1
Bmp.WinForms/MainForm.resx

@@ -132,7 +132,7 @@
   <metadata name="SettingButtonToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>818, 19</value>
   </metadata>
-  <metadata name="TrackBarToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+  <metadata name="SeekTrackBarToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>1067, 19</value>
   </metadata>
   <metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">