zoukankan      html  css  js  c++  java
  • 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:WINDOWSsystem32MacromedFlashFlash32_18_0_0_203.ocx -u
     * Regsvr32 C:WINDOWSsystem32MacromedFlashFlash32_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)
            {
    
            }
    
        }
    }
    

      

  • 相关阅读:
    Vue之axios基础使用
    Vue + Spring Boot 项目实战(二):使用 CLI 搭建 Vue.js 项目
    解决:'webpack-dev-server' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
    CentOS root用户修改只读文件时提示加! 解决办法
    CentOS 7 源码编译安装 Redis
    CentOS安装Jdk并配置环境变量
    Vue + Spring Boot 项目实战(一):项目简介
    druid 数据源 使用属性文件的一个坑
    scala 学习笔记(07) 一等公民的函数
    linux:手动校准系统时间和硬件CMOS时间
  • 原文地址:https://www.cnblogs.com/geovindu/p/4646074.html
Copyright © 2011-2022 走看看