简体   繁体   English

将 HTML5 音频“currentTime”和“duration”导入 Python

[英]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.我正在使用 HTML5 音频播放器在 python/flask web 应用程序中播放音频内容。 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?如何将这两条信息导入 Python? Do I need to pass it into a form (eg, DecimalField from WTForms)?我是否需要将其传递到表单中(例如,WTForms 中的 DecimalField)? 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.我已经查看了许多其他问题,但它们似乎都是关于显示数据,而不是将其传递到 Python 中以便对其进行操作。

FWIW, I am using Python, Flask, SQLAlchemy, HTML.... FWIW,我正在使用 Python、Flask、SQLAlchemy、HTML ....

Thanks in advance!提前致谢!

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.我所做的是使用 javascript 在单击按钮时获取 html 音频文件的 currentTime,并将值传递给 Flask 表单上的隐藏 html 输入字段。 Then on another button click I submit the value to Python.然后在另一个按钮上单击我将值提交给 Python。 I'm sure this solution is specific to my application, but I'm happy to answer questions if others have trouble.我确定此解决方案特定于我的应用程序,但如果其他人遇到问题,我很乐意回答问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM