Advertisement
Vertegel

Untitled

Jun 20th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.84 KB | None | 0 0
  1. public MainWindow()
  2.         {
  3.             InitializeComponent();
  4.  
  5.             MediaBack.Source = new Uri("C:/Content/i5_Back.mp4");
  6.             MediaBack.Play();
  7.             MediaContent.Source = new Uri("C:/Content/i5_Content.mp4");
  8.  
  9.  
  10.             Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
  11.             IPEndPoint ip = new IPEndPoint(IPAddress.Any, 5003);
  12.             s.Bind(ip);
  13.             ReceiveUdp(s);
  14.          
  15.         }
  16.  
  17.        
  18.  
  19.         public void ReceiveUdp(Socket s)
  20.         {
  21.             SocketAsyncEventArgs e = new SocketAsyncEventArgs();
  22.             e.SetBuffer(new byte[100], 0, 100);
  23.             e.RemoteEndPoint = new IPEndPoint(IPAddress.Any, 5003);
  24.             e.UserToken = s;
  25.             e.Completed += new EventHandler<SocketAsyncEventArgs>(RecvCompleted);
  26.             s.ReceiveFromAsync(e);
  27.         }
  28.  
  29.         public void RecvCompleted(object sender, SocketAsyncEventArgs e)
  30.         {
  31.             string Data = Encoding.ASCII.GetString(e.Buffer, e.Offset, e.BytesTransferred);
  32.        
  33.             ReceiveUdp((Socket)e.UserToken);
  34.  
  35.             Dispatcher.BeginInvoke(new ThreadStart(delegate
  36.             {
  37.                 // label.Content = Data;
  38.                 if (Data == "PLAY")
  39.                 {
  40.  
  41.                     if (!locked)
  42.                     {
  43.                         MediaContent.Position = TimeSpan.FromTicks(1);
  44.                         MediaContent.Play();
  45.                         DoubleAnimation FadeIn = new DoubleAnimation(0.0, 1.0, new Duration(TimeSpan.FromSeconds(0.5)), FillBehavior.HoldEnd);
  46.                         DoubleAnimation FadeOut = new DoubleAnimation(1.0, 0.0, new Duration(TimeSpan.FromSeconds(0.5)), FillBehavior.HoldEnd);
  47.                         MediaContent.BeginAnimation(MediaElement.OpacityProperty, FadeIn);
  48.                         MediaBack.BeginAnimation(MediaElement.OpacityProperty, FadeOut);
  49.  
  50.                        
  51.  
  52.  
  53.                         MediaBack.Stop();
  54.                         locked = true;
  55.                     }
  56.  
  57.                 }
  58.                 else if (Data == "STOP")
  59.                 {
  60.                     if (locked)
  61.                     {
  62.                         MediaBack.Play();
  63.                         DoubleAnimation FadeIn = new DoubleAnimation(0.0, 1.0, new Duration(TimeSpan.FromSeconds(0.5)), FillBehavior.HoldEnd);
  64.                         DoubleAnimation FadeOut = new DoubleAnimation(1.0, 0.0, new Duration(TimeSpan.FromSeconds(0.5)), FillBehavior.HoldEnd);
  65.                         MediaBack.BeginAnimation(MediaElement.OpacityProperty, FadeIn);
  66.                         MediaContent.BeginAnimation(MediaElement.OpacityProperty, FadeOut);
  67.                         MediaContent.Stop();
  68.  
  69.                         locked = false;
  70.  
  71.                     }
  72.  
  73.                 }
  74.  
  75.  
  76.             }));
  77.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement