Windows Develop Bookmark and Share   
 index > Windows Forms General > Flash video (swf) hosted in C# application - how to check swf lenght
 

Flash video (swf) hosted in C# application - how to check swf lenght

I have some powerpoint presentations converted into flash movies and I want to play them in a C# windows form.

I have added the AxShockwaveFlash librabry and I can play the swf files without problems in my application but then I need to check when the video has ended and then I cannot see how I can do it.

I have tried some properties like:

axShockwaveFlash.Playing

axShockwaveFlash.Frames and axShockwaveFlash.TotalFrames

But seems that they don't work properly, for example the bool property axShockwaveFlash.Playing its always false while playing the powerpoint converted to flash (swf).

Can someone tell me how can I check the lenght or is there any event that its fired when the flash movie its finish?

Thanks in advance.

Alejandro

Alejo Mejia  Monday, September 07, 2009 1:10 PM
Hi Alejo,

We can use a Timer to track the movie playing and compare the current frame index to the total frame count to know if the movie playing stops. This is a code snippet:
//The swf file path.
const string _moviePath = @"C:\Users\v-shunli\Desktop\1.swf";
//Timer used to record the time and trace the playing process.
Timer _timer = new Timer();
//Record the last frame index.
int _lastFrame = -1;
//The frame count of the movie.
int _frameCount = 0;
//Recored the time when ths movie starts playing.
DateTime _movieStartTime = DateTime.MinValue;
private void FlashForm_Load(object sender, EventArgs e)
{
    //Handle this event to get the frame count.
    axShockwaveFlash1.OnReadyStateChange += new AxShockwaveFlashObjects._IShockwaveFlashEvents_OnReadyStateChangeEventHandler(axShockwaveFlash1_OnReadyStateChange);
    //Load the movie
    axShockwaveFlash1.LoadMovie(0, _moviePath);            
    axShockwaveFlash1.Loop = false;
    _timer.Interval = 100;
    _timer.Tick += new EventHandler(_timer_Tick);
    _timer.Start();
    axShockwaveFlash1.Play();
    _movieStartTime = DateTime.Now;
}
void axShockwaveFlash1_OnReadyStateChange(object sender, AxShockwaveFlashObjects._IShockwaveFlashEvents_OnReadyStateChangeEvent e)
{
    //"state = 4" means the movie loading is finished.
    if (e.newState == 4 && _frameCount == 0)
    {                
        //Get the frame count.
        _frameCount = axShockwaveFlash1.TotalFrames;
    }
}
void _timer_Tick(object sender, EventArgs e)
{
    if (_frameCount != 0)
    {
        if (_lastFrame == _frameCount - 1)
        {
            //The frame is the last one. In other words, the movie playing finishes.
            //Stop the timer.
            _timer.Stop();
            //Get the movie playing time.
            TimeSpan time = DateTime.Now - _movieStartTime;
            //Show the message.
            MessageBox.Show(string.Format("Playing stops. Movie Length: {0}s", time.Milliseconds / 1000.0));

        }
        else
        {
            //Save the current frame index.
            _lastFrame = axShockwaveFlash1.FrameNum;
        }
    }
}
The link below shows how to use Flash Player 8 External API which can provide more control on the flash playing:
http://www.codeproject.com/KB/audio-video/flashexternalapi.aspx.

Let me know if this does not help.
Aland Li




Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Wednesday, September 09, 2009 6:09 AM
Hi Alejo,

We can use a Timer to track the movie playing and compare the current frame index to the total frame count to know if the movie playing stops. This is a code snippet:
//The swf file path.
const string _moviePath = @"C:\Users\v-shunli\Desktop\1.swf";
//Timer used to record the time and trace the playing process.
Timer _timer = new Timer();
//Record the last frame index.
int _lastFrame = -1;
//The frame count of the movie.
int _frameCount = 0;
//Recored the time when ths movie starts playing.
DateTime _movieStartTime = DateTime.MinValue;
private void FlashForm_Load(object sender, EventArgs e)
{
    //Handle this event to get the frame count.
    axShockwaveFlash1.OnReadyStateChange += new AxShockwaveFlashObjects._IShockwaveFlashEvents_OnReadyStateChangeEventHandler(axShockwaveFlash1_OnReadyStateChange);
    //Load the movie
    axShockwaveFlash1.LoadMovie(0, _moviePath);            
    axShockwaveFlash1.Loop = false;
    _timer.Interval = 100;
    _timer.Tick += new EventHandler(_timer_Tick);
    _timer.Start();
    axShockwaveFlash1.Play();
    _movieStartTime = DateTime.Now;
}
void axShockwaveFlash1_OnReadyStateChange(object sender, AxShockwaveFlashObjects._IShockwaveFlashEvents_OnReadyStateChangeEvent e)
{
    //"state = 4" means the movie loading is finished.
    if (e.newState == 4 && _frameCount == 0)
    {                
        //Get the frame count.
        _frameCount = axShockwaveFlash1.TotalFrames;
    }
}
void _timer_Tick(object sender, EventArgs e)
{
    if (_frameCount != 0)
    {
        if (_lastFrame == _frameCount - 1)
        {
            //The frame is the last one. In other words, the movie playing finishes.
            //Stop the timer.
            _timer.Stop();
            //Get the movie playing time.
            TimeSpan time = DateTime.Now - _movieStartTime;
            //Show the message.
            MessageBox.Show(string.Format("Playing stops. Movie Length: {0}s", time.Milliseconds / 1000.0));

        }
        else
        {
            //Save the current frame index.
            _lastFrame = axShockwaveFlash1.FrameNum;
        }
    }
}
The link below shows how to use Flash Player 8 External API which can provide more control on the flash playing:
http://www.codeproject.com/KB/audio-video/flashexternalapi.aspx.

Let me know if this does not help.
Aland Li




Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Wednesday, September 09, 2009 6:09 AM

You can use google to search for other answers

Custom Search

More Threads

• Visual Studio .NET 2003
• Datagridviewcombobox key up event
• Form Refresh
• How to go to the desired line in a textBox?
• Performance and BackgroundWorker
• Saving a word document: The document saves blank with no data.
• View Code Button
• Question about customizing display of a ListBox
• How to draw clickable text?
• connection string on froms