public MediaElementPro GetPlayer(TrackItem item) { if (player1.GetTag <TrackItem>() == item) { return(player1); } else if (player2.GetTag <TrackItem>() == item) { return(player2); } return(null); }
public async void PlayPlayer(TrackItem trackItem) { MediaElementPro player = p1Playing ? player2 : player1; MediaElementLoader loader = p1Playing ? loader2 : loader1; if (!player.VideoLoaded) { if (player.GetTag <TrackItem>() == null) { player.Tag = trackItem; } await loader.LoadVideo(player.GetTag <TrackItem>()); } if (trackItem != player.GetTag <TrackItem>()) { return; } Console.WriteLine($"Play{player.Source.ToString()} At {player.Name}"); player.Play(); Canvas rootCanvas = ((VideoLayer)player.TemplatedParent).Parent as Canvas; VideoLayer rootLayer = (VideoLayer)player.TemplatedParent; player.PositionChanged += localPositionChanged; p1Playing = !p1Playing; trackItem.PropertyChanged += (sen, e) => { object value = PropertyManager.GetProperty(trackItem.Property, e.PropertyName); switch (e.PropertyName.ToLower()) { case "left": case "top": case "scale": rootLayer.Width = (double.IsNaN(rootCanvas.Width) ? rootCanvas.ActualWidth : rootCanvas.Width) * (double)PropertyManager.GetProperty(trackItem.Property, "Scale"); rootLayer.Height = (double.IsNaN(rootCanvas.Height) ? rootCanvas.ActualWidth : rootCanvas.Height) * (double)PropertyManager.GetProperty(trackItem.Property, "Scale"); player.Width = rootLayer.Width; player.Height = rootLayer.Height; Canvas.SetLeft(rootLayer, (rootCanvas.ActualWidth - player.Width + (rootCanvas.ActualWidth * 2 * (double)PropertyManager.GetProperty(trackItem.Property, "Left"))) / 2); Canvas.SetTop(rootLayer, (rootCanvas.ActualHeight - player.Height + (rootCanvas.ActualHeight * 2 * (double)PropertyManager.GetProperty(trackItem.Property, "Top"))) / 2); break; case "opacity": player.Opacity = (double)value; break; case "volume": var volume = (((double)value) * 0.5); Console.WriteLine(trackItem.Text + " : " + volume); if (volume == 0) { Application.Current.MainWindow.Dispatcher.Invoke(() => { player.Volume = 0; }); } else { player.Volume = volume + 0.5; } if ((bool)PropertyManager.GetProperty(trackItem.Property, "IsMute") && player.Volume != 0) { ((VideoItemProperty)trackItem.Property).IsMute = false; } break; case "chromakeyuse": case "chromakeyusage": case "chromakeycolor": VideoLayer vLayer = (VideoLayer)player.TemplatedParent; Brush newColor = (Brush)PropertyManager.GetProperty(trackItem.Property, "ChromaKeyColor"); SolidColorBrush newBrush = (SolidColorBrush)newColor; newBrush.Color.ToHSL(out double _h, out double _s, out double _l); _chromaKeyEffect = new ChromaKeyEffect() { HueMin = (float)_h, HueMax = (float)_h, SaturationMax = (float)_s, SaturationMin = (float)_s, LuminanceMax = (float)_l, LuminanceMin = (float)_l, Smooth = (float)((double)PropertyManager.GetProperty(trackItem.Property, "ChromaKeyUsage")), }; if ((bool)PropertyManager.GetProperty(trackItem.Property, "ChromaKeyUse")) { vLayer.Effect = _chromaKeyEffect; } else { vLayer.Effect = null; } break; case "ismute": bool isMute = (bool)value; if (isMute) { player.Volume = 0; } else { player.Volume = (double)PropertyManager.GetProperty(trackItem.Property, "Volume"); } break; default: break; } }; foreach (PropertyInfo allProperties in trackItem.Property.GetType().GetRuntimeProperties()) { trackItem.OnPropertyChanged(allProperties.Name); } void localPositionChanged(MediaElementPro s, TimeSpan p) { s.PositionChanged -= localPositionChanged; TrackItem itm = s.GetTag <TrackItem>(); s.Position = MediaTools.FrameToTimeSpan(itm.ForwardOffset + CurrentFrame - itm.Offset, CurrentFrameRate); s.Visibility = Visibility.Visible; s.Width = rootCanvas.ActualWidth;// * itm.ItemProperty.Size; s.Height = rootCanvas.ActualHeight; if (s == player1) { player2.Visibility = Visibility.Hidden; } else { player1.Visibility = Visibility.Hidden; } } }