Esempio n. 1
0
            /// <summary>
            /// Allocates the static pointer to the CallbacksNative passed in. This is used to pass it into the CAPI.
            /// </summary>
            /// <returns>The pointer to the native callbacks.</returns>
            public static IntPtr AllocateSystemCallbacks()
            {
                if (SystemCallbacks != IntPtr.Zero)
                {
                    MLPluginLog.Error("MLMusicServiceNativeBindings.CallbacksNative.AllocateCallbacksPointer failed to allocate new callbacks pointer. Reason: Static callback pointer was already allocated, please call MLMusicServiceNativeBindings.CallbacksNative.DeallocateCallbacksPointer and try again");
                    return(IntPtr.Zero);
                }

                SystemCallbacks = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(CallbacksNative)));
                CallbacksNative callbacks = CallbacksNative.Create();

                callbacks.OnPlaybackStateChange = HandlePlaybackStateChange;
                callbacks.OnRepeatStateChange   = HandleRepeatStateChange;
                callbacks.OnShuffleStateChange  = HandleShuffleStateChange;
                callbacks.OnMetadataChange      = HandleMetadataChange;
                callbacks.OnPositionChange      = HandlePositionChange;
                callbacks.OnError        = HandleError;
                callbacks.OnStatusChange = HandleStatusChange;
                callbacks.OnVolumeChange = HandleVolumeChange;
                Marshal.StructureToPtr(callbacks, SystemCallbacks, false);
                return(SystemCallbacks);
            }