• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 562
  • Last Modified:

TMediaPlayer

How come i cannoty play a AVI file with following code ?

  MediaPlayer1.Close;
  MediaPlayer1.Filename:= GetCurrentDir + '\17.avi';
  MediaPlayer1.DeviceType := dtAVIVideo;
  MediaPlayer1.Display:= Panel1;
  MediaPlayer1.Open;
  MediaPlayer1.Play;

thanks,
Andrew
0
andrewyu
Asked:
andrewyu
  • 11
  • 8
  • 3
  • +1
1 Solution
 
vadim_tiCommented:
rename .avi to .mpg, may be it will help
0
 
andrewyuAuthor Commented:
No, it cannot help.

However, the file can open in Windows Medai Player.

Thanks,
Andrew
0
 
andrewyuAuthor Commented:
After I change the code as follownig, the ediaPlayer1.Position is moving (i.e. the number is increasing).
However, I cannot see any MOVIE from its popup window.
What seems to be the problem ?

  MediaPlayer1.Close;
  MediaPlayer1.DeviceType := dtAutoSelect;
//  MediaPlayer1.Display:= Panel1;
  MediaPlayer1.Filename:= GetCurrentDir + '\17.avi';
  MediaPlayer1.Open;
  MediaPlayer1.DisplayRect:= Rect(0, 0, 400, 400);
  MediaPlayer1.Rewind;
  MediaPlayer1.Play;

Thanks,
Andrew
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
Eddie ShipmanAll-around developerCommented:
Can you post the AVI somewhere where we can get it?
0
 
andrewyuAuthor Commented:
I found I can only play file with compression on "Mcrosoft MPEG-4 Video Codec" and cannot play file with compression on "XviD MPEG-4 Codec".

BUT, both can play smooth in Windows Media Player.

How can I solve this problem ?

Thanks,
Andrew
0
 
vadim_tiCommented:
see code below worked for me after renaming file from .AVI to .MPG
if i tried to play some .AVI files, i had error something like "compression not found"


procedure TMainForm.FormCreate(Sender: TObject);
begin
    mp := TMediaPlayer.Create(Self);
    mp.Visible := false;
    mp.VisibleButtons := [];
    mp.Parent := Panel1;
    mp.Display := Panel1;
end;


procedure TMainForm.DoPlay(filename: String; loop, fullScreen: Boolean);
var
  rect, fRect: TRect;
  h, w: Integer;
begin
  if not inPlay then begin
    fRect := GetClientRect;
    inPlay := true;
    inLoop := loop;


    mp.Wait := true; mp.Notify := false;
    mp.Close;
    mp.FileName := filename;
    mp.Wait := true; mp.Notify := false;
    mp.Open;

    FillChar(Rect, sizeof(TRect), 0);
    rect := mp.DisplayRect;
    h := rect.Bottom - rect.Top;
    w := rect.Right - rect.Left;
    if (h > 0) and (w > 0) then begin
      if fullScreen then begin
        Panel1.Align := alClient;
        mp.DisplayRect := fRect;
      end
      else begin
        Panel1.Align := alNone;
        Panel1.height := h; Panel1.Width := w;
        Panel1.Top := (frect.Bottom - frect.Top - h) div 2;
        Panel1.Left := (frect.Right - frect.Left - w) div 2;
      end;
      Panel1.Visible := true;
    end;
    mp.Wait := false; mp.Notify := true;
    mp.Play;
  end;
end;
0
 
StevenBCommented:
The TMediaPlayer component struggles with many compressions. You can try importing the Windows Media Player ActiveX control to play your file instead:

1) From the Delphi main menu click Component->Import ActiveX Control
2) Select Windows Media Player from the list of controls and click the Install button
3) The Windows Media Player Control should be installed on your palette (probably on the ActiveX tab)

Maybe that would work?
0
 
andrewyuAuthor Commented:
Hi, vadim_ti,

It still cannot work.

Hi, StevenB,

Do you have any sample code for that control and how can i IN-VISIBLE the button ?

Thanks,
Andrew
0
 
andrewyuAuthor Commented:
Hi, StevenB,

Wooo. It can play the video now.
But, how can I IN-VISIBLE the button ?

Thanks,
Andrew
0
 
andrewyuAuthor Commented:
Hi, StevenB,

Wooo. It can play the video now.
But, how can I IN-VISIBLE the button and REPEATLY ?

Thanks,
Andrew
0
 
andrewyuAuthor Commented:
Hi, StevenB,

Wooo. It can play the video now.
But, how can I IN-VISIBLE the button and play REPEATLY ?

Thanks,
Andrew
 
0
 
Eddie ShipmanAll-around developerCommented:
" IN-VISIBLE the button"

Which button?
0
 
andrewyuAuthor Commented:
I mean those button on the bottom, i.e. Play, slider, volume, pause, stop ...
0
 
Eddie ShipmanAll-around developerCommented:
In TMediaPlayer or the the Media Player ActiveX? Please be more specific which you are using, here.
0
 
Eddie ShipmanAll-around developerCommented:
I'd still like to have a copy of the AVI to test, if possible.
0
 
StevenBCommented:
 To be honest andrew, I'm not sure how, if indeed it is possible, you hide the buttons on the Windows Media Player ActiveX. A nasty hack would be to hide them behind a panel, but I can't advocate this sort of dirty coding ;o)



0
 
Eddie ShipmanAll-around developerCommented:
I see no way to access the Players controls from the ActiveX. I know you can set the UI_MODE of the Player to NONE
but can not find out how to do it in the ActiveX.
0
 
andrewyuAuthor Commented:
hi, EddieShipman,

Sorry ! I cannot give you the AVI at this moment.

Anyway, what do you mean by UI_MODE ?

Thanks,
Andrew
0
 
Eddie ShipmanAll-around developerCommented:
When you select View Fullscreen, it sends a Set_UIMoid call to the WMP iwth the ui_mode flag of 'none'.

I can find no way to tell WMP to go fullscreen from the OCX.
0
 
andrewyuAuthor Commented:
What is value for Set_UIMoid (I guess it is Set_UIMode) and "none" ?

Thanks,
Andrew
0
 
StevenBCommented:
Yeah, no worries mate.
0
 
Eddie ShipmanAll-around developerCommented:
So, did you get it working? If so, please post your result.
0
 
andrewyuAuthor Commented:
I cannot test it at this moment (because i cannot upgrade my Media Player to version 10 now), however, it is right resources for me.

Anyway, I will test it completely 2 weeks later and I will tell you the result afterward !

Thank you very much for your help !

Best,
Andrew
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 11
  • 8
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now