我需要在C#应用程序中播放各种swf文件。
他们似乎开始玩得很好,但试图暂停它并没有影响第一次,如果我再试一次,那么白棋会就会消失。
我正在使用的代码如下。
同时倒带&前进没有效果。
任何评论或帮助将不胜感激。
David Knight
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();
}
}
}
答案 0 :(得分:1)
我刚刚在c#中开发了一个项目,将一个flash对象嵌入到WPF UserControl中,它必须嵌入一个Windows Forms UserControl才能播放它。
所以,我的经验是停止() axShockwaveFlashObjects 的方法实际上暂停了电影而 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;
}