Web Worm
Web Worm

Reputation: 2066

controlling for each loop in visual basic

i have the following code....

For Each dgvRow In bout_grid.Rows
            vfile = dgvRow.Cells("FileName").Value
            video.FileName = "D:\bee\" + vfile

            vduration = video.Duration
            vposition = video.Position

            If vduration > 0 The
                bplayer_out.URL = "D:\bee\" + vfile
                bplayer_out.Ctlcontrols.play()
            End If

        Next dgvRow

but it plays only one video and than stops but i want that it should play every video in datagridview i.e bout_grid....i have tried

System.Threading.Thread.Sleep = vduration

but it stops every thing how can i solve it

Upvotes: 1

Views: 483

Answers (3)

Hans Passant
Hans Passant

Reputation: 941317

Yes, you can't make this kind of code work in a Windows Forms or WPF app. Windows apps are event driven, you can't program long loops without blocking UI updates.

Windows Media Player generates events when something significant happened. Like the PlayStateChange event. Write an event handler for that event to index to the next item in your list. Note that WMP also supports play lists.

Your ultimate resource for programming WMP in Visual Basic is this MSDN Library topic. Take a look at the provided samples.

Upvotes: 2

Philip Fourie
Philip Fourie

Reputation: 116837

It is very possible that bplayer_out.Ctlcontrols.play() is asynchronous, like with many other sound API's. It is therefore possible that next sound immediately plays while the first one is still busy - you might just hear the first one.

What type is bplayer?

Upvotes: 1

Ando
Ando

Reputation: 11409

What happens after bplayer_out.Ctlcontrols.play() finishes? A dialog pops up? An exception? Both these outcomes would halt the for each loop.

Run it with the debugger and see where the control returns after bplayer_out.Ctlcontrols.play()

Upvotes: 1

Related Questions