1

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?

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Tms91
  • 3,456
  • 6
  • 40
  • 74

2 Answers2

1

Is it ok for you to save the mp3 in a model as FileField ? By this way, you can store the file in the required location using ' upload_to ' too.

And more specific answer to your question: You can try VLC. Hope this helps

Srijwal R
  • 552
  • 9
  • 16
0

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!")
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Tms91
  • 3,456
  • 6
  • 40
  • 74
  • 1
    Check out [this](https://stackoverflow.com/a/17738606/9733868) if you are looking for including your static files inside your code. – Pedram Parsian Nov 26 '19 at 11:18