Skip to content

SDLmixer: provide Mix_ChannelFinished working example #86

Open
@marcusva

Description

@marcusva

Originally reported by: JP LeBreton (Bitbucket: JPLeBreton, GitHub: JPLeBreton)


I'd like to create a callback when a sound finishes playing, and it doesn't appear to work like anything else I've encountered using pysdl2 so far.

http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer.html#SEC37

When I call Mix_ChannelFinished(my_func) where my_func is a standard Python function, I get this error:

#!python


ctypes.ArgumentError: argument 1: <class 'TypeError'>: expected CFunctionType instance instead of method

My attempt to give it a CFunctionType instance looks like this:

#!python

MYFUNCTYPE = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.POINTER(ctypes.c_int))
my_c_func = MYFUNCTYPE(my_python_func)
sdlmixer.Mix_ChannelFinished(my_c_func)

but this gives the error:

#!python

ctypes.ArgumentError: argument 1: <class 'TypeError'>: expected CFunctionType instance instead of CFunctionType

I'm sure I'm doing something very simple wrong here, but it's non-obvious enough that it would be nice to have an example of how to do this properly in pysdl2's excellent docs!


Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions