0

I'm trying to get a number of frames from video using windows media player control. It was placed on Panel control.

Public Class Form1
    Private b As New System.Drawing.Bitmap(160, 120)
    Private rct As New Rectangle(0, 0, 160, 120)
    Private pb As PictureBox

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        wm.URL = TextBox1.Text
        wm.Ctlcontrols.play()
    End Sub

    Private Sub wm_OpenStateChange(sender As Object, e As AxWMPLib._WMPOCXEvents_OpenStateChangeEvent) Handles wm.OpenStateChange
        If e.newState = 13 And wm.playState = 3 Then
            Dim g As Graphics = Graphics.FromImage(b)
            g.CopyFromScreen(PointToScreen(Panel1.Location), New Drawing.Point(0, 0), b.Size, CopyPixelOperation.SourceCopy)
            pb = New PictureBox With {.Width = 160, .Height = 120, .Image = b}
            FlowLayoutPanel1.Controls.Add(pb)
            Try
                While True
                    wm.Ctlcontrols.currentPosition += 20
                    Application.DoEvents()
                    If wm.Ctlcontrols.currentPosition > wm.currentMedia.duration - 20 Then
                        Exit Sub
                    End If
                    b = New Bitmap(160, 120)
                    g = Graphics.FromImage(b)
                    g.CopyFromScreen(PointToScreen(Panel1.Location), New Drawing.Point(0, 0), b.Size, CopyPixelOperation.SourceCopy)
                    pb = New PictureBox With {.Width = 160, .Height = 120, .Image = b}
                    FlowLayoutPanel1.Controls.Add(pb)
                End While
            Catch ex As Exception
            End Try
        End If
    End Sub
End Class

As a result I want to get a number of frames in FlowLayoutPanel Control. But there are some 'Black Boxes' (repeated first frame). Any ideas?.. How can I make WMP to Update it's position and layout? My imagine is over.

  • what are the `newstate` and `playstate` states you are testing (you used literals making it hard to decipher). A good deal depends on the media (codec, format, video bit rate). When you set the position, it can take a while for the underlying player to catch up (and you are not helping with DoEvents). The WMP ready state will change as a result, but you are not checking that - the code assumes it is instantaneous. You might get better results, setting the position then trying to scrape the screen in a timer event. – Ňɏssa Pøngjǣrdenlarp Feb 17 '14 at 14:00
  • My IDE (vs2013) doesn't offer any literals for WMP states. That is why I used enumerator found here [link](http://msdn.microsoft.com/en-us/library/windows/desktop/dd564878(v=vs.85).aspx)[link]. Thank you for explanation!=) – Public Escobar Feb 17 '14 at 15:00
  • By the way, here is link [http://msdn.microsoft.com/en-us/library/windows/desktop/dd564878(v=vs.85).aspx]. Thank you for explanation!=) – Public Escobar Feb 17 '14 at 15:16
  • Whenever you change the position or playstate AxWMP goes thru a blizzard of state changes. You need to check that it is ready before scraping. You might also be missing a reference to a Lib to get all the Type values, VS/NET should at least be able to provide info for the event arg values. – Ňɏssa Pøngjǣrdenlarp Feb 17 '14 at 15:21

0 Answers0