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.
Related
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)
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 am new to Windows Phone development and I am trying to do something which I believe is quite simple: I have a page, with a button and a textBlock. I would like that, whenever the button is pressed, the textBlock's text change to "Bazinga!" for a few seconds and then revert to its previous value.
I have tried the code below but it does not work (I suppose because the textBlock's display is not refreshed while still in the Button_Click call).
After looking up a few keywords, I saw this: WPF not updating textbox while in progress
This tells me I must explicitly call the Dispatcher's Invoke method... but I only see a BeginInvoke() method (I guess this is a specificity of Windows Phone) and my few attempts at getting it right have been unlucky.
Thanks for any help you can
private void Button_Click(object sender, RoutedEventArgs e)
{
this.Function();
}
private void Function()
{
string text = this.TextBlock1.Text;
DateTime until = DateTime.Now.AddSeconds(5.0);
this.TextBlock1.Text = "Bazinga!";
while (DateTime.Now < until)
{
// Do nothing
}
this.TextBlock1.Text = text;
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
string text = TextBlock1.Text;
TextBlock1.Text = "Bazinga!";
await Task.Delay(5000);
TextBlock1.Text = text;
}
There have been a bunch of questions on how to implement a progress bar and I believe I have been through all of them and I still don't know why my progress bar won't work.
Well, it seems to work only after the operation is done, which is of course not what I want. I want the progress bar to work as the main operation is doing its thing.
My code is pretty long and painful so I'm going to simplify it to make it as basic as possible.
private void button1_Click(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync();
//Main UI Operation
}
private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 1; i <= 100; i++)
{
// Wait 100 milliseconds.
Thread.Sleep(100);
// Report progress.
backgroundWorker1.ReportProgress(i); }
}
private void BackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
}
Like I said, I only see the progress bar start after my main UI operation.
WorkerReportsProgress is set to True.
Minimum and Maximum are 0 and 100 respectively.
I feel like this might be a lack of understanding on Threads.
I tested the same code as you and found it worked. Did you forget to change the WorkerReportesProress property to True?
I have a strange bug, please, let me know if you have any clues about the reason.
I have a Timer (System.Windows.Forms.Timer) on my main form, which fires some updates, which also eventually update the main form UI. Then I have an editor, which is opened from the main form using the ShowDialog() method. On this editor I have a PropertyGrid (System.Windows.Forms.PropertyGrid).
I am unable to reproduce it everytime, but pretty often, when I use dropdowns on that property grid in editor it gets stuck, that is OK/Cancel buttons don't close the form, property grid becomes not usable, Close button in the form header doesn't work.
There are no exceptions in the background, and if I break the process I see that the app is doing some calculations related to the updates I mentioned in the beginning.
What can you recommend? Any ideas are welcome.
What's happening is that the thread timer's Tick method doesn't execute on a different thread, so it's locking everything else until it's done. I made a test winforms app that had a timer and 2 buttons on it whose events did this:
private void timer1_Tick(object sender, EventArgs e)
{
Thread.Sleep(6000);
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Start();
}
private void button2_Click(object sender, EventArgs e)
{
frmShow show = new frmShow();
show.ShowDialog(); // frmShow just has some controls on it to fiddle with
}
and indeed it blocked as you described. The following solved it:
private void timer1_Tick(object sender, EventArgs e)
{
ThreadPool.QueueUserWorkItem(DoStuff);
}
private void DoStuff(object something)
{
Thread.Sleep(6000);
}