473,404 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Media Element Unable to Pause and Play Programmatically

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_CameraViewer
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{

private DrawingImageProvider _provider;

private MediaConnector _connector;

private MotionDetector _detector;

private CameraURLBuilderWPF _myCameraURLBuilder;

private OzekiCamera _camera;

public MainWindow()
{
InitializeComponent();

_connector = new MediaConnector();

_provider = new DrawingImageProvider();

_detector = new MotionDetector();

videoViewer.SetImageProvider(_provider);

video MyWin = new video();
MyWin.Show();


}

void GuiThread(Action action)
{
Dispatcher.BeginInvoke(action);
}

private void StartMotionDetection()
{
_detector.HighlightMotion = HighlightMotion.Highlight;
_detector.MotionColor = MotionColor.Red;
_detector.MotionDetection += detector_MotionDetection;
_detector.Start();
}

void detector_MotionDetection(object sender, MotionDetectionEvent e)
{


GuiThread(() =>
{
if (e.Detection)
{
MotionEventLabel.Content = "Motion Detected";

}

else
MotionEventLabel.Content = "Motion Stopped";


video MyWin = new video(MotionEventLabel.Content.ToString());

});
}

private void StopMotionDetection()
{
_detector.Stop();
_detector.MotionDetection -= detector_MotionDetection;
_detector.Dispose();
}

private void MotionChecked(object sender, RoutedEventArgs e)
{
MotionEventLabel.Content = String.Empty;
var check = sender as CheckBox;
if (check != null)
{
if ((bool)check.IsChecked)
StartMotionDetection();
else
StopMotionDetection();
}
}

private void Compose_Click(object sender, RoutedEventArgs e)
{
_myCameraURLBuilder = new CameraURLBuilderWPF();
var result = _myCameraURLBuilder.ShowDialog();

if (result == true)
{
if (_camera != null)
{
_camera.Disconnect();
videoViewer.Stop();
}

_camera = new OzekiCamera(_myCameraURLBuilder.CameraURL);
_camera.CameraStateChanged += _camera_CameraStateChanged;

InvokeGuiThread(() =>
{
UrlTextBox.Text = _myCameraURLBuilder.CameraURL;
});

Disconnect();
}
}

private void Connect_Click(object sender, RoutedEventArgs e)
{

Streaming();

_connector.Connect(_camera.VideoChannel, _detector);
_connector.Connect(_detector, _provider);

_camera.Start();
videoViewer.Start();

}

private void Disconnect_Click(object sender, RoutedEventArgs e)
{
_connector.Disconnect(_camera.VideoChannel, _detector);
_connector.Disconnect(_detector, _provider);

_detector.Stop();
_camera.Disconnect();
videoViewer.Stop();
}

private void Disconnect()
{
btn_Connect.IsEnabled = true;
btn_Disconnect.IsEnabled = false;
}

private void Streaming()
{
btn_Connect.IsEnabled = false;
btn_Disconnect.IsEnabled = true;
}

void _camera_CameraStateChanged(object sender, CameraStateEventArgs e)
{
InvokeGuiThread(() =>
{
if (e.State == CameraState.Streaming)
{
Streaming();
}
if (e.State == CameraState.Disconnected)
{
Disconnect();
}

});
}

private void InvokeGuiThread(Action action)
{
Dispatcher.BeginInvoke(action);
}
}
}


Window 2:

using System;
using System.Collections.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.DirectX.AudioVideoPlayback;


namespace Basic_CameraViewer
{
/// <summary>
/// Interaction logic for video.xaml
/// </summary>
public partial class video : Window
{
public video()
{
InitializeComponent();
VideoControl.Volume = 100;



}

public video(string content)
{
string Motion = "Motion Detected";
string MotionStopped= "Motion Stopped";
if (content.ToString() == Motion)
{
this.Button_Click(content);

}
else if(content.ToString() == MotionStopped)
{
this.Button_Click2(content);

}
}

private void Button_Click2(string dsfsdfsd)
{
string MotionStopped = "Motion Stopped";
if (dsfsdfsd == MotionStopped)
{
VideoControl.Pause();
}

}

private void Button_Click(string sendere)
{
string MotionStopped = "Motion Detected";
if (sendere == MotionStopped)
{
VideoControl.Play();
}

}
}
}
Please help.

Thanks in advance.
Dec 20 '16 #1
0 1132

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Sepham.com | last post by:
Hi! I need to use the WMP10 ActiveX in my VB .NET application. When i try to open a file with the control, if the extension isn't recognized, it shows me a messagebox. How can I catch the event...
0
by: Senthamarai | last post by:
I have a list of .WMV files stored in a network share. Only one user will have permission to view the share contents. I want my program to impersonate that particular user while accessing and...
5
by: Brian.Steele | last post by:
Greetings everyone. See http://www.spiceisle.com/cgi-bin/slideshow/slideshow.cgi?dir=brian/personal/2005/uk_trip/images&type=jpg The "Pause" button works in IE, but not in Firefox. Any ideas...
3
by: John Piper | last post by:
Again, I am a beginer, and need help. Can some walk me through the steps to do the following: click a button, which will play a video file in WMP in fullscreen mode (launch player, not in a form)...
1
by: microteq | last post by:
Hello, I am trying to play a file from my ASP.NET application on the client's browser using a link like: <a href="../sounds/21.wav">Play</a> When I click the link, WMP opens and I get the...
5
by: | last post by:
Hello, I am wrtting a program that does some sound effects... the files are stored in a subfolder in the application folder... and I check the existence of the files before calling the method to...
1
by: =?Utf-8?B?c2hhcmVu?= | last post by:
im having a problem with my computer im trying to play sims2 seasons and every time i try to start the game it gives me an error msg 0x0000005 ive been unable to play this game for 6 months and its...
3
by: kelleyg | last post by:
I see this has been asked already, but the answer was insufficient: 'check the sticky' is not an answer. What, pray tell, is a 'sticky?' There is nothing called 'sticky' in the Flash forum. ...
2
by: =?Utf-8?B?amRjaGFyYm9ubmVhdQ==?= | last post by:
How can I use the media-control hardware buttons (play/pause, stop, next-track, previous-track) within my c# application? Thanks!
0
by: pavanip | last post by:
Hi, I am new to Silverlight Applications. I created one media player control to play video in asp.net website.I want to drag and drop that media player control to desired place when we run the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.