Board index » delphi » Free MediaPlayer component that resizes to fit panel

Free MediaPlayer component that resizes to fit panel

F.i I have a panel 320 x 240 pixels. If I play a 720x480 movie on this I
only get part of the video. How resize video or does a component exist that
does it for me?
 

Re:Free MediaPlayer component that resizes to fit panel


This is written for cbuilder if you note the MediaPlayer->DisplayRect.Right
and Bottom
reading these will give the width and height of the full size video.
writing will set the new size for the video display.

eg.   MediaPlayer.DisplayRect.Right  := 320;
       MediaPlayer.DisplayRect.Bottom  := 240;
not sure if the pascal syntax is correct .

you will need to read first to calculate the aspect ratio otherwise the
video will be distorted

The following code is a working example of a stretched media player
keeping the aspect ratio intact. it's written in builder but I hope it
helps.

Start a new application
put a button, panel, and media player onto the form
set the panel and media players visible property to false
then put the code below into the buttons onclick event
then run the app.

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  TRect r;
  Panel1->Visible = false; // This hides the video resize

  OpenDialog1->FileName = "*.avi"; // You can use any valid extention
  if (OpenDialog1->Execute())
  {
    MediaPlayer1->FileName = OpenDialog1->FileName;
  }

  MediaPlayer1->DeviceType = dtAutoSelect;
  MediaPlayer1->Display = Panel1;
  MediaPlayer1->Open();

  try
  {

   float width = MediaPlayer1->DisplayRect.Right;
   float height = MediaPlayer1->DisplayRect.Bottom;
   float Proportion = width / height;
   int   VideoSize = 150;         // video will display at this size

   if(width >= height)
   {
    r.right = VideoSize;
    r.bottom = VideoSize / Proportion;
   }
    else{ r.bottom = VideoSize * Proportion;
          r.right = VideoSize; }
          r.left = 0;
          r.top = 0;

   MediaPlayer1 -> DisplayRect = r;
   Panel1->Visible = true;
   MediaPlayer1->Wait = true;
   MediaPlayer1->Play();
  }
  __finally
  {
    MediaPlayer1->Close();
  }

Quote
}

Re:Free MediaPlayer component that resizes to fit panel


Sorry for the delay I inadvertantly posted to a local isp.

This is written for cbuilder if you note the MediaPlayer->DisplayRect.Right
and Bottom
reading these will give the width and height of the full size video.
writing will set the new size for the video display.

eg.   MediaPlayer.DisplayRect.Right  := 320;
       MediaPlayer.DisplayRect.Bottom  := 240;
not sure if the pascal syntax is correct .

you will need to read first to calculate the aspect ratio otherwise the
video will be distorted

The following code is a working example of a stretched media player
keeping the aspect ratio intact. it's written in builder but I hope it
helps.

Start a new application
put a button, panel, and media player onto the form
set the panel and media players visible property to false
then put the code below into the buttons onclick event
then run the app.

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  TRect r;
  Panel1->Visible = false; // This hides the video resize

  OpenDialog1->FileName = "*.avi"; // You can use any valid extention
  if (OpenDialog1->Execute())
  {
    MediaPlayer1->FileName = OpenDialog1->FileName;
  }

  MediaPlayer1->DeviceType = dtAutoSelect;
  MediaPlayer1->Display = Panel1;
  MediaPlayer1->Open();

  try
  {

   float width = MediaPlayer1->DisplayRect.Right;
   float height = MediaPlayer1->DisplayRect.Bottom;
   float Proportion = width / height;
   int   VideoSize = 150;         // video will display at this size

   if(width >= height)
   {
    r.right = VideoSize;
    r.bottom = VideoSize / Proportion;
   }
    else{ r.bottom = VideoSize * Proportion;
          r.right = VideoSize; }
          r.left = 0;
          r.top = 0;

   MediaPlayer1 -> DisplayRect = r;
   Panel1->Visible = true;
   MediaPlayer1->Wait = true;
   MediaPlayer1->Play();
  }
  __finally
  {
    MediaPlayer1->Close();
  }

Quote
}

Re:Free MediaPlayer component that resizes to fit panel


mstain...@ntlworld.com (Martin Stainsby) wrote in <3a26f609$1_1@dnews>:

Quote
>Sorry for the delay I inadvertantly posted to a local isp.

That's ok :)  Thank you and I will look at the stuff tonight. I did program  
C/C++ some years ago so I will manage I hope :)

--
Jacob Pedersen
AK Techotel
J.Peder...@techotel.dk

Other Threads