Hello all,
I am developign an application where a user come in front of camera and custom video will play and when user move out of camera range the video get stop. I have develope that motion detection app but unable to make video play and pause.
Please see code:
Window 1:
using System;
using System.Windows;
using System.Windows. Controls;
using Ozeki.Camera;
using Ozeki.Media;
namespace Basic_CameraVie wer
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private DrawingImagePro vider _provider;
private MediaConnector _connector;
private MotionDetector _detector;
private CameraURLBuilde rWPF _myCameraURLBui lder;
private OzekiCamera _camera;
public MainWindow()
{
InitializeCompo nent();
_connector = new MediaConnector( );
_provider = new DrawingImagePro vider();
_detector = new MotionDetector( );
videoViewer.Set ImageProvider(_ provider);
video MyWin = new video();
MyWin.Show();
}
void GuiThread(Actio n action)
{
Dispatcher.Begi nInvoke(action) ;
}
private void StartMotionDete ction()
{
_detector.Highl ightMotion = HighlightMotion .Highlight;
_detector.Motio nColor = MotionColor.Red ;
_detector.Motio nDetection += detector_Motion Detection;
_detector.Start ();
}
void detector_Motion Detection(objec t sender, MotionDetection Event e)
{
GuiThread(() =>
{
if (e.Detection)
{
MotionEventLabe l.Content = "Motion Detected";
}
else
MotionEventLabe l.Content = "Motion Stopped";
video MyWin = new video(MotionEve ntLabel.Content .ToString());
});
}
private void StopMotionDetec tion()
{
_detector.Stop( );
_detector.Motio nDetection -= detector_Motion Detection;
_detector.Dispo se();
}
private void MotionChecked(o bject sender, RoutedEventArgs e)
{
MotionEventLabe l.Content = String.Empty;
var check = sender as CheckBox;
if (check != null)
{
if ((bool)check.Is Checked)
StartMotionDete ction();
else
StopMotionDetec tion();
}
}
private void Compose_Click(o bject sender, RoutedEventArgs e)
{
_myCameraURLBui lder = new CameraURLBuilde rWPF();
var result = _myCameraURLBui lder.ShowDialog ();
if (result == true)
{
if (_camera != null)
{
_camera.Disconn ect();
videoViewer.Sto p();
}
_camera = new OzekiCamera(_my CameraURLBuilde r.CameraURL);
_camera.CameraS tateChanged += _camera_CameraS tateChanged;
InvokeGuiThread (() =>
{
UrlTextBox.Text = _myCameraURLBui lder.CameraURL;
});
Disconnect();
}
}
private void Connect_Click(o bject sender, RoutedEventArgs e)
{
Streaming();
_connector.Conn ect(_camera.Vid eoChannel, _detector);
_connector.Conn ect(_detector, _provider);
_camera.Start() ;
videoViewer.Sta rt();
}
private void Disconnect_Clic k(object sender, RoutedEventArgs e)
{
_connector.Disc onnect(_camera. VideoChannel, _detector);
_connector.Disc onnect(_detecto r, _provider);
_detector.Stop( );
_camera.Disconn ect();
videoViewer.Sto p();
}
private void Disconnect()
{
btn_Connect.IsE nabled = true;
btn_Disconnect. IsEnabled = false;
}
private void Streaming()
{
btn_Connect.IsE nabled = false;
btn_Disconnect. IsEnabled = true;
}
void _camera_CameraS tateChanged(obj ect sender, CameraStateEven tArgs e)
{
InvokeGuiThread (() =>
{
if (e.State == CameraState.Str eaming)
{
Streaming();
}
if (e.State == CameraState.Dis connected)
{
Disconnect();
}
});
}
private void InvokeGuiThread (Action action)
{
Dispatcher.Begi nInvoke(action) ;
}
}
}
Window 2:
using System;
using System.Collecti ons.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows. Controls;
using System.Windows. Data;
using System.Windows. Documents;
using System.Windows. Input;
using System.Windows. Media;
using System.Windows. Media.Imaging;
using System.Windows. Shapes;
using Microsoft.Direc tX.AudioVideoPl ayback;
namespace Basic_CameraVie wer
{
/// <summary>
/// Interaction logic for video.xaml
/// </summary>
public partial class video : Window
{
public video()
{
InitializeCompo nent();
VideoControl.Vo lume = 100;
}
public video(string content)
{
string Motion = "Motion Detected";
string MotionStopped= "Motion Stopped";
if (content.ToStri ng() == Motion)
{
this.Button_Cli ck(content);
}
else if(content.ToSt ring() == MotionStopped)
{
this.Button_Cli ck2(content);
}
}
private void Button_Click2(s tring dsfsdfsd)
{
string MotionStopped = "Motion Stopped";
if (dsfsdfsd == MotionStopped)
{
VideoControl.Pa use();
}
}
private void Button_Click(st ring sendere)
{
string MotionStopped = "Motion Detected";
if (sendere == MotionStopped)
{
VideoControl.Pl ay();
}
}
}
}
Please help.
Thanks in advance.
I am developign an application where a user come in front of camera and custom video will play and when user move out of camera range the video get stop. I have develope that motion detection app but unable to make video play and pause.
Please see code:
Window 1:
using System;
using System.Windows;
using System.Windows. Controls;
using Ozeki.Camera;
using Ozeki.Media;
namespace Basic_CameraVie wer
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private DrawingImagePro vider _provider;
private MediaConnector _connector;
private MotionDetector _detector;
private CameraURLBuilde rWPF _myCameraURLBui lder;
private OzekiCamera _camera;
public MainWindow()
{
InitializeCompo nent();
_connector = new MediaConnector( );
_provider = new DrawingImagePro vider();
_detector = new MotionDetector( );
videoViewer.Set ImageProvider(_ provider);
video MyWin = new video();
MyWin.Show();
}
void GuiThread(Actio n action)
{
Dispatcher.Begi nInvoke(action) ;
}
private void StartMotionDete ction()
{
_detector.Highl ightMotion = HighlightMotion .Highlight;
_detector.Motio nColor = MotionColor.Red ;
_detector.Motio nDetection += detector_Motion Detection;
_detector.Start ();
}
void detector_Motion Detection(objec t sender, MotionDetection Event e)
{
GuiThread(() =>
{
if (e.Detection)
{
MotionEventLabe l.Content = "Motion Detected";
}
else
MotionEventLabe l.Content = "Motion Stopped";
video MyWin = new video(MotionEve ntLabel.Content .ToString());
});
}
private void StopMotionDetec tion()
{
_detector.Stop( );
_detector.Motio nDetection -= detector_Motion Detection;
_detector.Dispo se();
}
private void MotionChecked(o bject sender, RoutedEventArgs e)
{
MotionEventLabe l.Content = String.Empty;
var check = sender as CheckBox;
if (check != null)
{
if ((bool)check.Is Checked)
StartMotionDete ction();
else
StopMotionDetec tion();
}
}
private void Compose_Click(o bject sender, RoutedEventArgs e)
{
_myCameraURLBui lder = new CameraURLBuilde rWPF();
var result = _myCameraURLBui lder.ShowDialog ();
if (result == true)
{
if (_camera != null)
{
_camera.Disconn ect();
videoViewer.Sto p();
}
_camera = new OzekiCamera(_my CameraURLBuilde r.CameraURL);
_camera.CameraS tateChanged += _camera_CameraS tateChanged;
InvokeGuiThread (() =>
{
UrlTextBox.Text = _myCameraURLBui lder.CameraURL;
});
Disconnect();
}
}
private void Connect_Click(o bject sender, RoutedEventArgs e)
{
Streaming();
_connector.Conn ect(_camera.Vid eoChannel, _detector);
_connector.Conn ect(_detector, _provider);
_camera.Start() ;
videoViewer.Sta rt();
}
private void Disconnect_Clic k(object sender, RoutedEventArgs e)
{
_connector.Disc onnect(_camera. VideoChannel, _detector);
_connector.Disc onnect(_detecto r, _provider);
_detector.Stop( );
_camera.Disconn ect();
videoViewer.Sto p();
}
private void Disconnect()
{
btn_Connect.IsE nabled = true;
btn_Disconnect. IsEnabled = false;
}
private void Streaming()
{
btn_Connect.IsE nabled = false;
btn_Disconnect. IsEnabled = true;
}
void _camera_CameraS tateChanged(obj ect sender, CameraStateEven tArgs e)
{
InvokeGuiThread (() =>
{
if (e.State == CameraState.Str eaming)
{
Streaming();
}
if (e.State == CameraState.Dis connected)
{
Disconnect();
}
});
}
private void InvokeGuiThread (Action action)
{
Dispatcher.Begi nInvoke(action) ;
}
}
}
Window 2:
using System;
using System.Collecti ons.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows. Controls;
using System.Windows. Data;
using System.Windows. Documents;
using System.Windows. Input;
using System.Windows. Media;
using System.Windows. Media.Imaging;
using System.Windows. Shapes;
using Microsoft.Direc tX.AudioVideoPl ayback;
namespace Basic_CameraVie wer
{
/// <summary>
/// Interaction logic for video.xaml
/// </summary>
public partial class video : Window
{
public video()
{
InitializeCompo nent();
VideoControl.Vo lume = 100;
}
public video(string content)
{
string Motion = "Motion Detected";
string MotionStopped= "Motion Stopped";
if (content.ToStri ng() == Motion)
{
this.Button_Cli ck(content);
}
else if(content.ToSt ring() == MotionStopped)
{
this.Button_Cli ck2(content);
}
}
private void Button_Click2(s tring dsfsdfsd)
{
string MotionStopped = "Motion Stopped";
if (dsfsdfsd == MotionStopped)
{
VideoControl.Pa use();
}
}
private void Button_Click(st ring sendere)
{
string MotionStopped = "Motion Detected";
if (sendere == MotionStopped)
{
VideoControl.Pl ay();
}
}
}
}
Please help.
Thanks in advance.