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>");
Related
i've been working on a personal assistant project, so far its going great but i dont know how to make her do a google search.
here's what i've tried :
if (speech == "friday search google")
{
Friday.SpeakAsync("what are you searching for?");
//theoratically speaking the next line should be the problem, i need a string that
//starts recording audio so i can recall the recorded audio as the named string (search)
SpeechRecognitionEngine search = new SpeechRecognitionEngine(); // <-- this line
string url = "www.google.com/search?=q";
Process.Start(url + search);
}
or if im entirely wrong, i'd really appreciate some help into making it work.
thanks in advance everyone!
Can someone please tell me whey I am getting a black screen with no video, only sound?
private void screen1btnPlay_Click(object sender, EventArgs e)
{
ScreenOne playScreen1 = new ScreenOne();
playScreen1.PlayScreenOne();
}
... and the other form is like this:
public partial class ScreenOne : Form
{
public ScreenOne()
{
InitializeComponent();
}
public void PlayScreenOne()
{
axVLCPlugin21.playlist.add("file:///" + #"Filepath", null);
axVLCPlugin21.playlist.play();
}
}
Sound works fine, but no video. All the properties of the VLC are left to default, is there something I need to change when using this plugin across multiple forms? Anyone know what's wrong?
Update:: I rebuilt the program in WPF and I am having the same problem. When I have a button on the second form (same form as player) it works fine, as soon as I call it from the main form, sound only. ugh!
I dont know but i can give some solution suggestions,
Make sure the VLC program is installed as 32-bit. I dont know, I've solved a problem that way.
I think high probabilty your problem is based on about "C:\Program Files (x86)\VideoLAN\VLC\plugins" Check your plugins. maybe your audio_filter, audio_mixer, audio_output plugins are missing.
you can remove Vlc, then download and install last VLC 32 bit.
I think that will solve your problem. Dont forget AxAXVLC works with vlc plugins.
I figured out my problem on my own!
When I was creating this instance,
ScreenOne playScreen1 = new ScreenOne();
I was actually creating a redundant instance of what I was trying to do, I'm not sure if that's the right way to put it but I basically already had an instance of the second form and was making another separate instance of the form that was named differently.
I already had in my code to open the second form
Screen2 Screen2 = new Screen2();
private void openScreen2Button_Click(object sender, EventArgs e)
{
Screen2.Show();
}
Then later was doing this which is WRONG, I was adding playscreen1 when I should still have been using Screen2.
Screen2 playScreen1 = new Screen2();
playScreen1.PlayScreenOne();
So when I wanted to use the method to play the media player on the second form from the first one, I just needed to use the same instance of Screen2 that I had created to open the form to begin with instead of created a new instance for what method I wanted to use.
IDK if my explanation makes sense, or maybe its basics to most people (I'm a noob), but if anyone comes across this problem, message me and I'll try to help.
o7
I am working on a C# Project with Visual Studio 2013.
My Problem:
There is a website on which you can search something and it displays a few results (i.e 30 of 1200). So, at the bottom of this website is a button to show more 30 results.
I succeeded in reading the current 30 results (using the WebClient), but I have no idea how to find a solution to get ALL the results.
I know what to do, but I don't know how to do it. I have to click on the button until there are no hidden results anymore. After that I have to read out the html (with my existing code).
I searched on google for a few hours and found some things with "headless" browsers, and I also tried to use the "InvokeMember"-Method of the Webbrowser, but it doesn't work. I only get the 30 results if I print out the HTML.
I hope you understand my question. Please help me.
Thanks.
WebBrowserControl Scroll to Bottom
private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
webBrowser1.Navigated += (s1, e1) =>
{
if (webBrowser1.Document.Body != null) webBrowser1.Document.Body.ScrollIntoView(false);
};
}
Or
if (theDoc.Body.InnerHtml != null)
{
try
{
webBrowser1.Document.Window.ScrollTo(0, webBrowser1.Document.Body.ScrollRectangle.Height);
timer2.Enabled = true;
}
catch { }
}
else
{
timer2.Enabled = true;
}
It looks like you need to implement pagination.
Depending on your requirements, you might need server or client side.
The link might help you decide:
StackOverflow Client Side vs Server Side
NOT using API
I am currently attempting to use a web browser in C# to load google maps and automatically focus on my current location, however, for some reason I cannot get this to work properly. The idea is simple. Load Google maps, and either execute the script to focus on my current location:
mapBrowser.Document.InvokeScript("mylocation.onButtonClick");
Or, invoke the button click through an HtmlElement:
HtmlElement myLocationButton = mapBrowser.Document.GetElementById("mylocation");
myLocationButton.InvokeMember("click");
But, of course neither of these methods actually work correctly, the coordinates returned are incorrent and the map never actually focuses. Any ideas on how I can fix this issue properly? The scripts aren't invoked until after the document is actually loaded:
private void mapBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if(mapBrowser.Url.ToString() == "https://www.google.com/maps/preview/")
{
try
{
//HtmlElement myLocationButton = mapBrowser.Document.GetElementById("mylocation");
//myLocationButton.InvokeMember("click");
mapBrowser.Document.InvokeScript("mylocation.onButtonClick");
//mapBrowser.Document.InvokeScript("focus:mylocation.main");
}
catch (Exception ex)
{
MessageBox.Show("Error Invoking Script: " + ex.Message);
}
}
}
so I don't believe that is the cause of my problem. Even more frustratingly, the auto-focus works fine if I click the button manually.
Any help is appreciated, thank you!
(NOTE, you may have to go into IE and allow Google maps access to your location in order to replicate this issue properly)
I've had problem few times that WebBrowser control uses too old version of IE. You need to modify registry to get it to use newer version of IE.
I tried "https://www.google.com/maps/preview/" with both IE 8 and 9 and it gave me an error, but it works on IE 10.
See: http://weblog.west-wind.com/posts/2011/May/21/Web-Browser-Control-Specifying-the-IE-Version
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/