Help us improve Softanics
We use analytics cookies to understand which pages and downloads are useful. No ads. Privacy Policy

OnLoadExternalResourceByRelativePath

Syntax

public delegate void OnLoadExternalResourceByRelativePathEventHandler(
  object sender,
  String RelativePath,
  Stream ContentStream,
  ref bool Handled);
 
public event OnLoadExternalResourceByRelativePathEventHandler OnLoadExternalResourceByRelativePath;

Description

Triggered when a movie tries to load an external resource (such as an image or XML file) using a relative path.

See also OnLoadExternalResourceByRelativePath.

C# Example

private void OnLoadExternalResourceByRelativePath(object sender, String strRelativePath, System.IO.Stream Stream, ref bool Handled)
{
    System.IO.Stream FromStream = null;
 
    if (strRelativePath == "images/embedded_image1.jpg")
        FromStream = this.GetType().Assembly.GetManifestResourceStream("Sample6_ExternalResourcesEmbedding.Resources.embedded_images.embedded_image1.jpg");
    if (strRelativePath == "images/embedded_image2.jpg")
        FromStream = this.GetType().Assembly.GetManifestResourceStream("Sample6_ExternalResourcesEmbedding.Resources.embedded_images.embedded_image2.jpg");
    if (strRelativePath == "images/embedded_image3.jpg")
        FromStream = this.GetType().Assembly.GetManifestResourceStream("Sample6_ExternalResourcesEmbedding.Resources.embedded_images.embedded_image3.jpg");
    if (strRelativePath == "images/embedded_image4.jpg")
        FromStream = this.GetType().Assembly.GetManifestResourceStream("Sample6_ExternalResourcesEmbedding.Resources.embedded_images.embedded_image4.jpg");
    if (strRelativePath == "images/embedded_image5.jpg")
        FromStream = this.GetType().Assembly.GetManifestResourceStream("Sample6_ExternalResourcesEmbedding.Resources.embedded_images.embedded_image5.jpg");
    if (strRelativePath == "images/external_image.jpg")
    {
        if (OpenJPEGFileDialog.ShowDialog() == DialogResult.OK)
            FromStream = OpenJPEGFileDialog.OpenFile();
    }
 
    if (FromStream != null)
    {
        const int size = 64 * 1024;
        byte[] buffer = new byte[size];
        int ReadBytes;
 
        while ((ReadBytes = FromStream.Read(buffer, 0, size)) > 0)
        {
            try
            {
                Stream.Write(buffer, 0, size);
            }
            catch (System.IO.IOException)
            {
                // Loading is interrupted
                break;
            }
        }
 
        Stream.Close();
 
        Handled = true;
    }
}

VB.Net Example

Private Sub f_in_box__control1_OnLoadExternalResourceByRelativePath(ByVal sender As Object, ByVal URL As String, ByVal Stream As System.IO.Stream, ByRef Handled As Boolean) Handles f_in_box__control1.OnLoadExternalResourceByRelativePath
 
    Dim FromStream As System.IO.Stream = Nothing
 
    If URL = "images/embedded_image1.jpg" Then
        FromStream = Me.GetType().Assembly.GetManifestResourceStream("Sample6_ExternalResourcesEmbedding.embedded_image1.jpg")
    End If
 
    If URL = "images/embedded_image2.jpg" Then
        FromStream = Me.GetType().Assembly.GetManifestResourceStream("Sample6_ExternalResourcesEmbedding.embedded_image2.jpg")
    End If
 
    If URL = "images/embedded_image3.jpg" Then
        FromStream = Me.GetType().Assembly.GetManifestResourceStream("Sample6_ExternalResourcesEmbedding.embedded_image3.jpg")
    End If
 
    If URL = "images/embedded_image4.jpg" Then
        FromStream = Me.GetType().Assembly.GetManifestResourceStream("Sample6_ExternalResourcesEmbedding.embedded_image4.jpg")
    End If
 
    If URL = "images/embedded_image5.jpg" Then
        FromStream = Me.GetType().Assembly.GetManifestResourceStream("Sample6_ExternalResourcesEmbedding.embedded_image5.jpg")
    End If
 
    If URL = "images/external_image.jpg" Then
        If OpenJPEGFileDialog.ShowDialog() = DialogResult.OK Then
            FromStream = OpenJPEGFileDialog.OpenFile()
        End If
    End If
 
    If Not FromStream Is Nothing Then
 
        ' Also you can write content in a separate thread
 
        Const Size = 64 * 1024
        Dim buffer(Size) As Byte
        Dim ReadBytes As Integer
 
        While True
 
            ReadBytes = FromStream.Read(buffer, 0, Size)
 
            If ReadBytes = 0 Then Exit While
 
            Try
                Stream.Write(buffer, 0, ReadBytes)
            Catch e As System.IO.IOException
                ' Loading is interrupted
                Exit While
            End Try
 
        End While
 
        Stream.Close()
 
        Handled = True
 
    End If
 
End Sub