查看完整版本: [-- C# VS2022 用APlayerCaller.dll调用无法播放 --]

APlayer 开发者论坛 -> APlayer 讨论区 -> C# VS2022 用APlayerCaller.dll调用无法播放 [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

hanlinhe110 2023-04-10 00:36

C# VS2022 用APlayerCaller.dll调用无法播放

由于2022不支持com 所以采用dll调用的方式,根据以下代码可以运行,
可以获得一个句柄,依据句柄打开文件也提示true。但是不现实也不播放任何东西。
VS2022 x86环境可以运行。
  1. 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");

            }
        }
    }



aplayer 2023-04-12 12:50
如果是这样说明缺少解码器,你把完整 Codecs 下载下来放在 APlayer.dll 所在目录试试。

hanlinhe110 2023-05-16 15:38
目前问题已解决,与编码无关,与C#代码有关系,有些用法不太会用导致无法播放。  目前环境VS2022  直接调用DLL就可以进行播放,有需要的可以加我Q1580007242.
[attachment=3431][attachment=3430]

qq270081366 2023-06-14 10:42
可以64位编译吗?

zjf1998 2023-08-02 13:45
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 2023-08-02 13:46
qq270081366:可以64位编译吗? (2023-06-14 10:42) 

我试过了,可以的

ankeyliu 2024-03-25 17:16
zjf1998:我试过了,可以的 (2023-08-02 13:46) 

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

q3943 2024-05-10 14:21
zjf1998:我试过了,可以的 (2023-08-02 13:46) 

可以发个源码给我看看吗394336949@qq.com,感谢感谢


查看完整版本: [-- C# VS2022 用APlayerCaller.dll调用无法播放 --] [-- top --]


Powered by phpwind v8.7 Code ©2003-2011 phpwind
Time 0.012004 second(s),query:0 Gzip enabled