Welcome to Omgili,
Omgili ( Oh My God I Love It ;) is a search engine for discussions. With Omgili you can find answers and solutions, debates, discussions, personal experiences, opinions and more... To learn more about Omgili click here.
This is a complete preview of the discussion as it was indexed by Omgili crawlers. Use this preview if the original discussion is unavailable.
Click here to view the original discussion.
 |
|
 |
|
catch Media Player Error - VB.NET
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.
[code
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
[/code]
|
|
 |
|
 |
 |
|
 |
|
Catch the media player error
Help with Code Tags VB.NET Syntax ( Toggle Plain Text ) ' 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
' 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 Teme64 @ Windows Developer Blog
|
|
 |
|
 |
 |
|
 |
|
Sir its not working..
Help with Code Tags ( Toggle Plain Text ) 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
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 .
Teme64 @ Windows Developer Blog
|
|
 |
|
 |
 |
|
 |
|
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.
Help with Code Tags VB.NET Syntax ( Toggle Plain Text ) 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
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 Teme64 @ Windows Developer Blog
|
|
 |
|
 |
 |
|
 |
|
Y u r right i cannot assign resource image to URL...Oops i was wrong...
Help with Code Tags ( Toggle Plain Text ) 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
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,
Help with Code Tags ( Toggle Plain Text ) file you ware attempting to play has an extension .txt that does not match the file format.
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 Last edited by sonia sardana : 9 Hours Ago at 3:13 am .
|
|
 |
|
 |
|
|
|