Click here to Skip to main content
15,889,116 members
Articles / Programming Languages / Visual Basic

How to Get Media Files Properties in VB.NET

Rate me:
Please Sign up or sign in to vote.
4.17/5 (5 votes)
28 Sep 2013CPOL6 min read 42.9K   5K   7   1
Getting media files properties beyond FileInfo

Image 1

Introduction

You may need some media files properties not provided by File or FileInfo framework classes. As far as I know, .NET Framework does not have classes doing this. Hopefully, there is a remedy available from SourceForge. It is Mediainfo.dll. The file goes with a standalone program to display information with more or less details in several ways. Or, you can use a third party program known as MeditaTab. This program adds a new tab in Windows Explorer's Property Dialog.

But, there is a major drawback with mediainfo DLL for BASIC programmers. It is written in C++. Hopefully, rescue goes from another developer: Tony George. It is a .NET wrapper for MediaInfo.dll and his name is MediaInfoNET.dll.

Background

Using Visual Studio's Object browser and debugger and trial and error, it appears that MediaInfoNet.dll exposes data from MediaInfo.dll by means of six streams: Audio, Video, Image, Text, Menu and Chapter. Each one of these streams exposes nearly the same data from the others completed by his own set of specific properties. When two streams are of the same nature, like two audio channels are there; the two streams are presented individually.

Using the Code

The code itself is relatively simple and commented. But there are some things that might be of some concern to you.

Language and Localization

I am a French-speaking person. So I began writing this program in French, in a French version of Visual Studio, with French variable names, and so one. It was almost finished when I thought it could be useful to publish an article in CodeProject about it. But, I did not want to change all variable names to English ones. So, I added comments in English, including translation for some variable names. I also localized program in English. I think these comments will be a good help to readers. So, I consider this as a good reason to comment code, despite gurus who say otherwise.

You will notice that I added a French Form1 and a French resource file. It was not necessary because application's default settings are equally in French. But you can get your application easily in your own language. This is particularly true for all readers speaking languages other than French or English. You need only to modify default Form1 and default resource file to your own language.

Before going to localization process itself; here are actual resource files used in this application.

Application Culture Application Language Resource Files Purpose
Default (Par défaut) French (Français) Form1.resx, Ressources.resx Used when there is no specific language (e.g. fr-CA, fr-BE, en-CA, en-US) or neutral language (e.g. fr, en) Resource file.
French (Français) French Form1.FR.resx, Ressources.FR.resx Used when there is no specific French language (e.g. fr-CA, fr-BE, fr-FR) Resource file. It is a neutral French Language
English (Anglais) English Form1.EN.resx, Ressources.EN.resx Used when there is no specific English language (e.g. en-CA, en-US, en-GB) Resource file. It is a neutral English Language
Table 1 - Languages and corresponding resources files.

Now, it is time to localize the application. It requires two steps:

  1. Localize the Form(s)
  2. Localize other elements like Instructions to user and output texts

Localization Process

Each new form in your project is a Default (Par défaut) form, as in Figure 1.

Image 2

Figure 1 - View showing Default language form

As already mentioned, if you want your own language as default language, replace French texts as each control's text property value with equivalent term in your own language. You can use Table 2 as a guide, if needed. In this case, you don't have to modify Language property of your form. Let it to Default (Par défaut), as in Figure 2. VB.NET will take care of the resource file.

The first step in localization of a form is modify the Localizable property from False to True. So we may now begin translation of controls text property value.

Image 3

Figure 2 - Localizable property set to True

Let us make the English version of Form1.

  1. Change language form Default (Par défaut) to English (Anglais). (In fact, it would be the same process for any language you could select.)

    Image 4

    Figure 3 - Language property set to English
  2. Translate controls text property to English (or other language, if you want). I used terms I thought generally used as English equivalent for my initial French texts, but you may actually use something else, if you prefer.

    So, here are the French terms I used on the form and their English translation:

    French English
    Propriétés de fichiers multimédias Media Files Properties
    Conserver les données existantes Keep Existing Data
    Même fichier Keep Existing File
    Fichier File
    Chercher Scan Drive
    Propriétés Properties
    Aperçu Print Preview
    Mise en page Page Setup
    Imprimer Print
    Quitter Quit
    Table 2 - French terms with their English equivalents.
  3. It is now time to proceed with the application Resource File First, let us see an extract from the default resource file.

    Image 5

    Figure 4 - French Language Resources

    and now this is an extract of the English version of the above.

    Image 6

    Figure 5 - English Language Resources

    You will notice that resources names (Noms) are names of properties provided by MediaInfoNet.dll. These names are used to recall needed text.

    Open default Resource File (Resources.resx), change the values (Valeurs) to English terms (or any other language you may want). If you want a default file in your own language, you save file with its own name (Resources.resx). If it is a localized language, you save it with a new name. This name must be like Resources.xx.YY.resx or Resources.xx.resx. xx represents neutral culture like fr for French, en for English and so one. YY represents a specific country, like CA for Canada, FR for France, GB for Great-Britain, US for United-States, and so one. Both YY and xx must comply with VB standards.

  4. If you want to view the result, you will need to change your application language, unless you just changed default French to your own language. The earliest moment is the best. Personally, I do this in the startup event procedure.
    VB.NET
    Private Sub MyApplication_Startup(sender As Object, _
    e As ApplicationServices.StartupEventArgs) Handles Me.Startup
                My.Application.ChangeCulture("en")
                My.Application.ChangeUICulture("en")
            End Sub
    ...
  5. Launch your application and look! Your form is now in English:

    Image 7

    Figure 6 - English Version of the form

IMPORTANT

This application is a small one. So there is no real problem to store text strings in the main resource file. But larger applications could probably require use of satellite assemblies for localization.

External Files

You will need five other files not provided by .NET Framework.

  1. MediaInfo.dll: This file is needed to get data from media files. It must be in the same folder as MediaInfoNet.dll. You cannot establish reference to it.
  2. MediaInfoNet.dll: This file exposes date from MediaInfo.dll to your program. You must establish reference to it.
  3. RichTextBoxImprimable.dll, literally PrintableRichTextBox: A RichTextBox which allows printing formatted text and graphics the easy way. Code and details comes from Microsoft. You must establish reference with it.
  4. RichTextBoxImprimable.xml and RichTextBoxImprimable.pdb: Two files that go with RichTextBoxImprimable.dll.

Image 8

Figure 7 - Other files you need in your Bin\Debug folder or in your Bin\Release folder

Points of Interest

This is the first article that I submitted to CodeProject. I wanted something easy to understand. I hope it is just right and not too simple.

Avast Anti Virus did not like my second method and systematically found a virus there. So, it is possible you get the same problem. I changed to a different AV software. This one does nothing. I swear, I did not put any virus there.

History

  • September 26th 2013: Original article

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionIncorrect names! Pin
NeoSvet29-Sep-20 19:59
NeoSvet29-Sep-20 19:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.