I would like to modify BasicPlayback media foundation sample in order to be able to open MPEG2 files.
I know that native MF does not support MPEG2 format.But it is possible to create custom media type of MPEG2.
Could you provide me a sample code how should I do that
Thank you

Creating custom MPEG2 media type
TechedRonan
So if you wanted MF to be able to play back MPEG2 files, you would first need to write a Media Source for MPEG2, since Media Foundation doesn't natively provide one. I'm sure you've noticed the wavsource sample in the SDK. You would also need to write decoder(s) as MFT(s), for which the MFT_Grayscale sample might be useful.
You're correct that this MPEG2 Media Source would need to provide mediatypes to describe its streams. It's definitely valid to do MFCreateMediaType() and then set the various MF_MT_XXX attributes that are relevant. If it's easier, though, you might want to make use of MFCreateMediaTypeFromRepresentation, which gives you the option of starting with an AM_MEDIA_TYPE representation.