hanlinhe110 |
2023-04-10 00:36 |
C# VS2022 用APlayerCaller.dll调用无法播放
由于2022不支持com 所以采用dll调用的方式,根据以下代码可以运行, 可以获得一个句柄,依据句柄打开文件也提示true。但是不现实也不播放任何东西。 VS2022 x86环境可以运行。
- using Microsoft.VisualBasic.Logging;
using System; using System.Diagnostics; using System.Runtime.InteropServices;
namespace MainAplayer { public partial class Form1 : Form { public delegate void fun0();//声明委托 public delegate void fun1(long l1);//声明委托 public delegate void fun2(long l1, long l2);//声明委托 public delegate void fun3(long l1, long l2, long l3);//声明委托 public delegate void funstr(string l1);//声明委托 public Form1() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) {
}
[DllImportAttribute("APlayerCaller.dll", EntryPoint = "APlayer_Create", SetLastError = true)] public static extern int APlayer_Create ( long hParent, long x, long y, long nWidth, long nHeight, long OnMessage, long OnStateChanged, long OnOpenSuccess, long OnSeekCompleted, long OnBuffer, long OnVideoSizeChanged, long ondownloadcodec, long OnEvent );
[DllImportAttribute("APlayerCaller.dll", EntryPoint = "APlayer_OpenW", CharSet =CharSet.Unicode, SetLastError =true)] public static extern bool APlayer_OpenW(long hand, string url);
[DllImportAttribute("APlayerCaller.dll", EntryPoint = "APlayer_Play", SetLastError = true)] public static extern bool APlayer_Play(long hand);
[DllImportAttribute("APlayerCaller.dll", EntryPoint = "APlayer_SetCustomLogo", SetLastError = true)] public static extern bool APlayer_SetCustomLogo(long hand,long logo); private void button1_Click(object sender, EventArgs e) { fun3 DOnMessage = new fun3(OnMessage); IntPtr POnMessage = Marshal.GetFunctionPointerForDelegate(DOnMessage); fun2 DOnStateChanged = new fun2(OnStateChanged); IntPtr POnStateChanged = Marshal.GetFunctionPointerForDelegate(DOnStateChanged); fun0 DOnOpenSuccess = new fun0(OnOpenSucceeded); IntPtr POnOpenSuccess = Marshal.GetFunctionPointerForDelegate(DOnOpenSuccess); fun1 DOnSeekCompleted = new fun1(OnSeekCompleted); IntPtr POnSeekCompleted = Marshal.GetFunctionPointerForDelegate(DOnSeekCompleted); fun1 DOnBuffer = new fun1(OnBuffer); IntPtr POnBuffer = Marshal.GetFunctionPointerForDelegate(DOnBuffer); fun0 DOnVideoSizeChanged = new fun0(OnVideoSizeChanged); IntPtr POnVideoSizeChanged = Marshal.GetFunctionPointerForDelegate(DOnVideoSizeChanged); funstr DOnDownloadCodec = new funstr(OnDownloadCodec); IntPtr POnDownloadCodec = Marshal.GetFunctionPointerForDelegate(DOnDownloadCodec); fun2 DOnEvent = new fun2(OnEvent); IntPtr POnEvent = Marshal.GetFunctionPointerForDelegate(DOnEvent);
//创建代码 long HAplayer = APlayer_Create(panel1.Handle.ToInt32(), 0, 0, 200, 200, (long)POnMessage, (long)POnStateChanged, (long)POnOpenSuccess, (long)POnSeekCompleted, (long)POnBuffer, (long)POnVideoSizeChanged, (long)POnDownloadCodec, (long)POnEvent); MessageBox.Show("句柄是:" + HAplayer.ToString()); //APlayer_SetCustomLogo(HAplayer, -1); bool isOpen = APlayer_OpenW(HAplayer, "D:\\A\\1.mp4"); MessageBox.Show("isOpen:" + isOpen); // APlayer_Play(HAplayer); } void OnMessage(long l1, long l2, long l3) { //方法体 Debug.WriteLine(l1 + "=OnMessage=" + l2); } void OnStateChanged(long l1, long l2) { Debug.WriteLine(l1 + "=OnStateChanged=" + l2); } void OnOpenSucceeded() { Debug.WriteLine("=OnOpenSucceeded="); } void OnSeekCompleted(long l1) { Debug.WriteLine(l1 + "=OnSeekCompleted="); } void OnBuffer(long l1) { Debug.WriteLine(l1 + "=OnBuffer="); } void OnVideoSizeChanged() { Debug.WriteLine( "=OnVideoSizeChanged=" ); } void OnEvent(long nEventCode, long nEventParam) { Debug.WriteLine(nEventCode + "=OnEvent=" + nEventParam); } void OnDownloadCodec(string l1) { Debug.WriteLine(l1 + "==OnDownloadCodec");
} } }
|
|