Loading movie (flv) from memory stream

.NET Edition of the F-IN-BOX
keith jeram
Posts: 6
Joined: Wed Jan 09, 2008 4:03 pm

Loading movie (flv) from memory stream

Postby keith jeram » Wed Jan 09, 2008 4:17 pm

I have just purchased F-in-Box and want to load a flash movie (flv) directly from a memory stream. (The movie has been saved to a database as a byte array and then recovered into a memory stream.) I am using F-in-box in Visual Studio 2005, C#.

Can you supply some simple example code for doing this please. Do we need to have the file FLVPlayer.swf embedded in the application, as in your examples? What is this file anyway?

I have tried various approaches based on your examples, but without success so far. I'm sure I'm missing something very simple!

Many thanks.

Softanics
Site Admin
Posts: 1402
Joined: Sat Sep 18, 2004 3:03 am
Location: Russia, St. Petersburg
Contact:

Postby Softanics » Wed Jan 09, 2008 5:21 pm

Thank you for your question.

Yes, you need FLVPlayer.swf embedded in the application. This file contains FLV player. Flash isn't able to play FLV directly, only from a player inside a flash movie. FLVPlayer.swf contains such movie.

How to play FLV from a stream step-by-step (also see example samples\C#\Sample02_SWF_FLV_Embedding):

1. Add FLVPlayer.swf as embedded resource to a project.

2. Add a handler:

Code: Select all

f_in_box__control1.AxCode.OnLoadExternalResourceByFullPath +=
new f_in_box__lib.AxCode.OnLoadExternalResourceByFullPathEventHandler(OnLoadExternalResourceByFullPath);


2. Loads FLVPlayer.swf from a resource:

Code: Select all

f_in_box__control1.PutMovieFromStream(
   this.GetType().Assembly.GetManifestResourceStream("Sample02_SWF_FLV_Embedding.Embedded_Movies.movie.swf"));
f_in_box__control1.FlashMethod_Play();


3. The handler code:

Code: Select all

private void OnLoadExternalResourceByFullPath(object sender, String URL, System.IO.Stream Stream, ref bool Handled)
{
   if (URL == "http://FLV/FlashVideo.flv")
   {
      System.IO.Stream FLVStream = !!!Your stream here!!!;

      FromStreamToStreamWriter writer =
         new FromStreamToStreamWriter(
               FLVStream,
               Stream
               );

      Handled = true;
   }
}


FromStreamToStreamWriter creates a separate thread that copies bytes from FLVStream to Stream. But if FLV is small you can copy its content inside the handler:

Code: Select all

private void OnLoadExternalResourceByFullPath(
   object sender,
   String URL,
   System.IO.Stream Stream,
   ref bool Handled)
{
   if (URL == "http://FLV/FlashVideo.flv")
   {
      Stream FLVStream = !!!Your stream here!!!;

      const int nSize = 64 * 1024;
      byte[] buffer = new byte[nSize];

      int nReadBytes;

      while (true)
      {
         nReadBytes = FLVStream.Read(buffer, 0, nSize);

         if (0 == nReadBytes)
            break;

         try
         {
            ToStream.Write(buffer, 0, nReadBytes);
         }
         catch (System.IO.IOException /* e */ )
         {
            // Loading is interrupted
            break;
         }
      }

      FLVStream.Close();
      ToStream.Close();
   }

   Handled = true;
}
Best regards, Artem A. Razin,
F-IN-BOX support
Ask your question here: http://www.f-in-box.com/support.html

keith jeram
Posts: 6
Joined: Wed Jan 09, 2008 4:03 pm

Loading movie (flv) from memory stream

Postby keith jeram » Thu Jan 10, 2008 12:13 pm

Many thanks for helpful response. It's now working beautifully!

Keith


Return to “.NET Edition”

Who is online

Users browsing this forum: No registered users and 2 guests

cron