Seite 1 von 1

Flash aus Speicher abspielen

Verfasst: 24.07.2006 06:36
von Leonhard
Orginal Therad aus dem Englischem Forum: http://www.purebasic.fr/english/viewtopic.php?t=22740

Code: Alles auswählen

; Play Flash from Memory

;
; Embedded flash player example (ActiveX)
;
; By AlphaSND
;
; Translated to PB4 by Flype
; Playing from included data by Esteban1
;
; Flash ActiveX interface definition
;

Interface IShockwaveFlash Extends IDispatch
  get_ReadyState(a)
  get_TotalFrames(a)
  get_Playing(a)
  put_Playing(a)
  get_Quality(a)
  put_Quality(a)
  get_ScaleMode(a)
  put_ScaleMode(a)
  get_AlignMode(a)
  put_AlignMode(a)
  get_BackgroundColor(a)
  put_BackgroundColor(a)
  get_Loop(a)
  put_Loop(a)
  get_Movie(a)
  put_Movie(a)
  get_FrameNum(a)
  put_FrameNum(a)
  SetZoomRect(a,b,c,d)
  Zoom(a)
  Pan(a,b,c)
  Play()
  Stop()
  Back()
  Forward()
  Rewind()
  StopPlay()
  GotoFrame(a)
  CurrentFrame(a)
  IsPlaying(a)
  PercentLoaded(a)
  FrameLoaded(a,b)
  FlashVersion(a)
  get_WMode(a)
  put_WMode(a)
  get_SAlign(a)
  put_SAlign(a)
  get_Menu(a)
  put_Menu(a)
  get_Base(a)
  put_Base(a)
  get_scale(a)
  put_scale(a)
  get_DeviceFont(a)
  put_DeviceFont(a)
  get_EmbedMovie(a)
  put_EmbedMovie(a)
  get_BGColor(a)
  put_BGColor(a)
  get_Quality2(a)
  put_Quality2(a)
  LoadMovie(a,b.p-bstr)
  TGotoFrame(a,b)
  TGotoLabel(a,b)
  TCurrentFrame(a,b)
  TCurrentLabel(a,b)
  TPlay(a)
  TStopPlay(a)
  SetVariable(a,b.p-bstr)
  GetVariable(a,b.p-bstr)
  TSetProperty(a,b,c)
  TGetProperty(a,b,c)
  TCallFrame(a,b)
  TCallLabel(a,b)
  TSetPropertyNum(a,b,c)
  TGetPropertyNum(a,b,c)
  get_SWRemote(a)
  put_SWRemote(a)
  get_Stacking(a)
  put_Stacking(a)
EndInterface

Prototype AtlAxWinInit()
Prototype AtlAxCreateControl(a.p-bstr,b.l,c.l,d.l)
Prototype AtlAxGetControl(a.l,b.l)

Procedure.l FlashLoadFromData(SwfStart.l,SwfEnd.l,*FlashObject.IShockwaveFlash)
  FlashBuffer=AllocateMemory(SwfEnd-SwfStart+8) ; let's make room
  If FlashBuffer
    PokeL(FlashBuffer,$55665566) ;now write the header
    PokeL(FlashBuffer+4,SwfEnd-SwfStart) ; and the file size
    CopyMemory(SwfStart,FlashBuffer+8,SwfEnd-SwfStart) ; then copy the whole file.
    If CreateStreamOnHGlobal_(FlashBuffer,#True,@FlashStream.IStream)=0 ;Create a stream.
      *FlashObject\QueryInterface(?IID_IPersistStreamInit,@FlashPSI.IPersistStreamInit) ; Ask for IPersistStreamInit interface     
      If FlashPSI
        If FlashPSI\load(FlashStream)=0 ;load the stream we created
          ReturnValue=1
        EndIf
        FlashPSI\Release(); self explained
      EndIf 
      FlashStream\Release() ; idem
    EndIf
    FreeMemory(FlashBuffer) ;idem
  EndIf
  ProcedureReturn ReturnValue
EndProcedure

If OpenLibrary(0,"atl.dll")
  AtlAxWinInit.AtlAxWinInit             = GetFunction(0, "AtlAxWinInit")
  AtlAxCreateControl.AtlAxCreateControl = GetFunction(0, "AtlAxCreateControl")
  AtlAxGetControl.AtlAxGetControl       = GetFunction(0, "AtlAxGetControl")
Else
  MessageRequester("Error", "OpenLibrary() failed.")
  End
EndIf

;Movie$ = "c:\clock.swf"
;Movie$ = "c:\\WINDOWS\\Help\\Tours\\mmTour\\segment1.swf"

CoInitialize_(0)

If OpenWindow(0, 100, 100, 300, 315, "")
 
  CreateGadgetList(WindowID(0))
  ContainerGadget(0, 0, 0, 300, 275) ; This will be our container window, where the ActiveX will be rendered
  CloseGadgetList()
 
  ButtonGadget(1, 10, 285, 70, 25, "Play", #PB_Button_Toggle)
  ;ButtonGadget(2, 90, 285, 70, 25, "Play")
 
  If AtlAxWinInit()
   
    AtlAxCreateControl("ShockwaveFlash.ShockwaveFlash", GadgetID(0), 0, @Container.IUnknown) ; It always create the IE control even if flash isn't found
   
    If Container
     
      AtlAxGetControl(GadgetID(0),@oFlash.IShockwaveFlash)
     
      If oFlash
       
        If oFlash\QueryInterface(?IID_ShockwaveFlash, @oFlash) = 0 ; Be sure it's a flash object in the IE container
         
          ;oFlash\LoadMovie(0, Movie$)
          FlashLoadFromData(?FlashFileStart,?FlashFileEnd,oFlash) ; Let's get it from included data
          oFlash\get_ReadyState(@state)   ; 0=Loading, 1=Uninitialized, 2=Loaded, 3=Interactive, 4=Complete. 
         
          Select state
            Case 4 , 3
              ;oFlash\Play()
              oFlash\FlashVersion(@Version)
              Debug "Flash Version: " + Hex(Version)
              ;oFlash\put_BackgroundColor($000000)
              oFlash\get_BackgroundColor(@BackColor)
              Debug "BackColor: " + Hex(BackColor)
            Default
              Debug state
              MessageRequester("Error", "The movie can't be loaded ("+Movie$+")")
          EndSelect
          oFlash\put_Quality(0)
          Repeat
            Select WaitWindowEvent(50)
              Case #PB_Event_CloseWindow
                Break
              Case #PB_Event_SizeWindow
                ResizeGadget(0, #PB_Ignore, #PB_Ignore, WindowWidth(0), WindowHeight(0)-35)
                ResizeGadget(1, #PB_Ignore, WindowHeight(0)-30, #PB_Ignore, #PB_Ignore)
                ;ResizeGadget(2, #PB_Ignore, WindowHeight(0)-30, #PB_Ignore, #PB_Ignore)
              Case #PB_Event_Gadget
                Select EventGadget()
                  Case 1
                    Select GetGadgetState(1)
                      Case 0 : oFlash\Stop()
                      Case 1 : oFlash\Play()
                    EndSelect
                EndSelect
            EndSelect
            oFlash\CurrentFrame(@frame)
            SetWindowTitle(0, "Frame " + Str(frame))
          ForEver
         
          oFlash\Release()
         
        EndIf
       
        oFlash\Release()
       
      EndIf
     
    EndIf
   
  EndIf
 
  CloseWindow(0)   ; Don't forget this one, else the program will crash
 
EndIf

CoUninitialize_()

End

DataSection
IID_ShockwaveFlash: Data.q $11CFAE6DD27CDB6C,$000054534544B896
IID_IPersistStreamInit:
Data.l $7FD52380
Data.w $4E07,$101B
Data.b $AE,$2D,$08,$00,$2B,$2E,$C7,$13
FlashFileStart:
IncludeBinary "c:\\WINDOWS\\Help\\Tours\\mmTour\\segment1.swf"
FlashFileEnd:
EndDataSection

Verfasst: 24.07.2006 09:13
von HeX0R
Verlinke wenigstens zum richtigen Beitrag.

Aber den Sinn verstehe ich irgendwie nicht.
Wozu Estebans Code hier nochmal posten ?

Verfasst: 24.07.2006 09:29
von Kiffi
HeX0R hat geschrieben:Aber den Sinn verstehe ich irgendwie nicht.
Wozu Estebans Code hier nochmal posten ?
... überdies habe ich erst unlängst in einem entsprechenden Thread auf
diesen Beitrag verlinkt.

Grüße ... Kiffi

Verfasst: 05.02.2007 01:02
von Delle
Der User muss also einen IE mit installiertem ActiveX haben richtig?

Muss das Flashplugin auch installiert sein, oder ist diese flash.ocx wieder was anderes?

Verfasst: 05.02.2007 08:02
von Leonhard
Das ActiveX - Element muss installiert sein. Den Internet-Explorer benötigt man nicht dazu!

Diese Funktion liest das ActivX-Element mit hilfe der OCX-Datei aus.

Verfasst: 08.02.2007 18:42
von Delle
Das dürfte ja bei fast jedem Windows-User der Fall sein oder?

Aber ist nun die "flash.ocx" sozusagen das Plugin?

Was wenn man ein Flash9-File abspielen will und das "Plugin" aber eher "alt" ist?

Und noch was anderes: Wie kann man mit obigen Code auslesen, wie groß der Movie ist und welche Flashversion?

Verfasst: 08.02.2007 18:56
von ts-soft
Flashversion:

Code: Alles auswählen

      If oFlash
          a.l
          oFlash\FlashVersion(@a)
          Debug a
Wie das jetzt ausgewertet wird, weiß ich nicht (Minor, Mayor usw.)

Verfasst: 08.02.2007 21:45
von Delle
Hallo,

das liefert die Version von diesem .ocx zurück...

Ich meinte eher die Version und Größe vom .swf ... damit man eine Abfrage basteln kann, ob das SWF auf dem Rechner läuft oder eher nicht.