- initial import
This commit is contained in:
52
src/utils_bt_audio.py
Executable file
52
src/utils_bt_audio.py
Executable file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
|
||||
import os
|
||||
import time
|
||||
import utils
|
||||
import typing
|
||||
import subprocess
|
||||
|
||||
|
||||
def start_PA() -> bool:
|
||||
# Ensure pulseaudio is available
|
||||
retcode = os.system('pulseaudio --check')
|
||||
if retcode == 0:
|
||||
utils.log('Stopping pulse audio...')
|
||||
retcode = os.system('pulseaudio --kill')
|
||||
if retcode != 0:
|
||||
utils.log(f'pulseaudio failed to stop, exit code: {retcode}')
|
||||
# return False
|
||||
|
||||
# Wait 5 second
|
||||
utils.log('Waiting 5s for pulseaudio stop...')
|
||||
time.sleep(5.0)
|
||||
|
||||
utils.log('Starting pulseaudio...')
|
||||
retcode = os.system('pulseaudio --start')
|
||||
if retcode != 0:
|
||||
utils.log(f'pulseaudio failed to start, exit code: {retcode}')
|
||||
return False
|
||||
|
||||
# Check if module-bluetooth-discover is available
|
||||
retcode, output = subprocess.getstatusoutput('/usr/bin/pacmd list modules | /usr/bin/grep module-bluetooth-discover')
|
||||
if retcode == 0:
|
||||
if 'module-bluetooth-discover' in output:
|
||||
utils.log('PA module-bluetooth-discover is loaded already.')
|
||||
return True
|
||||
else:
|
||||
utils.log('PA module-bluetooth-discover is not loaded yet.')
|
||||
|
||||
utils.log('Attempt to load module-bluetooth-discover...')
|
||||
retcode = os.system('pacmd load-module module-bluetooth-discover')
|
||||
if retcode != 0:
|
||||
utils.log(f'Failed to load module-bluetooth-discover, exit code: {retcode}')
|
||||
return False
|
||||
else:
|
||||
print('...success.')
|
||||
|
||||
return True
|
||||
|
||||
if __name__ == '__main__':
|
||||
start_PA()
|
||||
|
||||
Reference in New Issue
Block a user