In general case, there is no a way.
But this is not a problem: it won't play, that's all. Wouldn't that be a good validation? Well, get ready to process all exceptions, of course. Take any other player; or, why player? any good software having such dialog. Nothing will validate file content, for a good reason: even if the file has some signature, even if you know it and validate it, who will guarantee that it has no garbage?
By the way, media files are way more complex than that: the file have certain container format. And don't think that *.MP4 is used only by one container — there is a good number of different containers based on MPEG, and not only. Now, a container can combine one, two or more different compression algorithms in it, which all have their own signatures. This machinery is quite complex. That said, making it possible to play only one container of file type will have very little value.
[EDIT]
Please see all my comments in this discussion. If you really want to bite a bullet (which I still cannot seriously advise), you can try to use… some other available software. This could be ffMpeg or underlying libavcodec:
http://en.wikipedia.org/wiki/Ffmpeg[
^],
http://ffmpeg.org/[
^],
http://en.wikipedia.org/wiki/Libavcodec[
^],
http://libav.org/[
^].
First of all, run one already built utility to see how it works with your files. Its name is "ffprobe.EXE", and it is a part of ffmpeg; and the analogous application doing exactly the same is bundled with libavcodec. The quality of these open-source multiplatform library and utilities is very high; this is the main thing I use for all my media needs, and it
almost never betrays me, getting sufficient access to most of the most rare or exotic formats and codecs.
It parses your media file and gives you information on it. It's really fast and would be enough for consistency.
You can use it as a library, but you should understand that it is written in C, so you would need to use P/Invoke. As a cheap alternative, you could simply execute the utility using
System.Diagnostics.Process.Start
, redirect its output and analyze the resulting output text. I hope you know how to do all that, it's simple enough.
Now, the problem is: ffMpeg (libav) is not relied on the codecs installed in the system, in contrast, it carries everything in the product itself. That said, the format/codec
repertoire of ffMpeg (libav) could happen to be much wider than that of your codec set, so what might happen is: ffMpeg (libav) can cope with some file, but your player fails to play it. I observed it many times, when I compare "ffProbe.exe" (or "ffPlay.exe") with Windows Visual Studio (which is actually ridiculously weak in supported media features).
But this is better than nothing. Besides, you can analyze the output of "ffProbe.exe" and reject some formats/codecs which you know to be not supported by your player.
Alternatively, you can opt for a different player. VLC, for example, is based on ffMpeg and cab be embedded in your application as a component; and some .NET wrappers are also available; please see my past answers:
Streaming music files in vb.net without WMP[
^],
need help in getting the streaming video from an other computer in C#[
^].
—SA