csharp: Flash Player play *.flv file in winform

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 forth
            XmlNodeList 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 forth
            XmlNodeList 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)
        {

        }

    }
}

  

时间: 2024-10-11 14:57:39

csharp: Flash Player play *.flv file in winform的相关文章

Install Adobe Flash Player 11.2 on CentOS/RHEL 7/6/5, Fedora 20/19

Adobe Flash Player are very useful for watching videos in web browser online. Without flash player most of the videos will not play in your browser. This article will help you to install Adobe flash player plugin for your browsers in CentOS 6/5, Redh

centos6.5 firefox升级 flash player安装 adblock plus广告屏蔽插件安装

firefox升级 1.到官网https://www.mozilla.org/en-US/firefox/new/?from=getfirefox上下载最新的firefox版本,我下载的是firefox-33.1.1.tar.bz2 2.删除原有的Firefox 浏览器 1 #yum erase firefox 也可以使用rpm的形式删除 3.解压到你希望安装的目录,例如我的是/usr/local,解压后会生成一个firefox的文件夹 1 #tar -jxvf firefox-33.1.1.t

ubuntu下chromium 安装flash player

原文地址 :http://blog.sina.com.cn/s/blog_858820890102v63w.html 不记得从今年什么时候起,Chromium 不再支持 Netscape plugin API (NPAPI),官方软件仓库中的 flashplugin 已经无法工作. 浏览器不支持flash怎么能用?必须解决之. 1.网上搜索了半天,大多是按照浏览器提示下载Adobe Flash Player 插件,然后解压出libflashplayer.so,把libflashplayer.so

html文件中flash视频格式(flv、swf)文件的嵌入方法

flash文件的格式:.FLV 和 .SWF flash视频格式有两种扩展名可以使用:.flv和.swf.他们有什么不同呢? (1)一个.flv文件(flash视频)是基于图片的视频流和音频.如果你在运行一个流服务,flv将是一个好的选择.上游条件是,这个文件的任何部分可以被客户终端访问,并且任何时间不会等待下载.话又说回来了,运行一个流服务待价昂贵. (2).swf也是Macromedia Flash文件格式,是一个完整的视频-音频文件,并具有脚本和其它更多的.这将有利于HTTP(渐进式)下载

linux下为firfox安装flash player

1.去官网下载×.tar.gz包,如:flash_player_npapi_linux.x86_64.tar.gz 2.解压 tar -zxvf flash_player_npapi_linux.x86_64.tar.gz 3.安装方法可以参照,解压文件中的readme.txt Installing using the plugin tar.gz: o Unpack the plugin tar.gz and copy the files to the appropriate location.

Adobe Flash Player

FlashPlayer Translation(s): English - Espa?ol - Fran?ais - Italiano - Русский - 简体中文 Flash > Adobe Flash Player Please note that Flash will be EOL at the end of 2020 so you should migrate any use of Flash to HTML5 as soon as possible. Adobe Flash Pla

解决浏览器Adobe Flash Player不是最新版本问题

方法/步骤 首先打开浏览器,登录网址[http://www.adobe.com/cn/],步骤截图如下所示:   点击[菜单],下拉打开的列表,找到并点击[Adobe Flash Player],步骤截图如下所示:   点击页面上的[您是否有其他操作系统或浏览器?]按钮,步骤截图如下所示:   根据自己的情况,先选择操作系统,需要注意的是,在选择Adobe Flash Player的版本时,一定要看准,要选择PPAPI版本的,现在谷歌浏览器已经停止支持NPAPI版本的插件了. 特别提醒,注意把那

Linux入门(9)——Ubuntu16.04安装flash player

打开网页经常提示安装flash player,不安装flash player很多网页的视频都看不了. Ubuntu16.04安装flash player 打开终端,输入: sudo apt-get install flashplugin-installer

安装Ubuntu双系统系列——为Firefox安装Adobe Flash Player

使用环境:OS:Ubuntu 12.04 LTSBrowser: Firefox 12.0Adobe Flash Player: install_flash_player_11_linux.x86_64.tar.gz 安装方法:1. 下载Adobe Flash Player:请从Adobe官方下载,也可以从这个URL下载,这个URL也是官方的链接:http://fpdownload.macromedia.com/get/flashplayer/pdc/11.2.202.235/install_f