|
|
#1 |
|
Hyperactive Member
Join Date: Apr 08
Posts: 348
![]() |
catch Media Player Error
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] |
|
|
|
|
|
#2 |
|
.NUT
Join Date: May 05
Location: Sydney, Australia
Posts: 54,913
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: catch Media Player Error
For a start, all your Trim calls are pointless. You know for a fact that none of the values you've defined has leading or trailing spaces so why do you need to Trim them? The file extensions are in the same boat. If a file extension has leading or trailing spaces then it's not a valid file extension.
Also, your code is way longer than it needs to be. You don't need to identify what a file extension is, just whether it's valid or not. As such you can just put all the extensions in an array and then use a single line to check whether the array contains the current extension. As for the question, you're already handling exceptions so catch the appropriate type of exception that is thrown when an invalid file type is used and then do whatever's appropriate.
__________________
![]() 2007, 2008, 2009, 2010 Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs MSDN "How Do I?" Videos: VB | C# VBForums Database Development FAQ My CodeBank Submissions: VB | C# (ForumAccount has translated some of my VB submissions to C#) My Blog: Defining and Raising Custom Events | Manipulating GDI+ Drawings | Using Parameters in ADO.NET |
|
|
|
|
|
#3 |
|
Hyperactive Member
Join Date: Apr 08
Posts: 348
![]() |
Re: catch Media Player Error
But sir i have to get the extension of the file na
sExtension = IO.Path.GetExtension("sFileName") And then check that extension in array,But i dont want using extension method,Is there any other way Round...... I know my code is longer way,But sir using if statements will take less than searching elements in array.Isn't so?Or I m wrong??? Last edited by sonia.sardana; Jul 13th, 2009 at 02:53 AM. |
|
|
|
|
|
#4 |
|
Hyperactive Member
Join Date: Apr 08
Posts: 348
![]() |
Re: catch Media Player Error
Since i get no anwer, I follow jmcilhinney suggestion...
Code:
Public Class Form2
Public ExtensionsArrayList As New ArrayList
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call LoadExtensionsToArrayList()
End Sub
Private Sub LoadExtensionsToArrayList()
Try
ExtensionsArrayList.Add(Ext_bmp)
ExtensionsArrayList.Add(Ext_gif)
ExtensionsArrayList.Add(Ext_jpeg)
ExtensionsArrayList.Add(Ext_jpg)
ExtensionsArrayList.Add(Ext_wma)
ExtensionsArrayList.Add(sExe_asx)
ExtensionsArrayList.Add(sExe_wax)
ExtensionsArrayList.Add(sExe_m3u)
ExtensionsArrayList.Add(sExe_wpl)
ExtensionsArrayList.Add(sExe_wvx)
ExtensionsArrayList.Add(sExe_wmx)
ExtensionsArrayList.Add(sExe_searchms)
ExtensionsArrayList.Add(sExe_dvrms)
ExtensionsArrayList.Add(sExe_mid)
ExtensionsArrayList.Add(sExe_rmi)
ExtensionsArrayList.Add(sExe_midi)
ExtensionsArrayList.Add(sExe_mpeg)
ExtensionsArrayList.Add(sExe_mpg)
ExtensionsArrayList.Add(sExe_m1v)
ExtensionsArrayList.Add(sExe_m2v)
ExtensionsArrayList.Add(sExe_mod)
ExtensionsArrayList.Add(sExe_mp2)
ExtensionsArrayList.Add(sExe_mpa)
ExtensionsArrayList.Add(sExe_mpe)
ExtensionsArrayList.Add(sExe_ifo)
ExtensionsArrayList.Add(sExe_vob)
ExtensionsArrayList.Add(sExe_wav)
ExtensionsArrayList.Add(sExe_snd)
ExtensionsArrayList.Add(sExe_au)
ExtensionsArrayList.Add(sExe_aif)
ExtensionsArrayList.Add(sExe_aifc)
ExtensionsArrayList.Add(sExe_aiff)
ExtensionsArrayList.Add(sExe_wmv)
ExtensionsArrayList.Add(sExe_wmd)
ExtensionsArrayList.Add(sExe_avi)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sExtension As String
sExtension = IO.Path.GetExtension("sFileName")
If CheckWhetherExtValid(sExtension) Then
WindowsMediaPlayer.URL = "sFileName"
Else
WindowsMediaPlayer.URL = FOLDER_IMAGES & "\PlayListImage.jpg"
End If
End Sub
Private Function CheckWhetherExtValid(ByVal sExtension As String) As Boolean
Try
Dim lCount As Integer
CheckWhetherExtValid = False
For lCount = 0 To ExtensionsArrayList.Count - 1
If Trim(ExtensionsArrayList.Item(lCount).ToString) = Trim(sExtension) Then
CheckWhetherExtValid = True
Exit For
End If
Application.DoEvents()
Next
Catch ex As Exception
MsgBox(ex.Message)
CheckWhetherExtValid = False
End Try
End Function
End Class
|
|
|
|
|
|
#5 | |
|
.NUT
Join Date: May 05
Location: Sydney, Australia
Posts: 54,913
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: catch Media Player Error
I already answered your question. You just didn't read it:
Quote:
__________________
![]() 2007, 2008, 2009, 2010 Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs MSDN "How Do I?" Videos: VB | C# VBForums Database Development FAQ My CodeBank Submissions: VB | C# (ForumAccount has translated some of my VB submissions to C#) My Blog: Defining and Raising Custom Events | Manipulating GDI+ Drawings | Using Parameters in ADO.NET |
|
|
|
|
|
|
#6 |
|
Hyperactive Member
Join Date: Apr 08
Posts: 348
![]() |
Re: catch Media Player Error
Sir if file is invalid,no exception is thrown,control doesn't go in Catch block....I want that control goes to catch block..so i set the default image there & there is no need to check extensions....
|
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|