[DUG] Play a movie from a stream

Phil Middlemiss phil at tumonz.co.nz
Fri May 19 10:01:40 NZST 2006


Hi Leigh - I'm not sure at this point.

I've found some code that will let me provide a memory stream for the 
TMediaPlayer - I had to go in and change a couple of lines of code in 
MPlayer unit though. I also have to be careful how it's encoded. The 
media player control seems a little flaky to me - it doesn't seem to 
handle a lot of AVIs that the Microsoft Media Player program plays.

I've also got some code that let's me play it without the TMediaPlayer 
(basically just uses the same mci commands) so I may end up using that - 
haven't decided yet.

Anyway, There is a control here:
http://www.wilsonc.demon.co.uk/misccomponents.htm

called TMediaPlayerMemoryFile which works when you change the lines in 
TMedia Player.
All I changed in MPlayer were the lines in the TMediaPlayer.Open method, 
starting line 844:

changed:

  if FDeviceType <> dtAutoSelect then
    FFlags := FFlags or mci_Open_Type;

  if FDeviceType <> dtAutoSelect then
    FFlags := FFlags or mci_Open_Type
  else
    FFlags := FFlags or MCI_OPEN_ELEMENT;

which seems to be a bug to me (doing the same thing twice).
Change to this:

  if FDeviceType <> dtAutoSelect then
    FFlags := FFlags or mci_Open_Type;

  if FElementName <> '' then
    FFlags := FFlags or MCI_OPEN_ELEMENT;

It doesn't work if you don't have the MCI_OPEN_ELEMENT flag set.
There are no instructions included in the TMediaPlayerMemoryFile 
component so here they are:
1. MediaPlayerMemoryFile.FileName := 'TEST.XXX', where 'XXX' is some
unregistered file type
2.MediaPlayer.FileName := MediaPlayerMemoryFile.FileName + '+';
The 'plus' sign tells the MM IO subsystem to get the data from the 
hooked IO
proc.
3.MediaPlayer.DeviceType := dtAVIVideo; for .avi or
   MediaPlayer.DeviceType := dtWaveAudio; for  .wav.

and then call MediaPlayer.Open, and MediaPlayer.Play.

The stand-alone code I found is here (provided by Nils Haeck on a 
NLDelphi forum):
-----------------------------------------------------------------------------
unit Unit1;
{
  This demo shows how to play AVI video from memory using
  the mciSendCommand and mmio functions

  Date: 17 Oct 2003

  (c) Nils Haeck www.simdesign.nl

}

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, MMSystem, ExtCtrls;

type
  TForm1 = class(TForm)
    edFilename: TEdit;
    Label1: TLabel;
    btnPick: TButton;
    btnOpen: TButton;
    btnPlay: TButton;
    lbDeviceID: TLabel;
    Panel1: TPanel;
    procedure btnPickClick(Sender: TObject);
    procedure btnOpenClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure btnPlayClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    FIsOpened: boolean;
    FDeviceID: Word;
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

// Global memory pointer - for now
var
  FMem: pointer = nil;
  FSize: integer = 0;
  FOpened: boolean = False;
const
  FFourCC = 'IOCB'; // acronym for IO CallBack (but it really does not 
matter - choose as you wish)

function MyIOCallback(lpmmioinfo: PChar; uMessage: UINT; lParam1, 
lParam2: LPARAM): Longint stdcall;
// This function is called and will provide access to the file. The MM 
system "thinks"
// this is a file, while we use the global memory stream.
var
  AInfo: pmmioInfo;
begin
  AInfo := pmmioInfo(lpmmioinfo);
  case uMessage of
  MMIOM_OPEN:
    // Open the "file"
    begin
      if FOpened then begin
        Result := 0;
        exit;
      end;
      FOpened := True;
      AInfo.lDiskOffset := 0;
      Result := 0;
    end;
  MMIOM_CLOSE:
    // Close the "file"
    Result := 0;
  MMIOM_READ:
    // Read data from the "file"
    begin
      // Copy from memory - no checking
      Move(pointer(integer(FMem) + AInfo.lDiskOffset)^, 
pointer(lParam1)^, lParam2);
      AInfo.lDiskOffset := AInfo.lDiskOffset + lParam2;
      Result := lParam2;
    end;
  MMIOM_SEEK:
    // Seek new position in the "file"
    begin
      case lParam2 of
      // From beginning:
      0: AInfo.lDiskOffset := lParam1;
      // From current:
      1: AInfo.lDiskOffset := AInfo.lDiskOffset + lParam1;
      // From end:
      2: AInfo.lDiskOffset := FSize - 1 - lParam1;
      end;
      Result := AInfo.lDiskOffset;
    end;
  else
    // Unexpected msgs. For instance, we do not process MMIOM_WRITE in 
this sample
    Result := -1;
  end;
end;
---------------------------------------------------------------------
You will have to recreate the form, but that's pretty straight forward.

That's about as far as I have got yet - more urgent things have taken 
over for now.

Phil.

Leigh Wanstead wrote:
> Hi Phil,
>  
> How is going for this issue?
>  
> Regards
> Leigh
> www.smootharm.com <http://www.smootharm.com>
>
>     -----Original Message-----
>     *From:* delphi-bounces at ns3.123.co.nz
>     [mailto:delphi-bounces at ns3.123.co.nz]*On Behalf Of *Phil Middlemiss
>     *Sent:* Wednesday, 17 May 2006 5:19 p.m.
>     *To:* NZ Borland Developers Group - Delphi List
>     *Subject:* Re: [DUG] Play a movie from a stream
>
>     OK, had a closer look at it and I can see how it is supposed to
>     work (kind of). But I can't get it to work. It's supposed to
>     somehow work with the standard TMediaPlayer. However, the main
>     technique it uses (using mmioInstallIOProc) is applicable and I've
>     found some sample code that I can use instead hopefully.
>
>     If I get it working, I'll post the working code to the list.
>
>     Cheers,
>     Phil.
>
>     Ben Taylor wrote:
>>     well, from the 2sec i spent looking at it, it installs a custom io-handler to the
>>     mediaplayer, then implements the iorequests using a memorystream.. there's
>>     definately no file-based activity there. yes, you need to set a filename in the
>>     mediaplayer, but thats only used to identify which named-memorystream to use as a
>>     datasource..
>>
>>     hth,
>>     b
>>
>>     --- Phil Middlemiss <phil at tumonz.co.nz> wrote:
>>
>>
>>     ---------------------------------
>>       Hi Ben,
>>
>>     yes, found that before too. Works by writing to a temporary file as faras I can tell
>>     by looking at the source code. As I said, I spent half aday scouring the internet.
>>
>>     Has no one done this before?
>>
>>     Phil.
>>
>>     Ben Taylor wrote:  
>>     1min on google found this:
>>     http://www.wilsonc.demon.co.uk/misccomponents.htm"TMediaPlayerMemoryFile allows you
>>     to play wave and AVI memory images using theregular Delphi TMediaPlayer component. 
>>     You can create the memory images on-the-flyor load them from resources."looks like a
>>     nice workaround to the mediaplayer limitation..no idea if it works.. --- Phil
>>     Middlemiss <phil at tumonz.co.nz> wrote:  
>>           
>>     I need to play a video clip (with audio) from a memory stream instead of     
>>         
>>     Send instant messages to your online friends http://au.messenger.yahoo.com
>>     _______________________________________________Delphi mailing
>>     listDelphi at ns3.123.co.nzhttp://ns3.123.co.nz/mailman/listinfo/delphi  
>>       
>>>     begin:vcard
>>>     fn:Phil Middlemiss
>>>     n:Middlemiss;Phil
>>>     org:Vision Software, MTS Ltd
>>>     email;internet:phil at tumonz.co.nz
>>>     title:Project Leader
>>>     tel;work:+64 7 3480001
>>>     tel;cell:+64 27 4592648
>>>     x-mozilla-html:TRUE
>>>     url:http://www.tumonz.co.nz
>>>     version:2.1
>>>     end:vcard
>>>
>>>         
>>>>     _______________________________________________
>>>>           
>>>     Delphi mailing list
>>>     Delphi at ns3.123.co.nz
>>>     http://ns3.123.co.nz/mailman/listinfo/delphi
>>>
>>>         
>>
>>
>>     Send instant messages to your online friends http://au.messenger.yahoo.com 
>>     _______________________________________________
>>     Delphi mailing list
>>     Delphi at ns3.123.co.nz
>>     http://ns3.123.co.nz/mailman/listinfo/delphi
>>
>>
>>
>>       
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Delphi mailing list
> Delphi at ns3.123.co.nz
> http://ns3.123.co.nz/mailman/listinfo/delphi
>   
-------------- next part --------------
A non-text attachment was scrubbed...
Name: phil.vcf
Type: text/x-vcard
Size: 250 bytes
Desc: not available
Url : http://ns3.123.co.nz/pipermail/delphi/attachments/20060519/89eed3d2/phil.vcf


More information about the Delphi mailing list