How to change a video once the current has stopped? - c#

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?

Related

how to set WPF to allways recognize input

I am working on an wpf project with leap motion. My programm is allways checking for input via the leap motion controller and does something with it.
But when I open another programm (and my wpf gets in the background) my wpf freezes.
Is there a way my programm will not freeze even if I open another programm in fullscreen ?
EDIT:
here is how i get my input:
public MainWindow()
{
InitializeComponent();
CompositionTarget.Rendering += Update;
}
protected void Update(object sender, EventArgs e)
{
//get frame
Leap.Frame frame = leap.Frame();
...
}
Thank you Charles Ward this did it for me:
controller.SetPolicy(Controller.PolicyFlag.POLICY_BACKGROUND_FRAMES);
Leap doesn't seem to update when wpf window isn't active

Calling Play() on C# ShockWave component doesn't start YouTube video playback?

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);
}

Close c# application when video stops playing

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(); }
}

GIF Animation not working in Windows Form

I have 2 WinForms
Form2 uses Infragistics ultraTabControl.
On Tab Changing im Showing Form1.
In Form1
I have a PictureBox assigned with animated GIF
In Form2
I am displaying Form1 like this.
Form1 frmOne=new Form1();
frmOne.Show();
Problem
GIF is not playing animation.
Make sure you have your image in the image property NOT THE BACKGROUND IMAGE PROPERTY. That's the mistake I made
It is working fine for me. I have just dragged a new pictureBox on form and setting image property at Form_Load() event and showing GIF animated.
I did same as you on button click:
TestForms.NavBarTest newForm = new TestForms.NavBarTest();
newForm.Show();
At my Test Form:
private void NavBarTest_Load(object sender, EventArgs e)
{
pictureBox1.Image = NavronChartControl.Properties.Resources.url;
}
Note: If your picture box is disabled then it will not animate the Gif
Reference:
How do you show animated GIFs on a Windows Form (c#)
Animated Progress Indicator in C# (Windows Forms)
Try to implement using this link:Animated GIF in picturebox won't animate apprach.
The best way to achieve it is to run the animation in an async task, but accordingly, some limitations are possible to do that on windows form using:
System.Threading.Thread.Sleep(int milliseconds).
My splash view is displayed with a gif (loading)
e.g.: In your constructor,
public partial class MainMenu : Form
{
private SplashScreen splash = new SplashScreen();
public MainMenu ()
{
InitializeComponent();
Task.Factory.StartNew(() => {
splash.ShowDialog();
});
Thread.Sleep(2000);
}
It is imperative to put the Thread.Sleep(int) after starting a new one, don't forget that every action you did on this thread needs to be invoked, for example:
void CloseSplash()
{
Invoke(new MethodInvoker(() =>
{
splash.Close();
}));
}
Now your gif should work!
Solved
My current Thread is busy to Play GIF Animation.
I tried So many ways like Application.DoEvents(); etc.
But every thing can't helped me.
The answer in the following Question, which uses Threading is a very great working idea.
StackOverFlow: Show/Hide Splash Screen
Thanks for every one.
This question has already raised before.
Though the approach is different but the questions concept is the same
StackOverFlow: How do you show animated GIFs on a Windows Form (c#)
Source project where you can use Code Project
I guess that will help you out
I had the same issue and came across different solutions by implementing which I used to face several different issues. Finally, below is what I put some pieces from different posts together which worked for me as expected.
private void btnCompare_Click(object sender, EventArgs e)
{
ThreadStart threadStart = new ThreadStart(Execution);
Thread thread = new Thread(threadStart);
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
Here is the Execution method that also carries invoking the PictureBox control:
private void Execution()
{
btnCompare.Invoke((MethodInvoker)delegate { pictureBox1.Visible = true; });
Application.DoEvents();
// Your main code comes here . . .
btnCompare.Invoke((MethodInvoker)delegate { pictureBox1.Visible = false; });
}
Keep in mind, the PictureBox is invisible from Properties Window or do below:
private void ComparerForm_Load(object sender, EventArgs e)
{
pictureBox1.Visible = false;
}
If none of the previous answers work for you, another idea is to refresh the image tag or write it on the fly with jQuery.
In my case I needed to show an animated GIF when a button on the form was clicked. Previously it would show up but not animate. I just added a jQuery event when the button was clicked that added the image tag on-the-fly to a div through the parent tag's html() function.
$('.showhidegif').html("<img src='/Content/img/angled-spinner.gif' />");
<div class="col-sm-12 showhidegif"></div>
Worth a shot especially if you're already using jquery on your page.

how to execute a method BackgroundAudioPlayer fastforward?

Tell me please how to execute a method BackgroundAudioPlayer fastforward?
That is, how to do that when you long press the button, fast forward, and then release the button, the track nchinal play, in general as well as buttons work in the locked mode.
If you long press call as follows:
private void btnNext_Hold(object sender, System.Windows.Input.GestureEventArgs e)
{
BackgroundAudioPlayer.Instance.FastForward();
}
The track is scrolled to the end and pops up an error.
What is your desired behavior? You probably need some code on the MouseLeftButtonUp event to call Play to resume the playing of the current audio track.

Categories

Resources