Cannot display webcam Using Aforge.NET in C# - c#

I am currently working on a project where I need to simply display the users webcam on a
asp.image object. I am using the Aforge frame work and have gotten it to work on a windows app. In the windows app I would set up the video source variable equal to the image property of a picture box
In other words:
samplepicturebox1.image = videosource
The problem is, for asp there is only a asp:image object and the only property is .imageurl
imgSource.imageurl = ???
How would I go forth and link a video stream object to the image url or what other object would I use to display the stream? I have looked into putting an output on a seperate aspx.cs file so I could just use that as a imageurl but had no luck.
Here is my code to specify:
//using AForge.Video;
//using AForge.Video.DirectShow;
//using System.Drawing.Imaging;
public partial class WebForm1 : System.Web.UI.Page
{
private FilterInfoCollection VideoCaptureDevices;
private VideoCaptureDevice FinalVideo;
protected void Page_Load(object sender, EventArgs e)
{
drpSource.Items.Clear();
VideoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo VideoCaptureDevice in VideoCaptureDevices)
{
drpSource.Items.Add(VideoCaptureDevice.Name);
}
drpSource.SelectedIndex = 0;
}
protected void btnStart_Click(object sender, EventArgs e)
{
FinalVideo = new VideoCaptureDevice(VideoCaptureDevices[drpSource.SelectedIndex].MonikerString);
FinalVideo.NewFrame +=new NewFrameEventHandler(FinalVideo_NewFrame);
FinalVideo.Start();
}
void FinalVideo_NewFrame(object sender, NewFrameEventArgs deventArgs)
{
imgSource.ImageUrl=(FinalVideo.ToString());
}
}
I have also populated a combo box with the user's different video source. That also displays correctly
I really appreciate any help. This will translate into communications. I want to be able to stream between users just like Omegle and Chatroulette. If anyone would recommend a better framework to look into I'm open, I've only looked into Aforge and Touchless as two C# frameworks that support video streaming.
I've seen many use flash and I do know a bit of ActionScript, but to be completely honest, I'd rather not mess too much with flash as ActionScript is quite the pain and from my opinion in some aspects, flash slowly withering and dieing.

#KeithNicholas is correct. A web application is not the same as a client/winforms application. A web app is run in the webserver and not in the web browser.
It got no access to the user's webcam. You need to use a client side technology like flash or silverlight to be able to use the webcamera from the server.

Related

Youtube Video Player in C#

How do I embed a youtube video into my C# project?
I've looked at so many others that "answer" this question but, I can't find what I'm looking for.
I've tried many different ways to embed them but, they don't work.
I'm looking to use a web browser to just play the video but, with two options: loop and pause/play.
Reason I'm doing this is because I'm making a twitch chat bot and I'm trying to add song requests.
Latest attempt (because it was there so I decided on trying it out):
bool MUrlSpecify = true;
private void btnMSetCurrent_Click(object sender, EventArgs e)
{
const string page = "<html><head><title></title></head><body>{0}</body></html>";
string YTUrl;
if(MUrlSpecify == true)
{
YTUrl = "https://www.youtube.com/embed/" + txtMSetCurrent.Text;
wbMPlayer.DocumentText = string.Format(page, "");
}
}
(MUrlSpecify is a variable I added because later I'm going to have a search function)
If anyone can tell me how I should do this I'll try their method because I'm all
out of ideas.
Try to use webbrowser.NavigateToString("player code");
Get the code from share button in youtube. Work perfectly.
Example: wb.NavigateToString("<iframe width=\"420\" height=\"315\" src=\"https://www.youtube.com/embed/dSrozYNxAA4\" frameborder=\"0\" allowfullscreen></iframe>");

How to use NVDA screen reader in winForm application c#

I am working in winform application [Not WPF]. I need to support NVDA screen reader. Can anyone help how to make my application to support NVDA?
Does NVDA provide any SDK to used with .net ?
How can I implement below function in NVDA for Anouncing button name as i do with default narrator?
private void btnLogon_Click(object sender, EventArgs e) {
using(SpeechSynthesizer synth =new SpeechSynthesizer()) {
synth.SetOutputToDefaultAudioDevice();
synth.Speak("You have Pressed LOGON Button");
}
}
I have used screenreaderapi and used saystring method.

Playing sounds in WPF as a resource [duplicate]

This question already has answers here:
How to play a WPF Sound File resource
(4 answers)
Closed 7 years ago.
First of all, I've searched the site and looked at this but unfortunately it did not help me much.
Whenever I click a frog image that I made, I want to play a .wav file as a resource. Here's my code:
void newFrog_MouseUp(object sender, MouseButtonEventArgs e)
{
System.Media.SoundPlayer player = new System.Media.SoundPlayer(#"G:\COSR3S\FrogsAndLilyPads\FrogsAndLilyPads\Sounds\FrogCroak.wav");
player.Play();
}
Of course this worked but my problem is the directory changes from computer to computer, so I thought I'd have to play it as a resource. I don't know how to do that. I am a fairly new programmer, just to keep in mind.
I tried a few variations based on the aforementioned link and played around with it. Examples:
void newFrog_MouseUp(object sender, MouseButtonEventArgs e)
{
Uri uri = new Uri(#"pack://application:,,,/Sounds/FrogCroak.wav");
var player = new MediaPlayer();
player.Open(uri);
player.Play();
}
I also tried doing this, although I thought this one wouldn't work, but I tried it anyway:
void newFrog_MouseUp(object sender, MouseButtonEventArgs e)
{
Uri uri = new Uri(#"pack://application:,,,/Sounds/FrogCroak.wav");
System.Media.SoundPlayer player = new System.Media.SoundPlayer(uri);
player.Play();
}
I was not sure if the "pack://application:,,," was something that would refer to the file being played.
I also tried to make it as if it was an image, like so:
void newFrog_MouseUp(object sender, MouseButtonEventArgs e)
{
System.Media.SoundPlayer player = new System.Media.SoundPlayer(new Uri(#"pack://application:,,,/Sounds/FrogCroak.wav", UriKind.RelativeOrAbsolute));
player.Play();
}
So instead of new BitmapImage I did new System.Media.SoundPlayer and only to find out that it wouldn't work that way.
EDIT: I forgot to mention that this worked, but it did not play any sound.
void newFrog_MouseUp(object sender, MouseButtonEventArgs e)
{
Uri uri = new Uri(#"pack://application:,,,/Sounds/FrogCroak.wav");
var player = new MediaPlayer();
player.Open(uri);
player.Play();
}
Edit2: The possible duplicate technically didn't solve my problem, but according to the accepted answer it is not possible. Is there any other way I could play the audio using a different method?
This works for me using Visual Studio 2013 with a command line application:
Embed the .wav file as a resource (Resources.resx) in the project
I used Add Resource from Existing file
Set the persistence for the file as 'Linked at compile time'
Reference the file from code using something like this. Timer is the namespace this code is from and NotificationSound is what I called the embedded sound:
var notificationSound = new SoundPlayer(Timer.Properties.Resources.NotificationSound);
notificationSound.PlaySync();
This allowed me to play the sound from the application after moving the executable and renaming the original sound file (just to check that it was actually embedded).

Sharing from Windows Phone 8

I am working on a Windows Phone 8 app and am trying to share content through the DataTransferManager. The Windows API documentation says it is supported in Windows Phone but when the DataTransferManager.GetForCurrentView() function is called I get an exception
System.NotSupportedException was unhandled by user code
HResult=-2146233067
Message=Specified method is not supported.
Source=Windows
InnerException:
I have been searching for an answer and can't find anyone else with the same issue, any help would be appreciated. All samples on this topic seem to be Windows 8 specific, but Phone 8 does include these functions. Here's sample code from my app.
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(dataTransferManager_DataRequested);
}
private void dataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
DataPackage requestData = e.Request.Data;
requestData.Properties.Title = "Share Text Example";
requestData.Properties.Description = "An example of how to share text.";
requestData.SetText("Hello World!");
}
private void Button_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
{
DataTransferManager.ShowShareUI();
}
Again, the exception is shown when the page loads on the DataTransferManager.GetForCurrentView(); function so it doesn't get to the other lines, but included them anyway. I've tried adding/removing permissions and assemblies but must be missing something. I've also tried putting the function in different events (such as the onTap function) with the same results.
If anyone is interested in trying this on their own here is some documentation:
DataTransferManager
DataRequested
DataPackage
GetForCurrentView()
UPDATE
Although it may not be the best solution given the context of this question, I am implementing the Email/Sms/Link Tasks as described below rather than using the DataTransferManager. It seems that DataTransferManager may not be accessible in WP8 and although the tasks will take a number of different functions they seem to be the best way to perform the intended functionality.
I think I have found most of what I was looking for with Launchers... Rather than just using the Windows 8 general sharing functionality I can be specific with Tasks/Launchers.
Unfortunately it doesn't have as many sharing options as the charm does, I will be implementing several functions for email/sms/social but so far this is the best solution.
Here are the functions that I will be implementing
private void ShareLink(object sender, System.Windows.Input.GestureEventArgs e)
{
ShareLinkTask shareLinkTask = new ShareLinkTask()
{
Title = "Code Samples",
LinkUri = new Uri("http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff431744(v=vs.92).aspx", UriKind.Absolute),
Message = "Here are some great code samples for Windows Phone."
};
shareLinkTask.Show();
}
private void ShareEmail(object sender, System.Windows.Input.GestureEventArgs e)
{
EmailComposeTask emailComposeTask = new EmailComposeTask()
{
Subject = "message subject",
Body = "message body",
To = "recipient#example.com",
Cc = "cc#example.com",
Bcc = "bcc#example.com"
};
emailComposeTask.Show();
}
private void ShareSMS(object sender, System.Windows.Input.GestureEventArgs e)
{
SmsComposeTask smsComposeTask = new SmsComposeTask()
{
Body = "Try this new application. It's great!"
};
smsComposeTask.Show();
}
Ref:
Launchers for Windows Phone
Share Link Task
According to my API reference, DataTransferManager is reserved for native apps only. Windows Phone API Quickstart.
Have you tried using the fully qualified method? It would be something like this:
DataTransferManager dataTransferManager = indows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
Also, make sure your target is Windows Phone 8.
The Windows 8 Share Contract isn't supported on WP8. There isn't even a Share charm on WP8. Why are you trying to use the DataTransferManager?
Instead of using the Share Contract, most usecases can work just fine with WP8 app2app custom protocols and file extensions. Using WP8 app you can transfer files and data across apps. Althrough the standardized contract of the Share Contract is gone, apps can create their own contracts using custom protocols and file extensions.
Here for example you can learn more about a real-world 3rd party implementation of Nokia Music custom protocols.

Webcams, C#, and a reliable wrapper

I'm in dire need of a replacement for a wrapper being used in a C# application. Basically, what we need to do is attach a webcam feed to one of two picture boxes. This will be used to take still images at the push of a button, which may detach the camera feed and attach the still image to that picture box, then reattach the camera feed later. We had previously found some free code to utilize with a CaptureDevice.cs file and Pinvoke.dll to tie it into avicap32.dll. Unfortunately, this seems to have random, intermittent errors that cannot be reliably reproduced. It's just too flaky. At some random point, one of those picture boxes may go black and won't show the feed until the picture is taken, at which point the proper picture is attached to the picture box. Then, even if there's only one webcam attached, it'll keep prompting for the webcam to be selected, something it wouldn't do otherwise.
Quite frankly, I'm surprised and dismayed that Microsoft hasn't included anything in .NET to cover webcam video feeds. I'm looking for something reliable and relatively simple to implement to replace this buggy webcam system.
It is time to use MediaCapture object. Use this sample for MS Windows 10 https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/CameraStarterKit/
And read this article as well http://www.codepool.biz/csharp-camera-api-video-frame.html
May I suggest
http://www.emgu.com/wiki/index.php/Main_Page
I have used OpenCV in many C++ libraries and it seems to work very well for webcams from other things I've tried. Emgu is just a C# wrapper for OpenCV.
Here is a sample project to try it out on. It's very basic and simple, but should work right away.
http://dl.dropbox.com/u/18919663/vs%20samples/OpenCVCSharpTest.zip (just uploaded)
Sample:
using Emgu.CV;
using Emgu.CV.Structure;
...
public partial class Form1 : Form
{
public Capture cvWebCam;
public Form1()
{
InitializeComponent();
try
{
cvWebCam = new Capture();
timer1.Start();
}
catch
{
Console.WriteLine("Default camera not found or could not start");
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (cvWebCam != null)
using (Emgu.CV.Image<Bgr, byte> frame = cvWebCam.QueryFrame())
{
pictureBox1.BackgroundImage = frame.ToBitmap();
}
}
}
Try DirectShow.net- it's a free wrapper library to access DirectShow functionality from .NET:
http://directshownet.sourceforge.net
Its code samples contain a sample app for capturing video from webcams, too:
http://sourceforge.net/projects/directshownet/files/DirectShowSamples/

Categories