Reputation: 4214
I am developing an app in Django.
I have an mp3 file saved in the directory my_project/static/sounds/1607.mp3
I have a script.py
file located in my_project/my_app/my_folder
How can I tell my Django to play it at the end of a script.py
?
Upvotes: 1
Views: 951
Reputation: 4214
You can do it with playsound module.
This is a (inefficient) way to indicate Django the directory in which is the file you want to play:
from playsound import playsound
import os
from django.contrib.staticfiles import finders
result = finders.find('static/sounds/1607.mp3')
searched_locations = finders.searched_locations
sound_dir = os.path.join(searched_locations[0]+r'\sounds\1607.mp3')
playsound(sound_dir)
print("Sound just played!")
Upvotes: 0