play multifiles video in media player

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • keannuriefky
    New Member
    • Aug 2014
    • 1

    play multifiles video in media player

    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 :

    Code:
    Dim path As String = System.AppDomain.CurrentDomain.BaseDirectory() & "Video\" 
     AxWindowsMediaPlayer1.uiMode = "none"
            AxWindowsMediaPlayer1.settings.setMode("loop", True)
    
    If Not Directory.Exists(path) Then
     Else
    Dim dInfo As DirectoryInfo = New DirectoryInfo(path)
    For Each File As FileInfo In dInfo.GetFiles("*.mp4")
                    '' ''AxWindowsMediaPlayer1.newMedia(path & File.Name)
       ''Playlist.appendItem(AxWindowsMediaPlayer1.newMedia(path & File.Name))
     AxWindowsMediaPlayer1.URL = path & File.Name
                    ''Application.DoEvents()
    
                Next
                ' '' ''AxWindowsMediaPlayer1.Ctlcontrols.play()
            End If
    Last edited by Rabbit; Aug 30 '14, 09:25 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • IronRazer
    New Member
    • Jan 2013
    • 83

    #2
    Hi,
    If you don`t use a Playlist then you will need to use the AxWindowsMediaP layer1.PlayStat eChange 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 AxWindowsMediaP layer added to the form. You will also need a folder in the Debug folder named "Videos" with your video files in it.

    Code:
    Public Class Form1
        Private WithEvents Tmr As New Timer With {.Interval = 200}
        Private VideoFiles As New List(Of String)
        Private VideoPath As String = IO.Path.Combine(Application.StartupPath, "Videos")
        Private PlayingIndex As Integer = 0
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            For Each fn As String In IO.Directory.GetFiles(VideoPath, "*.mp4")
                VideoFiles.Add(fn) 'add all the video file names to the List
            Next
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            PlayingIndex = 0 'if you want it to start at the first video every timr this button is clicked
            AxWindowsMediaPlayer1.URL = VideoFiles(PlayingIndex)
        End Sub
    
        Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
            If AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsMediaEnded Then
                Tmr.Start()
            End If
        End Sub
    
        Private Sub Tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Tmr.Tick
            Tmr.Stop()
            PlayingIndex += 1
            If PlayingIndex > VideoFiles.Count - 1 Then PlayingIndex = 0 'if its the last video then start at the first video again
            AxWindowsMediaPlayer1.URL = VideoFiles(PlayingIndex)
            AxWindowsMediaPlayer1.Ctlcontrols.play()
        End Sub
    End Class

    Comment

    Working...