I have a simple WinForms C# application that embeds a ShockWave COM component on a form. I have a Test button that when clicked, calls the Play() method on the component. When I click the button nothing happens. The YouTube player is plainly visible in the ShockWave component with a video still and the player chrome in the frame, with a big Play button on it. But it doesn't start playing.
Sample code:
private void button1_Click(object sender, EventArgs e)
{
axShockwaveFlash1.Play();
}
Does anyone know how to fix this? I'm wondering if it's because the ShockWave component might need to have "requires click to play" or some other registry/system setting cleared before the Play() method works? If that happens to be the case, then how can I do that programmatically so a new install works perfectly without putting the user through some kind of a pre-setup hassle?
With Youtube videos and AxShockwaveFlash objects the Play() method doesn't function, however, there is a nice workaround for this.
The secret is adding ?autoplay=1 to the end of the URL containing the video you wish to play.
Something like this will provide the desired effect:
private void button1_Click(object sender, EventArgs e)
{
string path = #"http://www.youtube.com/v/Q-h4ulFK2Ek?autoplay=1";
axShockwaveFlash1.Load(0, path);
}
Related
I am currently working with .NET 4.5. Programming a photobooth. The photobooth should start wit fullscreen:
Show an Intro screen with an intro video.
When the user clicks on the screen, it has to show a get ready! video
When the get ready video finishes playing, it has to show a countdown video
When the countdown video finishes, it has to take a picture.
Right now I can do #1 and #2. I can also take pictures. My problem is with the sequence. Once a video finishes, I need to change the video, but since everything runs in the event handler, it only plays the video WHILE the program is running the event handler.
Is there any better and smarter way to do this?
Here is my code:
What I have and works right now:
private void Form1_Load(object sender, EventArgs e)
{
// maximize the screen
FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Maximized;
TopMost = true;
// play an intro video without the UI controls
this.videoPath = this.basePath + "intro.mp4";
this.wmpVideo.URL = this.videoPath;
this.wmpVideo.settings.setMode("Loop", true);
this.wmpVideo.Ctlcontrols.play();
this.wmpVideo.uiMode = "none";
}
Then, if the user clicks on the video, it will change the video to a new file:
private void wmpVideo_MouseDownEvent(object sender, AxWMPLib._WMPOCXEvents_MouseDownEvent e)
{
if (this.current == 0) //this means that currently we are in the intro
{
// Then I change the video to "get ready!"
this.changeVideo("getready.mp4",1);
}
changeVideo basically updates the video to getready.mp4. Then, I need it to change it to countdown.mp4.
In order to move from one video to another, I need to check when the video finishes. I do this right now with:
wmpVideo.PlayStateChange += new AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler(checkGetReadyFinished);
And the event handler looks like this:
private void checkGetReadyFinished(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
if (e.newState == 8) {
// If we are currently in the "getready state"
if (this.current == 1)
{
// then I change the video to the countdown.mp4
this.changeVideo("countdown.mp4", 2);
}
}
}
PROBLEM
I noticed the video ONLY plays when I am on the event handler method. I realized this because I saw that no video was played, so I added a MessageBox in the changeVideo method. I saw that as long as the MessageBox was showing, the video was playing. When I clicked "OK", the video disappeared
I.E., I need to stay in the event handler method.
QUESTION
Is there any other better way to show a video1, then show video2 when video1 finishes. As I mentioned, I need to do a photobooth program.
I also tried calling another form, but as soon as I set it to fullscreen, the screen sort of flashes.
Is there any optimal way of doing this?
So I've got application that uses webbrowser and going through specified website.
At the end of the process it clicks on button and Download dialog box appear. Problem is: to download this file I have to either SendKeys or position properly mouse and simulate clicks.. When I have remote desktop open it works well, but when I disconnect SendKeys give error "Access denied" - I believe it's related to windows lock mode, and mouse is not moving at all..
Is there any possibility that I can make it work? I found that there is no other option to download that file than SendKeys or simulate mouse position and clicks.. I have to stick to webbrowser.
Why are you trying to visually click on the button, or link? just in DocumentCompleted event of the WebBrwoser invoke the click event:
public void WebBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser wb = (WebBrowser)sender;
wb.Document.GetElementById("someElementId").InvokeMember("click");
}
Of course in this example I have used GetElementById() however you may use any method or loops, ... to find the element you want.
I have a windows form application,there is a webbrowser control on the middle of the form. that navigates to a Youtube video, the full screen button of the video doesn't work.
How can i get the fullscreen event (when triggered using html or flash)?
void MainFormLoad(object sender, EventArgs e){
this.KeyDown+= new KeyEventHandler(MainForm_KeyDown);}
void MainForm_KeyDown(object sender, KeyEventArgs e){
if( e.KeyCode == Keys.ControlKey)
MessageBox.Show("What is the Ctrl?");}
I am still shocked by how bad IE 11 shows web pages. So I strongly recommend using another engine like Chromium. View this post in order to know about library options.
I went with CefSharp and there is a great How To Guide in here But the browser lakes just full screens to form boundaries, so be noted in case using this option you might need to implement it yourself.
I am trying to figure out how to close my application when the video that the form plays stops playing. Currently, the user clicks a button to bring up Form2. The control for the video is set to force the video full screen, and start playing from the beginning of the video. I am using axWindowsMediaPlayer to provide the video. I am also a complete neophyte when it comes to C#.
How would I get my application to close when the video stops playing?
You need to detect when the media has ended, here is a tutorial on: "Detect the End of Media - axWindowsMediaPlayer". Then you need to call Close(); to close the form you are currently playing the media from.
Example (snippets from msdn):
// Subscribe to the Play State Change event
player.PlayStateChange +=
new AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler(player_PlayStateChange);
Then you need the event handler that can look like this:
private void player_PlayStateChange(object sender,
AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
// 8 = Media Ended
if(e.newState == 8) { Close(); }
}
I want my sound to play when I click a button. the sound file will play but will only play once.
I need it to play everytime i hit a button. please help.
Heres what i have so far::
XAML:
MediaElement x:Name="SoundClip" Source="Dart.mp3" AutoPlay="False" />
C#:
private void OutBull_Click(object sender, RoutedEventArgs e)
{
SoundClip.Play();
game.update_score(25);
updateGUI();
}
private void Bull_Click(object sender, RoutedEventArgs e)
{
SoundClip.Play();
game.update_score(50);
updateGUI();
}
I need all these to play the sound when i click them. Not just once in which it only does?????
If you set the MediaEnded event as below it should work.
private void SoundClip_MediaEnded(object sender, Windows.UI.Xaml.RoutedEventArgs e) {
SoundClip.Stop();
}
SoundPlayer is only supposed to be compatible with .wav files. Have you attempted to convert your .mp3 file to a .wav file? It may be causing the SoundPlayer to stop working after the first time it plays the file due to the lack of compatibility.
So in your HTML code there should be an or something that you can set to reset
This is java but if you google onclick reset it should help.
<br>
<input type="reset" name=resetbutton value=Reset
onClick='alert("The reset button was clicked")'>
<br>
Reset the buttons at the end so the next time you click it, the methods get passed to the button again.
Should work