2009-12-09 85 views
3

我想從內存流或字節數組中加載SWF對象,而不是磁盤上的文件。從內存流或字節數組中加載Flash電影

AxShockwaveFlash類提供方法和屬性來加載SWF,以字符串的形式提供其路徑,但我還沒有看到另一種方式。有一個InlineData屬性,但通常這個類是無證的,我不知道這個屬性是做什麼的。它可以完成嗎?

感謝 ˚F

+0

http://stackoverflow.com/questions/1553563/play-flv-from-bytearray-in-flash-player – Amarghosh 2009-12-10 09:19:58

回答

9

我想什麼你想要做的是在C#中初始化這個,而不是在Flash本身。它可以做到,但是有限制(例如,你可能會遇到奇怪的安全問題)。另一個需要注意的是,這只是在VS 2010/Flash 10上進行過測試,但它理論上可以在任何版本中運行。

好吧,讓我們假設您已經使用標準機制將Flash控件放在窗體上。還要將您想要的閃存文件添加到資源(或內聯字節數組,由您決定)。

然後使用下面的代碼加載Flash文件。

private void InitFlashMovie(AxShockwaveFlash flashObj, byte[] swfFile) 
{ 
    using (MemoryStream stm = new MemoryStream()) 
    { 
     using (BinaryWriter writer = new BinaryWriter(stm)) 
     { 
      /* Write length of stream for AxHost.State */ 
      writer.Write(8 + swfFile.Length); 
      /* Write Flash magic 'fUfU' */ 
      writer.Write(0x55665566); 
      /* Length of swf file */ 
      writer.Write(swfFile.Length);      
      writer.Write(swfFile); 
      stm.Seek(0, SeekOrigin.Begin); 
      /* 1 == IPeristStreamInit */ 
      flashObj.OcxState = new AxHost.State(stm, 1, false, null); 
     } 
    } 
} 

傳遞形式的閃存對象和含有閃光文件來加載字節數組,它應該工作。

+0

此方法效果[R非常好!你是人類的霸王。 +1 – 2016-08-28 03:56:12

2

你是男人
非常感謝你我正在尋找,但除了原生的C沒有找到++,我試了一下,效果不錯

private:void initflash(AxShockwaveFlashObjects::AxShockwaveFlash^ax,array<System::Byte>^data) 
     { 
      MemoryStream^ ms=gcnew MemoryStream(); 
      BinaryWriter^ bwr=gcnew BinaryWriter(ms); 
      bwr->Write(8+data->Length); 
      bwr->Write(0x55665566); 
      bwr->Write(data->Length); 
      bwr->Write(data); 
      ms->Seek(0,SeekOrigin::Begin); 
      ax->OcxState=gcnew AxHost::State(ms,1,false,nullptr); 

      bwr->Close(); 
      delete bwr; 
      ms->Close(); 
      delete ms; 
     } 
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { 
      axShockwaveFlash1->FlashVars="indextext=courses/en0600000000/launch.text.xml&cid=0600000000&l1=en&l2=none"; 
      array<System::Byte>^data= File::ReadAllBytes("F:\\Learning\\unformated\\New Folder (3)\\CCNA\\theme\\index.swf"); 
      initflash(axShockwaveFlash1,data); 
      SubclassHWND^ s=gcnew SubclassHWND(); 
      s->AssignHandle(axShockwaveFlash1->Handle); 
     } 

最後兩行我「使用下面的類,以防止右鍵菜單M

ref class SubclassHWND :public NativeWindow 
{ 
public: 
    SubclassHWND(){} 
protected: 
    virtual void WndProc(Message %m) override 
      { 
       if(m.Msg==0x204) 
       { 
        return; 
       } 
       NativeWindow::WndProc(m); 
      } 
};