I am creating a c# winform application that download huge video files and playback them at the same time then ask user 'Do you want to Save the video?'
var fileStream = new FileStream(@"c:\c.mp4", FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
var writer = new BinaryWriter(fileStream);
totalBytesRead = 0;
double divide;
do
{
bytesRead = webStream.Read(buffer, 0, 4096);
if (bytesRead != 0)
{
writer.Write(buffer, 0, (int)bytesRead);
writer.Flush();
totalBytesRead += bytesRead;
}
} while (bytesRead != 0);
and
axWindowsMediaPlayer1.URL = "C:\\c.mp4";
With a high download speed there is no problem. But if download speed be less than play speed problem will begin: The media player will reach the Fake end of file and will stop and playing time will be zero and player will show a black screen. The only way that i consider is to Pause the player just before stop (Do you know a better way?), but i can't access last frame time. i tried this with no success:
axWindowsMediaPlayer1.PlayStateChange += axWindowsMediaPlayer1_PlayStateChange;
void axWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
if (e.newState == 8)//Meida ended
{
axWindowsMediaPlayer1.Ctlcontrols.pause();
HandleUnWantedStop();
My_Goal_Position= axWindowsMediaPlayer1.Ctlcontrols.currentPosition;
}
}
Thanks in advance.