Play Flash Video (FLV) from a Stream

With F-IN-BOX, you can play Flash Video (FLV) files from external sources, URLs, or directly from a memory stream.

When F-IN-BOX loads Flash Video, no temporary files are created. Everything runs directly from memory.

This also allows you to encrypt your videos and embed them as application resources. F-IN-BOX loads FLV files without ever saving them to disk.

To play a Flash Video from a stream, create a Flash movie that loads the FLV from a private URL such as http://FLV/FlashVideo.flv.

The Flash movie uses the following ActionScript code:

var netConn:NetConnection = new NetConnection();
 
netConn.connect(null);
 
var netStream:NetStream = new NetStream(netConn);
 
my_video.attachVideo(netStream);
netStream.setBufferTime(0);
netStream.play("http://FLV/FlashVideo.flv");

When Flash tries to load the FLV from http://FLV/FlashVideo.flv, F-IN-BOX provides the video content.

Handle this behavior by implementing the OnLoadExternalResourceByFullPath event to provide the video stream.


C# Example

f_in_box__control1.AxCode.OnLoadExternalResourceByFullPath +=
    new f_in_box__lib.AxCode.OnLoadExternalResourceByFullPathEventHandler(OnLoadExternalResourceByFullPath);
 
private void OnLoadExternalResourceByFullPath(
    object sender,
    string URL,
    System.IO.Stream Stream,
    ref bool Handled)
{
    if (URL == "http://FLV/FlashVideo.flv")
    {
        System.IO.Stream FLVStream =
            this.GetType().Assembly.
                GetManifestResourceStream("Sample2_SWF_FLV_Embedding.Embedded_Movies.flashvideo.flv");
 
        const int size = 64 * 1024;
        byte[] buffer = new byte[size];
        int ReadBytes;
 
        while ((ReadBytes = FLVStream.Read(buffer, 0, size)) > 0)
        {
            try
            {
                Stream.Write(buffer, 0, ReadBytes);
            }
            catch (System.IO.IOException)
            {
                // Loading is interrupted
                break;
            }
        }
 
        Stream.Close();
        Handled = true;
    }
}

VB.NET Example

Private Sub OnLoadExternalResourceByFullPath(_
    ByVal sender As Object, _
    ByVal URL As String, _
    ByVal Stream As System.IO.Stream, _
    ByRef Handled As Boolean _
)
    If URL = "http://FLV/FlashVideo.flv" Then
        Dim FLVStream As System.IO.Stream = _
            Me.GetType().Assembly. _
                GetManifestResourceStream("Sample2_SWF_FLV_Embedding.flashvideo.flv")
 
        ' You can write all content right here, but if FLVStream
        ' is large, writing will take time and block the UI.
        ' Another option is to write content in a separate thread.
        ' See Sample1_SWF_And_FLV_Player for a threaded example.
 
        Const nSize = 64 * 1024
        Dim buffer(nSize) As Byte
        Dim nReadBytes As Integer
 
        While True
            nReadBytes = FLVStream.Read(buffer, 0, nSize)
            If nReadBytes = 0 Then Exit While
 
            Try
                Stream.Write(buffer, 0, nReadBytes)
            Catch e As System.IO.IOException
                ' Loading is interrupted
                Exit While
            End Try
        End While
 
        Stream.Close()
        Handled = True
    End If
End Sub

This method allows you to securely embed and deliver FLV files directly from memory, improving application security and preventing temporary file creation.