VB.NET - DirectX.AudioVideoPlayback gives incorrect frame size? - vb.net

Hey, making a media player and need to know something.
I have a menu which reads file info, but for some reason, when I open a video that I KNOW is 1280x720, the width and height come up as 1292x758.
Edit:
When I open a video which is 640x480, it says it's 656x518
That, and an extra preview box pops up due to:
labFR.Text = "Frame rate: " & Strings.FormatNumber((1 / AudioVideoPlayback.Video.FromFile(labinput.text, True).AverageTimePerFrame), 3)
This needs to be playing so I can get the frame rate, but how to I close it once I have the frame rate?
Working in VB.NET Framework 4.0. (VS2010)
Answers to either of these problems are highly appreciated.

Got it. I have to Dim the Video outside of all the modules with autoplay set to false, then I can grab all the properties from the video without constantly opening the video on several threads over and over.
Dim openerfile As Video
Public Sub btnInputBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInputBrowse.Click
openerfile = Video.FromFile(labinputfile.Text, False) 'labinputfile is a textbox which is given the path of an openfiledialog
End Sub
Then all I have to do is use "openerfile" and its properties for what I wish.

Related

How to tell when WMP is done playing a video?

BACKGROUND:
I have a project where I am using a touchscreen for what video to play on the TV next to it. Both are connected to the same computer and the a VB app runs that then opens a video in window media player on the TV. We are opening video files by Process.start and have a string with the files location.
ISSUE:
I need to play a video twice when selected and then go back to a main video after playing the initial video twice. How can I determine when the video has finished playing? Videos are all the same file type but simply using the file size to try to determine length does not work. Two videos of the same length have a noticeable difference in file size.
So either I need to know what the length of the video is or when the video is finished.
Thanks in advance!
Private Sub Button17_Click(sender As Object, e As EventArgs) Handles Button17.Click, Button18.Click, Button19.Click, Button20.Click, Button21.Click, Button22.Click, Button23.Click, Button24.Click, Button25.Click, Button26.Click, Button27.Click, Button28.Click, Button29.Click, Button30.Click, Button31.Click, Button32.Click
Dim bNum As Integer
Dim temp As String
Try
MR = My.Computer.FileSystem.GetFiles("S:\A - All Other Sales Folders\Robots - All Files\YouTube Videos\Videos without Intro's\Material Removal")
temp = Strings.Mid(sender.Name, 7)
bNum = CInt(temp)
Process.Start(MR(bNum - 17))
wait(600) 'just have it go for 10 minutes unless they want to change videos, not the best solution here for a few reasons
Process.Start("S:\A - All Other Sales Folders\Robots - All Files\YouTube Videos\Videos without Intro's\RobotClips_KUKA Presentation_05-13-09.wmv") 'video to play on loop
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Run VB.net app on second monitor

I'm a newbie at coding but I have done simple application for the plan I work for!!
I recently encounter a "little" issue with one of my application!
I build a Windows Form application, with multiple form, that run on a dual screen CNC. The CNC program have to run on the primary screen at a higher resolution. My application run on the second screen who is a touch screen at 1024;768.
The problem itself is if I run the code with the debug data everything run as I want, open the application on second screen and all the next form open on this screen. If I install it with the released data, all form open on the primary monitor, even if I drag them on second screen. After I closed them, they return on the primary.
Is there a way I can put a code line at the beginning of each form who make all form open on the secondary screen.
When the setup will work correctly I'll lock the screen setup just to be sure nobody will mess with the settings.
Please be gentle with me I don't have any formation on how to code. I learn from myself with reading on the web!!
Thanks all!!
Something like this should position the window at offset 100, 100 on the first non-primary screen found. You can adjust the location and/or size to suit your needs.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim secondaryMonitor = Screen.AllScreens.FirstOrDefault(Function(x) Not x.Primary)
If secondaryMonitor IsNot Nothing Then
Dim newLocation = secondaryMonitor.Bounds.Location
newLocation.Offset(100, 100) ' adjust as needed
Me.Location = newLocation
' Also see Me.Size and Me.Bounds
End If
End Sub
This worked for me:
Private Sub _MainForm_Move(sender As Object, e As EventArgs) Handles MyBase.Move
' preserve me.Location.x and me.Location.y here.
End Sub
Then, at program boot, restore: me.Location.x and me.Location.y

Windows CE Generate Log on Barcode Scan

At the moment, I am currently faced with a small project as to update a current bar-code system so that it will store a log file on scan. However, I'm not provided with any source code for the current system. So I was thinking maybe I can develop a small .exe to run and it's job is just to store the ID scanned as well as the current timestamp to a text file named log.txt.
Here's all I'm provided with:
A small touchscreen device running on windows CE with a built-in bar-code
scanner (imager) and few other ports including a USB port.
A memory stick containing the object codes (exe, dll, pdb, bat and
xml) and other multimedia files.
SDK CD containing an SDK platform installer (.msi) requiring VS2005
SP1 to be installed.
Now I'm just confused on how to get the job done. I've been spending the past 3 days researching about this. One of my Google findings suggest that the bar-code scanner works just like a keyboard input? Hence, I made a simple VB6 application with a textbox to store the contents of it and reset the textbox at the same time when a 10-digit ID is inputted. The application is not executable in the device though (I found out that VB6 exe is not executable in winCE, sadly).
Furthermore, I tried to open MS WordPad in the device and attempted to scan the bar-code. Nothing is copied to the WordPad though. I thought bar-code scanner works identically like a keyboard input? My mistake? Any clarification will be highly appreciated.
I'm actually new to bar-code and winCE development and if it helps, I'm familiar with the following languages (in-order): C#, VB6, VB.Net, C, Java. Any suggestion on the quickest way to get the job done? I believe it's not a hectic job, but I'm stuck on where to begin.
Just tell me in case any further clarification is needed. Thanks in advance!
Edit#1:
Here's what I tried so far (Assuming Barcode Scan works just like keyboard input):
(Using VB.Net for Windows CE 5.0 Device under VS2005)
Private Sub barcodeTB_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles barcodeTB.TextChanged
If (Len(barcodeTB.Text) = 10) Then 'If 10 digits ID have been scanned..
Using writer As IO.StreamWriter = New IO.StreamWriter("log.txt", True)
writer.WriteLine(barcodeTB.Text & " " & DateTime.Now)
End Using
barcodeTB.Text = "" 'reset TextBox
End If
End Sub
It works just fine when I input the code manually. But nil when I tried to scan my bar-code.
Edit#2:
There are several PDFs provided in their website: http://www.scantech-id.com/en/support/download.php?pin=42676d021abeff1e479180ffeb4240e5
I'm perfectly sure that the scanner is installed in COM3 port if it helps! Still trying to figure this out.
Edit#3:
So this is my last attempt: To read it directly via the DataReceived from COM3 Port.
I set a timer so that it sends the data transmitted every 1 second if there's any. It works nicely as the textbox only get updated when I scan my bar-code. However, the output is not in a desirable format. What am I doing wrong? See below:
And here's the code:
Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, _
ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) _
Handles SerialPort1.DataReceived
Q.Enqueue(SerialPort1.ReadExisting())
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
SyncLock Q
While Q.Count > 0
receivedTB.Text &= Chr(13) & Chr(10) & Q.Dequeue
End While
End SyncLock
End Sub

Dragging and Dropping in VB.NET

I am preparing a chess program in VB.NET. So what I want to create is a drag and drop event. In drag and drop events, the original image is kept intact and the copy is placed wherever you want to place it.
But what I want to do is, I want to remove the original as soon as the image is being picked. Any idea how can I do that?
My user interface consists of 64 picture boxes arranged in rows of 8. And they all have images of their respective pieces on them.
Please help me.
#Hans is correct; it would be much easier to do this as one PictureBox. If, however, you are stuck on the method you are currently using, change the code in your MouseMove function on the source PictureBox to look like this. It basically copies the image to a variable, and then sets the source image to Nothing. Of course, you will have to handle if the move is not made (setting the source image back to the value of nImage) as well as dealing with disposing of the variable once the move is made.
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If m_MouseIsDown Then
' Initiate dragging and allow either copy or move.
Dim iImage As Image
iImage = PictureBox1.Image
PictureBox1.Image = Nothing
PictureBox1.DoDragDrop(iImage, DragDropEffects.Copy Or _
DragDropEffects.Move)
End If
m_MouseIsDown = False
End Sub

VB.NET WebBrowser disable javascript

Is there a way to disable javascript webbrowser in vb.net?
works for me:
Private Function TrimScript(ByVal htmlDocText As String) As String
While htmlDocText.ToLower().IndexOf("<script type=""text/javascript"">") > -1
Dim s_index As Integer = htmlDocText.ToLower().IndexOf("<script type=""text/javascript"">")
Dim e_index As Integer = htmlDocText.ToLower().IndexOf("</script>")
htmlDocText = htmlDocText.Remove(s_index, e_index - s_index)
End While
Return htmlDocText
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim webClient As New System.Net.WebClient
Dim result As String = webClient.DownloadString(yourUrl)
Dim wb As New WebBrowser
wb.Navigate("")
Do While wb.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
Loop
Dim script As String = TrimScript(result)
wb.DocumentText = script
End Sub
The short answer is: No.
The slightly longer answer is: No, the web-browser control API does not allow disabling standard browser functionality.
No really...but if you getting that annoying error message that pops up saying a script is running then you can turn the property of the webbrowser's suppress-errors "true"
Which popup message do you want to disable? If it's the alert message, try this, obviously resolving the window or frame object to your particular needs, I’ve just assumed top-level document, but if you need an iframe you can access it using window.frames(0). for the first frame and so on... (re the JavaScript part)... here is some code, assuming WB is your webbrowser control...
WB.Document.parentWindow.execScript "window.alert = function () { };", "JScript"
You must run the above code only after the entire page is done loading, i understand this is very difficult to do (and a full-proof version hasn't been published yet) however I have been doing it (full proof) for some time now, and you can gather hints on how to do this accurately if you read some of my previous answers labelled "webbrowser" and "webbrowser-control", but getting back to the question at hand, if you want to cancel the .confirm JavaScript message, just replace window.alert with window.confirm (of course, qualifying your window. object with the correct object to reach the document hierarchy you are working with). You can also disable the .print method with the above technique and the new IE9 .prompt method as well.
If you want to disable JavaScript entirely, you can use the registry to do this, and you must make the registry change before the webbrowser control loads into memory, and every time you change it (on & off) you must reload the webbrowser control out and into memory (or just restart your application).
The registry key is \HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\ - the keyname is 1400 and the value to disable it is 3, and to enable it is 0.
Of course, because there are 5 zones under the Zones key, you need to either change it for the active zone or for all zones to be sure. However, you really don't need to do this if all you want to do si supress js dialog popup messages.
Let me know how you go, and if I can help further.