I hope someone will be able to help me with my issue. i want to take a screenshot of the video at a specific time index, however when i try to change the time all i get is a blank black screen. i added buttons which play and pause, it allows me to play and pause the video, if i do that and then change the time index, i get an image. im confused as to why it doesn’t work using code. i even preform btnplay.PeformClick(); to play the video and when i do btnpause.PerformClick() to pause the video it doesn’t.
it seems that i can only get an image of the video if i have to physically hit the play and then pause button on my form, im trying to achieve this using code
private void Form1_Load(object sender, EventArgs e)
{
////////////////////LC4 VLC Settings///////////////////////////////////////////////////////////////////////////////////////////
control = new VlcControl();
var currentAssembly = Assembly.GetEntryAssembly();
var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;
var libDirectory = new DirectoryInfo(Path.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64"));
control.BeginInit();
control.VlcLibDirectory = libDirectory;
control.Dock = DockStyle.Fill;
control.EndInit();
panel1.Controls.Add(control);
main_form_LC4_data();
}
void main_form_LC4_data()
{
long vOut3 = 20;
playfile("path to file");
First_Frame(vOut3);
}
void playfile(string final)
{
control.SetMedia(new Uri(final).AbsoluteUri);
control.Time = 0;
control.Update();
}
void First_Frame(long vOut3)
{
control.Time = vOut3;
}
private void button9_Click(object sender, EventArgs e)
{
control.Play();
Console.WriteLine("PLAY");
}
private void button8_Click(object sender, EventArgs e)
{
control.Pause();
Console.WriteLine("PAUSE");
}
Above is my code in a nut shell
i have tried things like this
private void button10_Click(object sender, EventArgs e)
{
First_Frame(first_frame); // jump to index
}
and then calling up button10.PerformClick(); however it doesnt seem to work. once again if i physically hit the buttons on my form it works perfectly, however not in the way of coding it.
as an example :
play.PeformClick();
Pause.PeformClick();
time = vOut3;
I do hope this isnt to confusing im really stuck and am still hoping someone can help me
Thank you
A few things:
control.Update();
this does nothing.
You need to wait for the Playing event to be raised after setting the time, otherwise libvlc doesn't have the time to decode the frame and display it (setting the time is asynchronous)
Related
What I tried to was getting the value in the following way, which didn't work:
private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Normal);
axWindowsMediaPlayer1.Ctlcontrols.play();
axWindowsMediaPlayer1.Ctlcontrols.currentItem =
axWindowsMediaPlayer1.currentPlaylist.Item[listBox1.SelectedIndex];
backgroundWorker2.RunWorkerAsync();
}
private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
{
double val = 100*axWindowsMediaPlayer1.Ctlcontrols.currentPosition/axWindowsMediaPlayer1.currentMedia.duration;
TaskbarManager.Instance.SetProgressValue((int)val,100);
}
I am also not sure, where would I put the line for stopping the progress, but I guess it is a bit early to think about it, since I can't get the progress to work anyway.
Is the problem in how I used the backgroundWorker or in how I update the value, or something else?
Thanks in advance,
~~hlfrmn
EDIT:
private void TaskbarProgressValueDeterminator()
{
TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Normal);
while (axWindowsMediaPlayer1.Ctlcontrols.currentPosition < axWindowsMediaPlayer1.currentMedia.duration)
{
TaskbarManager.Instance.SetProgressValue((int)(100 * axWindowsMediaPlayer1.Ctlcontrols.currentPosition / axWindowsMediaPlayer1.currentMedia.duration), 100);
}
TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.NoProgress);
}
The background worker will update the progress only once. I expect you need to put in a while loop or a timer to update the progress repeatedly while the track is playing.
the title may sound confusing but ill explain it better here. Im making a program which displays the webcam capture in a picturebox using the "easy web cam" external reference. If i turn on my computer, go into VS, open the project and run, it will work, displaying my webcam capture. If i stop the program and then run it again, when i try to display it, i get a popup asking me to select a video source, none of the options is even my webcam and then another popup will appear saying
"An error ocurred while capturing the video image. The video capture will now be terminated.
Object reference not set to ann instance of an object"
The only thing i can think of is that the first time its setting up the camera but when i close it im not turning it off properly so when i run it again, it wont work. anyway heres the relevant code, bare in mind if answering, im not that experienced when coding so sometimes you might have to spell stuff out
using WebCam_Capture;
namespace WindowsWebRef
{
public partial class Frm_Main : Form
{
public Frm_Main()
{
InitializeComponent();
}
WebCam webcam;
private void button1_Click(object sender, EventArgs e)
{
webcam.Start();
}
private void Frm_Main_Load(object sender, EventArgs e)
{
webcam = new WebCam();
webcam.InitializeWebCam(ref WebCamIMG);
}
And the webcam class...
class WebCam
{
private WebCamCapture webcam;
private System.Windows.Forms.PictureBox _FrameImage;
private int FrameNumber = 30;
public void InitializeWebCam(ref System.Windows.Forms.PictureBox ImageControl)
{
webcam = new WebCamCapture();
webcam.FrameNumber = ((ulong)(0ul));
webcam.TimeToCapture_milliseconds = FrameNumber;
webcam.ImageCaptured += new WebCamCapture.WebCamEventHandler(webcam_ImageCaptured);
_FrameImage = ImageControl;
}
void webcam_ImageCaptured(object source, WebcamEventArgs e)
{
_FrameImage.Image = e.WebCamImage;
}
public void Start()
{
webcam.TimeToCapture_milliseconds = FrameNumber;
webcam.Start(0);
}
Restart your computer and be sure to add in webcam.Stop(); otherwise your program will hold on to the webcam and make it unavailable to use in any other application (or a different instance of the program.)
I struggled with what to title this as but hopefully I can explain a little better here. I am trying to write a program that will track an assembly through a 6 station assembly line. At each station, the operator will hit a button (such as station1start, station1stop, station2start, etc) and the button press event will send the timestamp to a database and also update the form visually by moving the traveling id number to the next station. I have this all working for the first couple of stations but I'm wondering if there is a way to use the same method for each station. For example have a method such as
void updateStart(int station_num)
where the station ID would be an argument but otherwise the method could be used for all of the stations. I know that variables in C# cannot be dynamically changed but am curious if there is another way to make this code cleaner. It seems like bad programming to have 6 methods almost identical. Especially if we were to add another 6 stations. See the screenshot of the form and my example code below of the button that the operator would hit when they started at station 2. Any help would be greatly appreciated!
http://i.stack.imgur.com/Ddxww.png
private void Station2Start_Click(object sender, EventArgs e)
{
Station2Label.Text = Station1Label.Text;
Station1Label.Text = "";
Station1Status.Text = "";
Station2Status.Text = "IN PROGRESS";
addTimeToDb(2);
}
The question is somewhat unclear but I believe it is:
I have the following code:
private void Station2Start_Click(object sender, EventArgs e)
{
Station2Label.Text = Station1Label.Text;
Station1Label.Text = "";
Station1Status.Text = "";
Station2Status.Text = "IN PROGRESS";
addTimeToDb(2);
}
private void Station3Start_Click(object sender, EventArgs e)
{
Station3Label.Text = Station2Label.Text;
Station2Label.Text = "";
Station2Status.Text = "";
Station3Status.Text = "IN PROGRESS";
addTimeToDb(2);
}
And so on, repeated many times with minor substitutions. How do I "DRY out" this code? (That is Don't Repeat Yourself.)
When you create the labels and status boxes put them in an array:
private Label[] stationLabels;
private Label[] statusLabels;
...
// in your form initialization after the creation of the labels:
stationLabels = new [] { Station1Label, Station2Label, Station3Label, ...
// and similarly for status labels.
Now write
private void StationClick(int station)
{
stationLabels[station-1].Text = stationLabels[station-2].Text;
... and so on
And then each method becomes
private void Station2Start_Click(object sender, EventArgs e)
{
StationClick(2);
}
private void Station3Start_Click(object sender, EventArgs e)
{
StationClick(3);
}
And so on.
I have a tabbed form with a StatusStrip at the bottom, which includes a StatusLabel. I want to use this status label for various actions ("1 record updated" etc). It is simple enough to create specific events to set the label's text property.
But how best to reset the status to blank? The user could perform any number of other operations where the status is no longer meaningful (going to another tab, clicking other buttons etc.).
It is not feasible to create all the possible events to reset the status message. Is there a way to incorporate some type of timer so that the message fades out after several seconds? Has anyone else found a good solution for this?
Is it truly important to clear the status though? There are plenty of products which will keep their status label unchanged until the next status event occurs. Visual Studio is a good example of this. It may be worth simplifying your scenario and taking this approach.
If you do want to clear the status after an event I think the most maintainable way to do this is with a Timer. Essentially clear after a few seconds when the status is set
Timer m_timer;
void SetStatus(string text) {
m_statusLabel.Text = text;
m_timer.Reset();
}
void OnTimerTick(object sender, EventArgs e) {
m_statusLabel.Text = "";
m_timer.Stop();
}
Yes a timer would work for this to clear it. Here is an example of one I've knocked together.
public partial class Form1 : Form
{
private System.Timers.Timer _systemTimer = null;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
_systemTimer = new System.Timers.Timer(500);
_systemTimer.Elapsed += _systemTimer_Elapsed;
}
void _systemTimer_Elapsed(object sender, ElapsedEventArgs e)
{
toolStripStatusLabel1.Text = string.Empty;
_systemTimer.Stop(); // stop it if you don't want it repeating
}
private void button1_Click(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = "random text just as an example";
}
private void button2_Click(object sender, EventArgs e)
{
_systemTimer.Start();
}
}
Assume button1 is your action to update the status, and button2 is just a random way to start the timer (this can be however you want to start it, I've only used another button click as an example). After the set amount of time passes the status label will be cleared.
I have an embedded video in a winform using axwindowsmediaplayer and C#.
I have a timer to set the control to fullscreen=true after some time.
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Stop();
videowmp.fullScreen = true;
}
I use a database to get the videos, and I call a function to obtain them every time the video finishes, for some reason I needed a second timer there to start the new video:
private void videowmp_PlayStateChange(object sender,
AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
if (e.newState == 8)
{
timer2.Interval = 100;
timer2.Enabled = true;
}
}
private void timer2_Tick(object sender, EventArgs e)
{
timer2.Enabled = false;
selec_video();
}
The function selec_video() gets the video, set the URL for the windows media player control and set it to play().
My problem is that when a video finishes, I lose full-screen mode. I mean the video goes back to its original size. I tried to set fullscreen=true after calling selec_video(), but I got an error (catastrophic error). I suppose this happens because the control is already in full screen... So what I want to do, is call selec_video(), without losing the full-screen mode.
The below code is checking your media player's play state. If it's playing something, it will set it to full screen mode.
private void timer2_Tick(object sender, EventArgs e)
{
selec_video();
if (videowmp.playState == WMPLib.WMPPlayState.wmppsPlaying)
{
videowmp.fullScreen = true;
}
}
You can use PlayStateChange action. And also you can find other state codes from PlayStateChange Event of the AxWindowsMediaPlayer Object
private void axWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
if (e.newState == 3)//Playing
{
axWindowsMediaPlayer1.fullScreen = true;
}
}