Media Player - Show custom Time Code - vb.net

I am trying to make a video player for a project which seems to be quite a challenge when I came to a stage where I need to show a time code (sort of time stamp) in a label next to the video being played.
The function of the program is...The movie file name contains the recording start time of the movie file in the format "17:56:33_Camera01.avi". When I load the movie in the player using the URL and click play the movie plays. I use a timer to get the current position of the playback in seconds,minutes and hours using the below method in the timer tick sub.
Dim PlayHour, PlayMin, PlaySec As Integer
Dim iSecond As Double = AxWindowsMediaPlayer1.Ctlcontrols.currentPosition
Dim iSpan As TimeSpan = TimeSpan.FromSeconds(iSecond)
PlayHour = iSpan.Hours.ToString.PadLeft(2, "0"c)
PlayMin = iSpan.Minutes.ToString.PadLeft(2, "0"c)
PlaySec = iSpan.Seconds.ToString.PadLeft(2, "0"c)
My requirement is to dynamically set a time code in the label by adding the current position hour, minute and second to the recorded time of the movie.
For example the movie file will show the time code as 17:56:33" when loaded, when the playback begins the seconds,minutes and hours (17:56:34, 17:56:35 and so...) should start incrementing in accordance with the actual time of the playback.
Can any one please guide me in the right direction... I am breaking my head on this since quite some time and heading no where...I am quite sure I have to use Timespan for this but don't know how to get this done.

Stick this in the tick event of a timer and set the interval to 1...
Dim controls As WMPLib.IWMPControls3 = axWindowsMediaPlayer1.Ctlcontrols
controls.currentPositionTimecode = "[00000]01:00:30.05"
Label1.Text = controls.currentPositionString
All you'll need to change is "Label1" and "axWindowsMediaPlayer1". You might want to play around with "[00000]01:00:30.05" to get the format you require; this displays mm:ss.

hii add label to media and this code to timer of track bar
` TrackBar2.Maximum = AxWindowsMediaPlayer1.Ctlcontrols.currentItem.duration
Label3.Text = AxWindowsMediaPlayer1.Ctlcontrols.currentPositionString
TrackBar2.Value = AxWindowsMediaPlayer1.Ctlcontrols.currentPosition
Label4.Text = AxWindowsMediaPlayer1.Ctlcontrols.currentItem.durationString `

Related

Windows Media Player Time Position

I embedded the Windows Media Player in a Microsoft Access form. I need to start playing videos from a specific time position. How can I set up the start position in VBA?
This is the code where I need to control WindowsMediaPlayer object, when clicking on a form list item the record should start playing let say... from 5th minute:
Sub SearchList_Click()
Me.WindowsMediaPlayer.URL = Me.SearchList.Column(2)
End Sub
Write:
Me.WindowsMediaPlayer.Contents.CurrentPosition=300
Ref:
https://learn.microsoft.com/en-us/windows/win32/wmp/object-model-reference-for-scripting
https://learn.microsoft.com/en-us/windows/win32/wmp/controls-object
https://learn.microsoft.com/en-us/windows/win32/wmp/controls-currentposition

Wait for 1 second before starting code again - VB.NET

I desperately need help with a game I am making. For a bit of context, i am making a memory game and i have the following piece of code that is being troublesome. I have a bunch of labels on the form, 16 to be exact, with 1 randomly generated symbol placed in each. Each symbol appears in the labels twice.
------------------------------Continued----------------------------------------
'MsgBox("hello") 'used to check if the second inccorect press shows up - it does show but instantly changes colour
'''''''''''''''''NEED SOME CODE THAT PAUSES IT HERE'''''''''''''''
labels(0).ForeColor = Color.DarkRed
sender.ForeColor = Color.DarkRed
End If
flips = 1
End If
End If
tmrmemory.Enabled = True ' starts the timer after the user clicks the first label
End Sub
What's supposed to happen is that when the labels clicked don't match, it should show both the clicked labels for a short period before changing them both back to "DarkRed" which is the colour of the form's background.
I have tried using a timer but then i can't use sender.forecolor=color.darkred because it is not declared globally.
I have also tried using the command Threading.Thread.Sleep(500) but it still doesn't show the second incorrect click. I know that the code i have used works because when i use the message box, i can see both symbols and when the two clicks are correct, it stays.
Threading.Thread.Sleep(500) will actually pause your code for half a second. However during this time it won't do anything, not even refresh your controls. To get the effect you want, you need to call the YourControl.Refresh method before calling Threading.Thread.Sleep to force the control to redraw immediately.
On a side note, I would advise you not to call Threading.Thread.Sleep on UI thread. It will give a feeling of program hang. Instead do your work on a separate thread. You can either do all the work yourself right from creating a separate thread to destroying it, or use the BackgroundWorker control which has all the functionality built in.
Here is the link to an article I wrote a long time ago regarding BackgroundWorker that might be useful for you:
http://www.vbforums.com/showthread.php?680130-Correct-way-to-use-the-BackgroundWorker
Declare a variable outside the sub that stores what label should be flipped when the timer ends.
Label click sets
storedLabel = sender
Timer tick sets storedLabel.ForeColor = Color.DarkRed

How do I make a section of code execute if a button is clicked after another button is clicked in visual basic

So basically what the title says. I want to make a program where you click a button, and then another button shows up, and then if you click the next button in a certain amount of time you get a point.
This is what I found in another thread, but this also makes the timer count down before the second button even shows up, even though this code is after the code making the next button show up.
Do While DoWhileBool = True
Select Case DirectCast(Sender, Button).Name
Case "ClickHere2"
If TimeCount > 0 Then
MultCount += 1
End If
Case "ClickHere3"
If TimeCount > 0 Then
MultCount += 1
End If
This is not the full code by any means, but I just wanted to show what I tried that doesn't work for having a button click event in an if statement inside another button click method.
Edit: I ended up figuring it out partially but pretty much all of what I was asking thanks to the help of the answer:
NumButTim.Stop()
If TimerVar <> 0 Then
MultCount += 1
MultCounter.Text = MultCount
MultCounter.Refresh()
End If
NumButTim.Start()
TimerVar = 5
'Do Until TimerVar = 0
' TimerVar = Timer1.ToString
' TimeCounter.Text = Timer1.ToString
' TimeCounter.Refresh()
'Loop
End Sub
The commented section was where I was trying to get a textbox to show the countdown time, but it doesn't work. I'm sure I could figure it out if I wanted to, but I've moved on to other things. Thanks to the person who answered it, he probably led me to the right answer.
Sidenote: I don't use visual basic anymore, but the idea I had that this was a part of was sort of a mix of clicker game num pad typing and letter key typing and the typing would increase a multiplier for a while. Never really finished that idea and I don't even know if what I had made in that game even exists anymore because my external hard drive went kaput before I had transferred all the old files onto my current computer.
From what i understand of your question, this is how i would do it:
Add a timer, and 2 buttons to the form
On form load, you want to set the interval on the timer, so something like this:
Timer1.Interval = 1000 'Set the interval to 1 second
Then when you click on the first button show the second button, so on button1 click:
Button2.show() 'Show the second button
Timer1.Start() 'Start the timer, so they have 1 second from now
And in button 2 click, you want to do your event, add a point etc:
points += 1
Then to make the second button dissapear, (timeout) after a certian amount of time, you change the interval of the timer1. If the button wants to show for 1 second, set the interval to 1000 (milliseconds)
Then in timer1.tick add this code:
timer1.Stop() 'Stop the timer so that its not ran again and again
Button2.Hide() 'Hide the second button
MsgBox("You was too slow!!") 'Tell the user they missed it, or your code..

VB.NET How would i get contents from a listbox and add them into a textbox one at a time automatically

Okay, long title i know but im in need of some help.
i have not got any code at the moment because i do not know where to start.
here is what i need to do:
i need to move the first line of text from a listbox to the textbox
then wait a few seconds and move to the second line of text, then wait a few seconds and move to the third, so on and so fourth.
its for a program i have in mind that i want to work on but am still stuck on this one part.
Please help me, been stuck for about 4 hours.
Try this code:
For Each objItem As Object In Me.ListBox1.Items
Me.TextBox1.Text = objItem.ToString
Me.TextBox1.Refresh()
Threading.Thread.Sleep(2000) 'wait 2000 milliseconds = 2 seconds
Next objItem

VB time input, a better way to do it?

Working on a handy program for my boss at work as a summer project in between semesters both to make life easier for her, and to practice and improve my skills. Intent is to allow her to quickly and easily calculate the hours and minutes the person worked. The form itself has a series of text boxes for the Clock in and Clock out time for each day that week. Currently it attempts to convert the txtbox text into a Date variable, then .Subtract()'s the start from the end and stores it in a rolling total variable which is displayed at the bottom of the form. I can't help but think there is a better way of going about doing this, and I'm absolutely certain that having the below block of code 21 times (7 days, 3 shifts) is inefficient.
Dim StartTime As Date
Dim EndTime As Date
Dim Worked As System.TimeSpan
Dim WorkedTotal As System.TimeSpan
If chkFirst.Checked = True Then
StartTime = CDate(txtMonStart.Text)
EndTime = CDate(txtMonEnd.Text)
EndTime = EndTime.AddHours(12)
Worked = EndTime.Subtract(StartTime)
lblMonWork.Text = Worked.ToString()
WorkedTotal += Worked
Currently it works, mostly. The user has to enter the ":" in the time input, and if the total exceeds 24 hours, it displays a day column (40 hour 12 min work week displays as 1.16:12). I'd like to eliminate both of these unplanned features and allow for my input validation to take place when the focus changes to another box. A changing bgcolor would indicate an invalid input.
Any bright ideas?
Instead of using TextBox for the time input, use DateTimePicker, just change the Format property to Time.
Handle the Validating event of the DateTimePicker and if it's invalid just set e.Cancel = False, that way they can't save changes unless it's valid. Or if you want them to be able to leave the DateTimePicker and just change the colour, just handle the ValueChanged event instead.
Regarding your code sample, I haven't really looked at the logic of it, but instead of having the same code 21 times, just move the code into a separate function and then call that function with the start and end times as parameters and it can return the workedtime as it's return value.
I'm not sure what your UI looks like but if you're repeating the start time and end time input control multiple times as well it might be worth looking at creating your own usercontrol that can contain one each of the start and end time controls, and then you could have the validation be inside that user control so you don't have to have lots of event handlers etc.