Search code examples
pythonhtmlflaskweb-applicationshtml5-audio

Getting HTML5 audio "currentTime" and "duration" into Python


I am using an HTML5 audio player to play audio content in a python/flask web application. I can display the current time and duration just fine on my web page, but now I want to get the current time of playback when a submit button is clicked. I also want to get the duration of the audio file.

How do I get these two pieces of information into Python? Do I need to pass it into a form (e.g., DecimalField from WTForms)? Is it a task for Beautiful Soup? I'm not quite sure what to do. I have reviewed many other questions, but they all seem to be about displaying the data, not passing it into Python so it can be manipulated.

FWIW, I am using Python, Flask, SQLAlchemy, HTML....

Thanks in advance!


Solution

  • I solved this issue. What I did was use javascript to obtain the currentTime of the html audio file upon click of a button and pass the value to a hidden html input field on a flask form. Then on another button click I submit the value to Python. I'm sure this solution is specific to my application, but I'm happy to answer questions if others have trouble.