By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,779 Members | 1,291 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,779 IT Pros & Developers. It's quick & easy.

play multifiles video in media player

P: 1
How to play video one by one, if i play (press button) only the end of file is playing. If i use playlist its work, my code :

Expand|Select|Wrap|Line Numbers
  1. Dim path As String = System.AppDomain.CurrentDomain.BaseDirectory() & "Video\" 
  2.  AxWindowsMediaPlayer1.uiMode = "none"
  3.         AxWindowsMediaPlayer1.settings.setMode("loop", True)
  4.  
  5. If Not Directory.Exists(path) Then
  6.  Else
  7. Dim dInfo As DirectoryInfo = New DirectoryInfo(path)
  8. For Each File As FileInfo In dInfo.GetFiles("*.mp4")
  9.                 '' ''AxWindowsMediaPlayer1.newMedia(path & File.Name)
  10.    ''Playlist.appendItem(AxWindowsMediaPlayer1.newMedia(path & File.Name))
  11.  AxWindowsMediaPlayer1.URL = path & File.Name
  12.                 ''Application.DoEvents()
  13.  
  14.             Next
  15.             ' '' ''AxWindowsMediaPlayer1.Ctlcontrols.play()
  16.         End If
Aug 29 '14 #1
Share this Question
Share on Google+
1 Reply


IronRazer
P: 82
Hi,
If you don`t use a Playlist then you will need to use the AxWindowsMediaPlayer1.PlayStateChange event to detect when the media ends so you can start the next video.

Being you can`t start the next video from within the PlayStateChange event you will need to use a Timer with a small delay like 200 milliseconds and in the Tick event you start the next video.

I take it you want a loop effect so in this example i check if it is the last video that ended and if it is then i start the first video again.

You can test the code in a new Form project with 1 Button and 1 AxWindowsMediaPlayer added to the form. You will also need a folder in the Debug folder named "Videos" with your video files in it.

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Private WithEvents Tmr As New Timer With {.Interval = 200}
  3.     Private VideoFiles As New List(Of String)
  4.     Private VideoPath As String = IO.Path.Combine(Application.StartupPath, "Videos")
  5.     Private PlayingIndex As Integer = 0
  6.  
  7.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  8.         For Each fn As String In IO.Directory.GetFiles(VideoPath, "*.mp4")
  9.             VideoFiles.Add(fn) 'add all the video file names to the List
  10.         Next
  11.     End Sub
  12.  
  13.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  14.         PlayingIndex = 0 'if you want it to start at the first video every timr this button is clicked
  15.         AxWindowsMediaPlayer1.URL = VideoFiles(PlayingIndex)
  16.     End Sub
  17.  
  18.     Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
  19.         If AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsMediaEnded Then
  20.             Tmr.Start()
  21.         End If
  22.     End Sub
  23.  
  24.     Private Sub Tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Tmr.Tick
  25.         Tmr.Stop()
  26.         PlayingIndex += 1
  27.         If PlayingIndex > VideoFiles.Count - 1 Then PlayingIndex = 0 'if its the last video then start at the first video again
  28.         AxWindowsMediaPlayer1.URL = VideoFiles(PlayingIndex)
  29.         AxWindowsMediaPlayer1.Ctlcontrols.play()
  30.     End Sub
  31. End Class
  32.  
Aug 30 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.