Closed gulaki closed 1 year ago
After doing some research into ctypes
see this stakoverflow question, this is what worked
class VlcBytes:
def __init__(self):
self._instance = vlc.Instance()
self._player = self._instance.media_player_new()
self._bytesio = None
self._media = None
self._stream_provider_obj = None
self._stream_provider_ptr = None
def play(self):
self._player.play()
def pause(self):
self._player.pause()
def load_bytes_media(self, bytesio):
self._bytesio = bytesio
self._stream_provider_obj = vlc.ctypes.py_object(self._bytesio)
self._stream_provider_ptr = vlc.ctypes.byref(self._stream_provider_obj)
self._media = self._instance.media_new_callbacks(
media_open_cb,
media_read_cb,
media_seek_cb,
media_close_cb,
self._stream_provider_ptr
)
self._player.set_media(self._media)
def load_mrl_media(self, filename):
self._media = self._instance.media_new(filename)
self._player.set_media(self._media)
vlcp = VlcBytes()
vlcp.load_mrl_media('drums.mid')
vlcp.play()
time.sleep(100)
This issue can be closed after moderator acknowledgement.
Thanks for documenting the issue and the solution. If you manage to make a simple example file, it could be put in the examples
directory of the python-vlc sources, so that it is more easily findable by other people.
I am constructing some MIDI data as a
io.BytesIO
object in memory. To load these into VLC as media for play I adapted the media callback functions adapted from the provided examples from the repo. In this example, I am just reading a midi file on disk and writing the data into aBytesIO
object.Then I have the vlc instance and player in the global scope
I am loading the MIDI data into an
io.BytesIO
object with the following code.Then setting up the callbacks to the new media type
This works well and the midi file plays. However, I actually need to play various MIDI data constructed in memory, so I pass the
BytesIO
object to a function to return the media object, that I then add to the player.This does not work and I get a SEGFAULT as
If instead of returning the media, I
set_media
andplay
inside the function, then I getI also tried
media_open_fd
thinkingBytesIO
are file like objects. But that doesn't work either. What is the correct way to handle this problem?