I m selecting the folder & playing all the files in the media player, of that folder. As u know folder contains all types of files including text,zip,image & so on.

So I want that when URL that is assigned to Media Player is .txt,then i assign any default image from resources.

I do not want to check extensions-
Currently I m checking the extension of each file before paying but i dont want dat.

Public Class Form1
    Public Ext_bmp As String = ".bmp"
    Public Ext_jpg As String = ".jpg"
    Public Ext_jpeg As String = ".jpeg"
    Public Ext_gif As String = ".gif"
    Public Ext_wma As String = ".wma"
    Public sExe_asx As String = ".asx"
    Public sExe_wax As String = ".wax"
    Public sExe_m3u As String = ".m3u"
    Public sExe_wpl As String = ".wpl"
    Public sExe_wvx As String = ".wvx"
    Public sExe_wmx As String = ".wmx"
    Public sExe_searchms As String = ".search-ms"
    Public sExe_dvrms As String = ".dvr-ms"
    Public sExe_mid As String = ".mid"
    Public sExe_rmi As String = ".rmi"
    Public sExe_midi As String = ".midi"
    Public sExe_mpeg As String = ".mpeg"
    Public sExe_mpg As String = ".mpg"
    Public sExe_m1v As String = ".m1v"
    Public sExe_m2v As String = ".m2v"
    Public sExe_mod As String = ".mod"
    Public sExe_mp2 As String = ".mp2"
    Public sExe_mpa As String = ".mpa"
    Public sExe_mpe As String = ".mpe"
    Public sExe_ifo As String = ".ifo"
    Public sExe_vob As String = ".vob"
    Public sExe_wav As String = ".wav"
    Public sExe_snd As String = ".snd"
    Public sExe_au As String = ".au"
    Public sExe_aif As String = ".aif"
    Public sExe_aifc As String = ".aifc"
    Public sExe_aiff As String = ".aiff"
    Public sExe_wmv As String = ".wmv"
    Public sExe_wmd As String = ".wmd"
    Public sExe_avi As String = ".avi"

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Dim sExtension As String
            sExtension = IO.Path.GetExtension("sFileName")

            If Trim(sExtension) = Trim(Ext_bmp) Or _
                      Trim(sExtension) = Trim(Ext_gif) Or _
                      Trim(sExtension) = Trim(Ext_jpeg) Or _
                      Trim(sExtension) = Trim(Ext_jpg) Or _
                      Trim(sExtension) = Trim(Ext_wma) Or _
                      Trim(sExtension) = Trim(sExe_asx) Or _
                      Trim(sExtension) = Trim(sExe_wax) Or _
                      Trim(sExtension) = Trim(sExe_m3u) Or _
                      Trim(sExtension) = Trim(sExe_wpl) Or _
                      Trim(sExtension) = Trim(sExe_wvx) Or _
                      Trim(sExtension) = Trim(sExe_wmx) Or _
                      Trim(sExtension) = Trim(sExe_searchms) Or _
                      Trim(sExtension) = Trim(sExe_dvrms) Or _
                      Trim(sExtension) = Trim(sExe_mid) Or _
                      Trim(sExtension) = Trim(sExe_rmi) Or _
                      Trim(sExtension) = Trim(sExe_midi) Or _
                      Trim(sExtension) = Trim(sExe_mpeg) Or _
                      Trim(sExtension) = Trim(sExe_mpg) Or _
                      Trim(sExtension) = Trim(sExe_m1v) Or _
                      Trim(sExtension) = Trim(sExe_m2v) Or _
                      Trim(sExtension) = Trim(sExe_mod) Or _
                      Trim(sExtension) = Trim(sExe_mp2) Or _
                      Trim(sExtension) = Trim(sExe_mpa) Or _
                      Trim(sExtension) = Trim(sExe_mpe) Or _
                      Trim(sExtension) = Trim(sExe_ifo) Or _
                      Trim(sExtension) = Trim(sExe_vob) Or _
                      Trim(sExtension) = Trim(sExe_wav) Or _
                      Trim(sExtension) = Trim(sExe_snd) Or _
                      Trim(sExtension) = Trim(sExe_au) Or _
                      Trim(sExtension) = Trim(sExe_aif) Or _
                      Trim(sExtension) = Trim(sExe_aifc) Or _
                      Trim(sExtension) = Trim(sExe_aiff) Or _
                      Trim(sExtension) = Trim(sExe_wmv) Or _
                      Trim(sExtension) = Trim(sExe_wmd) Or _
                      Trim(sExtension) = Trim(sExe_avi) Then
                WindowsMediaPlayer.URL = sFileName
            Else
                WindowsMediaPlayer.URL = My.Resources.PlayListImage
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Catch the media player error

' Try to play a text file
AxWindowsMediaPlayer1.URL = "D:\test.txt"
.
.
Private Sub AxWindowsMediaPlayer1_ErrorEvent(ByVal sender As Object, ByVal e As System.EventArgs) Handles AxWindowsMediaPlayer1.ErrorEvent
  ' Catch player errors
  Dim oErrorItem As WMPLib.IWMPErrorItem

  If CType(sender, AxWMPLib.AxWindowsMediaPlayer).Error.errorCount > 0 Then
    oErrorItem = CType(sender, AxWMPLib.AxWindowsMediaPlayer).Error.Item(0)
    If oErrorItem.errorCode = -1072885353 Then
      MsgBox("Invalid file")
    End If
  End If

End Sub

That error code was returned when the media player couldn't decode the file (text file in this case). I didn't check any documentation or test the code any further, but the same error code may be returned by some other error condition.

HTH

Sir its not working..

Public Class Form2

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AxWindowsMediaPlayer1.URL = "D:\Working\New Text Document.txt"
    End Sub

    Private Sub AxWindowsMediaPlayer1_ErrorEvent(ByVal sender As Object, ByVal e As System.EventArgs) Handles AxWindowsMediaPlayer1.ErrorEvent
        Dim oErrorItem As WMPLib.IWMPErrorItem
        If CType(sender, AxWMPLib.AxWindowsMediaPlayer).Error.errorCount > 0 Then
            oErrorItem = CType(sender, AxWMPLib.AxWindowsMediaPlayer).Error.Item(0)
            If oErrorItem.errorCode = -1072885353 Then
                MsgBox("Invalid file")
            End If
        End If
    End Sub
End Class

its not working

In what way it isn't working? Any error messages? Please be more specific.

Or do you mean it's not working "as is". It wasn't suppose to. You have to modify it slightly for your application. Instead of MsgBox("Invalid file") , write AxWindowsMediaPlayer1.URL = My.Resources.PlayListImage .

By the way. You can't assign Image type to String type like you do in WindowsMediaPlayer.URL = My.Resources.PlayListImage . Url property takes a path to a file. Save your image resource first to some temporary file.

Private m_TempImageFileName As String

Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  ' 
  m_TempImageFileName = My.Computer.FileSystem.GetTempFileName & ".jpg"
  Try
    My.Resources.BlogImage.Save(m_TempImageFileName, System.Drawing.Imaging.ImageFormat.Jpeg)
  Catch ex As Exception
    ' Handle I/O error(s)
  End Try

End Sub

Private Sub AxWindowsMediaPlayer1_ErrorEvent(ByVal sender As Object, ByVal e As System.EventArgs) Handles AxWindowsMediaPlayer1.ErrorEvent
  ' Catch player errors
  Dim oErrorItem As WMPLib.IWMPErrorItem

  If CType(sender, AxWMPLib.AxWindowsMediaPlayer).Error.errorCount > 0 Then
    oErrorItem = CType(sender, AxWMPLib.AxWindowsMediaPlayer).Error.Item(0)
    If oErrorItem.errorCode = -1072885353 Then
      CType(sender, AxWMPLib.AxWindowsMediaPlayer).Error.clearErrorQueue()
      CType(sender, AxWMPLib.AxWindowsMediaPlayer).URL = m_TempImageFileName
    End If
  End If

End Sub

Y u r right i cannot assign resource image to URL...Oops i was wrong...

Public Class Form2

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AxWindowsMediaPlayer1.URL = "D:\Working\New Text Document.txt"

    End Sub

    Private Sub AxWindowsMediaPlayer1_ErrorEvent(ByVal sender As Object, ByVal e As System.EventArgs) Handles AxWindowsMediaPlayer1.ErrorEvent
        Dim oErrorItem As WMPLib.IWMPErrorItem
        If CType(sender, AxWMPLib.AxWindowsMediaPlayer).Error.errorCount > 0 Then
            oErrorItem = CType(sender, AxWMPLib.AxWindowsMediaPlayer).Error.Item(0)
            If oErrorItem.errorCode = -1072885353 Then
                MsgBox("Invalid file")
            End If
        End If

    End Sub
End Class

When the form is loaded,error is there which is thrown by media player,

file you ware attempting to play has an extension .txt that does not match the file format.

Control never goes to WIndows Media error event.....

file you ware attempting to play has an extension .txt that does not match the file format.

Yes, that's not exactly an error. It's more like a warning that media player control can't decode the file. If you press Yes-button, the player will try to play the file and ends up raising the error.

You don't want any user interaction, am I right? I don't know how to suppress that warning and force the player to play the file anyway (I'm sure there's a way to do that).

In your original post you declared each acceptable file extension as a separate string. You could use an array instead, load extension from a text file and loop the extension array to determine (by file's extension) if the control will try to play it. And by the way, the original If...Then...Else...End If will fail with (legal) extensions like .Avi or .AVI. Instead of trimming (it's obsolete, there's no spaces) you should make a not case-sensitive comparison like sExtension.ToUpper = sExe_avi.ToUpper .

ks thx for suggestions....helpfull tips!!!!!!!!! I m still not marking traed as solved,may be i got ans from anybody

This article has been dead for over six months. Start a new discussion instead.