When I want the video to be maximize: I get this error:
Unable to cast COM object of type 'System.__ComObject' to interface type 'VisioForge.Shared.MediaFoundation.EVR.IMFVideoMixerControl2'.
This operation failed because the QueryInterface call on the COM component for the interface with IID '{8459616D-966E-4930-B658-54FA7E5A16D3}'
failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)). "
The piece of code that causes an error :
private async void button2_Click(object sender, EventArgs e)
{
// Stop the current playback
mediaPlayer1.Stop();
// Open a file dialog for selecting the encrypted file
OpenFileDialog openFileDialog = new OpenFileDialog
{
Filter = "Encrypted Files (*.Enc)|*.Enc",
Title = "Select Encrypted File"
};
// If the user selects an encrypted file
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string encryptedFilePath = openFileDialog.FileName;
// Read the encrypted file into a byte array
byte[] encryptedBytes = File.ReadAllBytes(encryptedFilePath);
// Use MemoryStream to read the encrypted data
using (MemoryStream inputStream = new MemoryStream(encryptedBytes))
// Use Aes for decryption
using (Aes aesAlg = Aes.Create())
{
byte[] iv = new byte[16];
inputStream.Read(iv, 0, iv.Length);
// Set the decryption key and initialization vector
aesAlg.Key = encryptionKey;
aesAlg.IV = iv;
// Use MemoryStream to write the decrypted output
using (MemoryStream decryptedStream = new MemoryStream())
// Use CryptoStream for decryption
using (CryptoStream cryptoStream = new CryptoStream(inputStream, aesAlg.CreateDecryptor(), CryptoStreamMode.Read))
{
// Use Task.Run to perform potentially blocking operations on a separate thread
await Task.Run(() =>
{
// Copy decrypted data from CryptoStream to MemoryStream
cryptoStream.CopyTo(decryptedStream);
// Reset the position to the beginning of the stream
decryptedStream.Position = 0;
// Create a ManagedIStream from the decrypted memory stream
ManagedIStream stream = new ManagedIStream(decryptedStream);
// Set the MediaPlayer source to the memory stream
mediaPlayer1.Source_Mode = VFMediaPlayerSource.Memory_DS;
mediaPlayer1.Source_Stream = stream;
mediaPlayer1.Source_Stream_Size = decryptedStream.Length;
mediaPlayer1.Source_Stream_VideoPresent = true;
mediaPlayer1.Source_Stream_AudioPresent = true;
mediaPlayer1.Audio_OutputDevice = "Default DirectSound Device";
// Choose video renderer based on availability
if (VideoCapture.Filter_Supported_EVR())
{
mediaPlayer1.Video_Renderer.Video_Renderer = VFVideoRenderer.EVR;
}
else if (VideoCapture.Filter_Supported_VMR9())
{
mediaPlayer1.Video_Renderer.Video_Renderer = VFVideoRenderer.VMR9;
}
else
{
mediaPlayer1.Video_Renderer.Video_Renderer = VFVideoRenderer.VideoRenderer;
}
// Reset the event before starting playback
playbackFinishedEvent.Reset();
// Subscribe to playback events
mediaPlayer1.OnStop += MediaPlayer1_OnStop;
mediaPlayer1.OnError += MediaPlayer1_OnError;
// Start playback
mediaPlayer1.Play();
// Block the execution until playback is finished or a timeout occurs
playbackFinishedEvent.WaitOne(TimeSpan.FromMinutes(5)); // Adjust the timeout as needed
});
}
}
}
}