csharp: Flash Player play *.flv file in winform
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | 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) { } } } |
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
分类:
CSharp code
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!