using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using AxShockwaveFlashObjects;/** VS2005在添加Shockwave时很多人都碰到一个这个问题,就是会说ActiveX注册失败* 先要用Regsvr32来注册ActiveX(运行:Regsvr32 控件名)-u为卸载参数* Regsvr32 C:\WINDOWS\system32\Macromed\Flash\Flash32_18_0_0_203.ocx -u* Regsvr32 C:\WINDOWS\system32\Macromed\Flash\Flash32_18_0_0_203.ocx* 在VS2005下项目-属性-生成-目标平台改为x86在选择生成-清理解决方案与重新生成解决方案直到资源管理器的引用下的AxShochwaveFlashObj的黄色感叹号消失*/
namespace AdobeFlashPlayDemo
{/// <summary>/// http://www.codeproject.com/Articles/12010/Fun-with-C-and-the-Flash-Player-External-API/// http://www.codeproject.com/Articles/10863/Flash-and-NET-with-FlashRemoting/// http://www.codeproject.com/Articles/15742/Multiple-File-Upload-With-Progress-Bar-Using-Flash/// http://www.codeproject.com/Articles/12928/Flash-GUI-for-Your-EXE-Using-Minimalistic-Approach/// </summary>public partial class FLVPlayer : Form{// private StatusBarPanel fileNameStatusBarPanel;/// <summary>/// /// </summary>public FLVPlayer(){InitializeComponent();//this.fileNameStatusBarPanel = new System.Windows.Forms.StatusBarPanel();try{axShockwaveFlash1.LoadMovie(0, Application.StartupPath + "\\player.swf");axShockwaveFlash1.FlashCall += new _IShockwaveFlashEvents_FlashCallEventHandler(flashPlayer_FlashCall);}catch (Exception ex){ExceptionUtilities.DisplayException("Unable to load SWF video player, please verify you have Flash Player 8 installed and try again.");this.Dispose();}}/// <summary>/// /// </summary>/// <param name="moviePath"></param>public FLVPlayer(string moviePath): this(){this.LoadVideo(moviePath);}/// <summary>/// /// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void Form1_Load(object sender, EventArgs e){}/// <summary>/// /// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void button1_Click(object sender, EventArgs e){openVideoDialog = new OpenFileDialog();openVideoDialog.Filter = "*.flv|*.flv";openVideoDialog.Title = "Select a Flash Video file...";openVideoDialog.Multiselect = false;openVideoDialog.RestoreDirectory = true;if (openVideoDialog.ShowDialog() == DialogResult.OK){LoadVideo(openVideoDialog.FileName);}}/// <summary>/// /// </summary>/// <param name="videoPath"></param>private void LoadVideo(string videoPath){fileNameStatusBarPanel.Text = videoPath;axShockwaveFlash1.CallFunction("<invoke name=\"loadAndPlayVideo\" returntype=\"xml\"><arguments><string>" + videoPath + "</string></arguments></invoke>");}/// <summary>/// /// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void FLVPlayer_DragDrop(object sender, DragEventArgs e){string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);if (fileNameStatusBarPanel.Text != files[0]){LoadVideo(files[0]);}}/// <summary>/// /// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void FLVPlayer_DragEnter(object sender, DragEventArgs e){if (e.Data.GetDataPresent(DataFormats.FileDrop, false)){e.Effect = DragDropEffects.All;}}/// <summary>/// /// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void FLVPlayer_DragLeave(object sender, EventArgs e){}/// <summary>/// /// </summary>/// <param name="width"></param>/// <param name="height"></param>public void ResizePlayer(int width, int height){axShockwaveFlash1.Width = width;axShockwaveFlash1.Height = height;videoPlaceholder.Width = width;videoPlaceholder.Height = height;}private void flashPlayer_FlashCall(object sender, _IShockwaveFlashEvents_FlashCallEvent e){XmlDocument document = new XmlDocument();document.LoadXml(e.request);// Since I have only one call back I just grab the arguments and call// the function. This needs to be made much more flexible when there are// multiple call backs going back and forthXmlNodeList list = document.GetElementsByTagName("arguments");ResizePlayer(Convert.ToInt32(list[0].FirstChild.InnerText), Convert.ToInt32(list[0].ChildNodes[1].InnerText));}/// <summary>/// /// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void axShockwaveFlash1_FlashCall(object sender, _IShockwaveFlashEvents_FlashCallEvent e){XmlDocument document = new XmlDocument();document.LoadXml(e.request);// Since I have only one call back I just grab the arguments and call// the function. This needs to be made much more flexible when there are// multiple call backs going back and forthXmlNodeList list = document.GetElementsByTagName("arguments");ResizePlayer(Convert.ToInt32(list[0].FirstChild.InnerText), Convert.ToInt32(list[0].ChildNodes[1].InnerText));}private void axShockwaveFlash1_Enter(object sender, EventArgs e){}}
}