I've downloaded a small .mp3 file from the net using Python's requests module, like this:
file_on_disk = open(filename, 'wb')
write(downloaded_file.content)
file_on_disk.close()
Now it works fine on the disk as an MP3 file should. However, I'd like to play it using python-vlc's MediaPlayer while it's still not written to disk, i.e. from memory. However, this doesn't work:
vlc.MediaPlayer(downloaded_file.content).play()
I get a TypeError: a bytes-like object is required, not 'str'
message. I checked the type of the content and type(downloaded_file.content)
identifies it as <class 'bytes'>, not str. The same MediaPlayer nicely plays the file once it's saved to the disk. What am I missing here, and how can I convert the file in-memory to a format that vlc.MediaPlayer is able to play?
(I'm a beginner so the answer might be obvious, but it keeps eluding me.)
edit: my full code is actually:
import requests, vlc
downloaded_file = requests.get('https://cdn.duden.de/_media_/audio/ID4111733_460321137.mp3')
from vlc import MediaPlayer
MediaPlayer(downloaded_file.content).play()