you can use this system i made, it works with url,bytes,bytes stream and local file
class Audio:
_total_audio_instances=[]
def main_audio_init():
import os
try:
from jnius import autoclass
except:
os.system("pip install jnius")
from jnius import autoclass
try:
import threading
except:
os.system("pip install threading")
Audio._autoclass=autoclass
Audio._threading=threading
def close_all_audio_instances():
for inst in Audio._total_audio_instances:
inst.stop()
inst.release()
def __init__(self,source:str,looping:bool=False):
self._class=Audio._autoclass('android.media.MediaPlayer')()
self._class.setDataSource(source)
self._class.prepare()
self._busy=0
self._position=self.get_duration()
self._class.setLooping(looping)
Audio._total_audio_instances.append(self._class)
def help(self):
h="""
Audio system_help:
init args:
<source>
-path
-url
-bytes
<looping>
-True
-False
commands:
<help>
helps you
<play>
plays the audio
<stop>
stops the audio
<get_duration>
get total audio length in seconds
<get_busy>
checks if the audio is playing
<wait>
waits for the audio to finish playing
<pause>
pauses the audio
<set_looping>
sets if the audio loops
"""
print(h)
def play(self,busy_check=True):
if busy_check:
Audio._threading.Thread(target=self._gb0,daemon=True).start()
self._class.start()
def stop(self):
self._class.stop()
def get_duration(self):
return self._class.getDuration()/1000
def get_busy(self):
if self.get_duration()==self._position:
return False
return True
def _gb0(self):
self._busy=1
dur=round(self.get_duration()*1000)
for p in range(dur):
p+=1
self._position=p/1000
time.sleep(0.001)
self._busy=0
def wait(self):
while self.get_busy():
pass
def pause(self):
self._class.pause()
def set_looping(self,a0:bool):
if a0!=True and a0!=False:
raise ValueError("invalid argument: avaiable: -True -False")
self._class.setLooping(a0)