0

我需要在 C# 应用程序中播放各种 swf 文件。

他们似乎开始玩得很好,但第一次尝试暂停它没有效果,如果我再试一次,面板就会变白。

我正在使用的代码如下。

倒带和前进也没有效果。

任何意见或帮助将不胜感激。

大卫奈特

namespace MyUI
{
    public partial class ABWithSWF : MyAbstractABFrm
    {
        // Keep Track of whats happening
        enum StateOfPlay {NotSet, Playing, Paused };

        private AxShockwaveFlashObjects.AxShockwaveFlash axShockwaveFlashCube = new AxShockwaveFlashObjects.AxShockwaveFlash();

        StateOfPlay playState = StateOfPlay.NotSet;

        public ABWithSWF()
        {
            InitializeComponent();
            pnlSwf.Controls.Add(axShockwaveFlashCube);
            axShockwaveFlashCube.Dock = DockStyle.Fill;
        }

        // One button that is either play or pause
        private void btnPlay_Click(object sender, EventArgs e)
        {
            // File to play
            string path = string.Format(@"{0}\graphical summary.swf", Utils.GetSWFPath());

            switch (playState)
            {
                case StateOfPlay.Paused:
                    axShockwaveFlashCube.Play();
                    btnPlay.ImageIndex = 3;
                    playState = StateOfPlay.Playing;
                    break;
                case StateOfPlay.Playing:
                    axShockwaveFlashCube.StopPlay();
                    btnPlay.ImageIndex = 4;
                    playState = StateOfPlay.Paused;
                    break;
                case StateOfPlay.NotSet:
                    axShockwaveFlashCube.LoadMovie(0, path);
                    axShockwaveFlashCube.Play();
                    btnPlay.ImageIndex = 4;
                    playState = StateOfPlay.Playing;
                    break;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            axShockwaveFlashCube.Rewind();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            axShockwaveFlashCube.Forward();
        }
    }
}
4

1 回答 1

1

我刚刚在 c# 中开发了一个项目,将 Flash 对象嵌入到 WPF UserControl 中,它必须嵌入 Windows Forms UserControl 才能播放它。

所以,我的经验是axShockwaveFlashObjects 的Stop()方法实际上是在暂停电影,而Play() 实际上是在恢复电影(也正在启动它)。

这是我在 Windows 窗体 UserControl 中用于播放、暂停、恢复和停止 swf 对象的代码:

    /// <summary>
    /// Starts playing the movie, or resumes
    /// it if it is paused.
    /// </summary>
    public void Play()
    {
        Stop();
        flash_control.Play();
    }

    /// <summary>
    /// Pauses the movie. To resume it, 
    /// call <see cref="Play()"/>.
    /// </summary>
    public void Pause()
    {
        flash_control.Stop();
    }

    /// <summary>
    /// Stops playing the movie
    /// </summary>
    public void Stop()
    {
        flash_control.Stop();
        flash_control.FrameNum = 0;
    }
于 2011-05-06T11:33:04.183 回答