• 2220阅读
  • 7回复

C# VS2022 用APlayerCaller.dll调用无法播放 [复制链接]

上一主题 下一主题
离线hanlinhe110
 

只看楼主 倒序阅读 使用道具 楼主  发表于: 2023-04-10
由于2022不支持com 所以采用dll调用的方式,根据以下代码可以运行,
可以获得一个句柄,依据句柄打开文件也提示true。但是不现实也不播放任何东西。
VS2022 x86环境可以运行。
  1. using Microsoft.VisualBasic.Logging;
  2. using System;
  3. using System.Diagnostics;
  4. using System.Runtime.InteropServices;
  5. namespace MainAplayer
  6. {
  7.     public partial class Form1 : Form
  8.     {
  9.         public delegate void fun0();//声明委托
  10.         public delegate void fun1(long l1);//声明委托
  11.         public delegate void fun2(long l1, long l2);//声明委托
  12.         public delegate void fun3(long l1, long l2, long l3);//声明委托
  13.         public delegate void funstr(string l1);//声明委托
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.         private void Form1_Load(object sender, EventArgs e)
  19.         {
  20.         }
  21.         [DllImportAttribute("APlayerCaller.dll", EntryPoint = "APlayer_Create", SetLastError = true)]
  22.         public static extern int APlayer_Create
  23.         (
  24.             long hParent,
  25.             long x,
  26.             long y,
  27.             long nWidth,
  28.             long nHeight,
  29.             long OnMessage,
  30.             long OnStateChanged,
  31.             long OnOpenSuccess,
  32.             long OnSeekCompleted,
  33.             long OnBuffer,
  34.             long OnVideoSizeChanged,
  35.             long ondownloadcodec,
  36.             long OnEvent
  37.         );
  38.         [DllImportAttribute("APlayerCaller.dll", EntryPoint = "APlayer_OpenW", CharSet =CharSet.Unicode, SetLastError =true)]
  39.         public static extern bool APlayer_OpenW(long hand, string url);
  40.         [DllImportAttribute("APlayerCaller.dll", EntryPoint = "APlayer_Play", SetLastError = true)]
  41.         public static extern bool APlayer_Play(long hand);
  42.         [DllImportAttribute("APlayerCaller.dll", EntryPoint = "APlayer_SetCustomLogo", SetLastError = true)]
  43.         public static extern bool APlayer_SetCustomLogo(long hand,long logo);
  44.         private void button1_Click(object sender, EventArgs e)
  45.         {
  46.             fun3 DOnMessage = new fun3(OnMessage);
  47.             IntPtr POnMessage = Marshal.GetFunctionPointerForDelegate(DOnMessage);
  48.             fun2 DOnStateChanged = new fun2(OnStateChanged);
  49.             IntPtr POnStateChanged = Marshal.GetFunctionPointerForDelegate(DOnStateChanged);
  50.             fun0 DOnOpenSuccess = new fun0(OnOpenSucceeded);
  51.             IntPtr POnOpenSuccess = Marshal.GetFunctionPointerForDelegate(DOnOpenSuccess);
  52.             fun1 DOnSeekCompleted = new fun1(OnSeekCompleted);
  53.             IntPtr POnSeekCompleted = Marshal.GetFunctionPointerForDelegate(DOnSeekCompleted);
  54.             fun1 DOnBuffer = new fun1(OnBuffer);
  55.             IntPtr POnBuffer = Marshal.GetFunctionPointerForDelegate(DOnBuffer);
  56.             fun0 DOnVideoSizeChanged = new fun0(OnVideoSizeChanged);
  57.             IntPtr POnVideoSizeChanged = Marshal.GetFunctionPointerForDelegate(DOnVideoSizeChanged);
  58.             funstr DOnDownloadCodec = new funstr(OnDownloadCodec);
  59.             IntPtr POnDownloadCodec = Marshal.GetFunctionPointerForDelegate(DOnDownloadCodec);
  60.             fun2 DOnEvent = new fun2(OnEvent);
  61.             IntPtr POnEvent = Marshal.GetFunctionPointerForDelegate(DOnEvent);
  62.             //创建代码
  63.             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);
  64.             MessageBox.Show("句柄是:" + HAplayer.ToString());
  65.             //APlayer_SetCustomLogo(HAplayer, -1);
  66.             bool isOpen = APlayer_OpenW(HAplayer, "D:\\A\\1.mp4");
  67.            MessageBox.Show("isOpen:" + isOpen);
  68.            // APlayer_Play(HAplayer);
  69.         }
  70.         void OnMessage(long l1, long l2, long l3)
  71.         {
  72.             //方法体
  73.             Debug.WriteLine(l1 + "=OnMessage=" + l2);
  74.         }
  75.         void OnStateChanged(long l1, long l2)
  76.         {
  77.             Debug.WriteLine(l1 + "=OnStateChanged=" + l2);
  78.         }
  79.         void OnOpenSucceeded()
  80.         {
  81.             Debug.WriteLine("=OnOpenSucceeded=");
  82.         }
  83.         void OnSeekCompleted(long l1)
  84.         {
  85.             Debug.WriteLine(l1 + "=OnSeekCompleted=");
  86.         }
  87.         void OnBuffer(long l1)
  88.         {
  89.             Debug.WriteLine(l1 + "=OnBuffer=");
  90.         }
  91.         void OnVideoSizeChanged()
  92.         {
  93.             Debug.WriteLine( "=OnVideoSizeChanged=" );
  94.         }
  95.         void OnEvent(long nEventCode, long nEventParam)
  96.         {
  97.             Debug.WriteLine(nEventCode + "=OnEvent=" + nEventParam);
  98.         }
  99.         void OnDownloadCodec(string l1)
  100.         {
  101.             Debug.WriteLine(l1 + "==OnDownloadCodec");
  102.         }
  103.     }
  104. }


离线aplayer

只看该作者 沙发  发表于: 2023-04-12
如果是这样说明缺少解码器,你把完整 Codecs 下载下来放在 APlayer.dll 所在目录试试。
离线hanlinhe110

只看该作者 板凳  发表于: 2023-05-16
目前问题已解决,与编码无关,与C#代码有关系,有些用法不太会用导致无法播放。  目前环境VS2022  直接调用DLL就可以进行播放,有需要的可以加我Q1580007242.
离线qq270081366

只看该作者 地板  发表于: 2023-06-14
可以64位编译吗?
离线zjf1998

只看该作者 4楼 发表于: 2023-08-02
回 hanlinhe110 的帖子
hanlinhe110:目前问题已解决,与编码无关,与C#代码有关系,有些用法不太会用导致无法播放。  目前环境VS2022  直接调用DLL就可以进行播放,有需要的可以加我Q1580007242.
[图片][attachment=34 .. (2023-05-16 15:38) 

我请教了楼主,对比了代码,发现是回调的声明不正确导致的问题,代码修正如下:
  
//   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 delegate void fun0();//声明委托
        public delegate void fun1(int l1);//声明委托
        public delegate void fun2(int l1, int l2);//声明委托
        public delegate void fun3(int l1, int l2, int l3);//声明委托
        public delegate void funstr(string l1);//声明委托


        void OnMessage(int l1, int l2, int l3)
        {
            //方法体
            //Debug.WriteLine(l1 + "=OnMessage=" + l2);
        }
        void OnStateChanged(int l1, int l2)
        {
            Debug.WriteLine(l1 + "=OnStateChanged=" + l2);
            if (l2 == 6)
            {
                PlayButton.Text = "播放";
            }
        }
        void OnOpenSucceeded()
        {
            Debug.WriteLine("=OnOpenSucceeded=");
        }
        void OnSeekCompleted(int l1)
        {
            Debug.WriteLine(l1 + "=OnSeekCompleted=");
        }
        void OnBuffer(int l1)
        {
            Debug.WriteLine(l1 + "=OnBuffer=");
        }
        void OnVideoSizeChanged()
        {
            Debug.WriteLine("=OnVideoSizeChanged=");
        }
        void OnEvent(int nEventCode, int nEventParam)
        {
            //Debug.WriteLine(nEventCode + "=OnEvent=" + nEventParam);
        }
        void OnDownloadCodec(string l1)
        {
            Debug.WriteLine(l1 + "==OnDownloadCodec");

        }
离线zjf1998

只看该作者 5楼 发表于: 2023-08-02
回 qq270081366 的帖子
qq270081366:可以64位编译吗? (2023-06-14 10:42) 

我试过了,可以的
离线ankeyliu

只看该作者 6楼 发表于: 03-25
回 zjf1998 的帖子
zjf1998:我试过了,可以的 (2023-08-02 13:46) 

能把这个demo 的源码发我一份吗,2849199918@qq.com,感谢
离线q3943

只看该作者 7楼 发表于: 05-10
回 zjf1998 的帖子
zjf1998:我试过了,可以的 (2023-08-02 13:46) 

可以发个源码给我看看吗394336949@qq.com,感谢感谢
1
快速回复
限100 字节
批量上传需要先选择文件,再选择上传
 
上一个 下一个