0
Good afternoon!
I’m trying to perform a seemingly simple task, which is to run an audio player on an HTML page using an app made in Flask, but I can’t get the player to load the audio.
PYTHON APP:
# -*- coding: utf-8 -*-
#/usr/bin/python3
import os, sys
from flask import Flask, render_template
app = Flask(__name__, template_folder=os.path.abspath("templates"))
path_music = os.getenv("HOME") + "/project/musics/"
@app.route("/", methods=["GET"])
def index():
return render_template("index.html", music=path_music+"music.mp3")
if __name__ == "__main__":
app.run(debug=True, port=8080)
HTML file:
<!DOCTYPE html>
<html lang="pt-br">
<head>
<title>Sound Music</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<audio controls preload="metadata" id="tagAudio" style="width: 99%">
<source src="{{music}}" type="audio/mpeg">
Your browser does not support the audio tag.
</audio>
<!--
<audio controls preload="metadata" id="tagAudio" style="width: 99%">
<source src="/home/michael/project/musics/music.mp3" type="audio/mpeg">
Your browser does not support the audio tag.
</audio>
-->
</body>
</html>
I did some tests running the index.html file directly by Firefox removing the syntax used by Flask and the audio is loaded.
Someone once had this problem can give me a strength ?
Thanks in advance!
Thanks man! You saved me for the second time!
– Michael Mattos
I have another POST that with your help I managed to solve my problem, I just needed to finish it, I believe I do not have permission to do such operation, follow the link: https://answall.com/questions/466193/herdar-m%C3%b3dulos-e-vari%C3%a1veis-de-initialize%C3%A7%C3%a3o-in-a-script-python-to-another-scrip
– Michael Mattos
If the answer solved your problem, just mark the answer as accepted - no more "finish". In the case of the other post, you took the tips I left, and described what worked and marked as accepted - not the most common, but is perfectly valid.
– jsbueno