简体   繁体   English

上传到Firebase存储时如何使用Cloud Functions for FIrebase获取mp3文件的持续时间

[英]How to get the duration of a mp3 file using Cloud Functions for FIrebase when uploaded to firebase storage

I am in the process of building a music library for a dance app. 我正在为舞蹈应用程序建立音乐库。 Currently I have the Cloud Function automatically create an database instance when a mp3 file is uploaded to Firebase storage, I still need to fetch the duration of that mp3 file in seconds somehow and store that info in database. 当前,当将mp3文件上传到Firebase存储时,云功能可以自动创建数据库实例,我仍然需要以秒为单位获取该mp3文件的持续时间,并将该信息存储在数据库中。 I am new to javascript and first time doing node.js, some sources point to using the mp3 metadata which I have no experience playing with either. 我是javascript的新手,也是第一次使用node.js,一些消息源指向使用我没有经验的mp3元数据。 Some help would be much appreciated. 一些帮助将不胜感激。

The easiest way to do this would be have your cloud function download each MP3 file, open it via some MP3-reading library, and get the length using some library, like mp3-duration . 最简单的方法是让您的云函数下载每个MP3文件,通过一些MP3读取库将其打开,然后使用诸如mp3-duration类的库来获取长度。

The main problem here is that downloading the entire MP3 just to calculate its duration is something of a waste of bandwidth. 这里的主要问题是,下载整个MP3只是为了计算其持续时间是浪费带宽。 You could probably improve on that, but doing so would probably be somewhat complex unless MP3 files happen to conveniently list their duration somewhere in the header (which I don't think is the case, but I'm not very familiar with the format). 您可能会对此进行改进,但这样做可能会有些复杂,除非MP3文件碰巧在标头中的某个位置方便地列出了它们的持续时间(我认为不是这种情况,但我对格式不是很熟悉) 。

It might be better to have whatever tool is uploading the objects calculate the duration locally and then add a piece of custom metadata to the object being uploaded that indicates its duration. 最好使用任何正在上载对象的工具,在本地计算持续时间,然后向正在上载的对象添加一段指示其持续时间的自定义元数据。 The custom metadata will be available to the cloud function, which can them make use of it. 自定义元数据将对云功能可用,他们可以利用它。

暂无
暂无

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

相关问题 使用 Firebase Cloud Functions 将文件上传到 Firebase 存储时出错 - Error while uploading file to Firebase Storage using Firebase Cloud Functions 使用http cloud云功能从Firebase云存储下载文件时,没有此类文件或目录 - no such file or directory when downloading a file from firebase cloud storage using http cloud cloud functions 从使用 Cloud Functions 上传的文件中获取下载 URL for Firebase - Get Download URL from file uploaded with Cloud Functions for Firebase 使用下载 url 和 Cloud Functions 从 Firebase 存储中删除文件 - Delete a file from firebase storage using download url with Cloud Functions 使用Cloud Functions REST API请求将文件存储在Firebase存储中 - Store file in Firebase Storage using Cloud Functions REST API request Firebase:云函数+存储读取文件 - Firebase: Cloud Functions + Storage Read File 如何使用 Cloud Function 从 Cloud Storage 获取 Firebase 的 object? - How to get object from Cloud Storage for Firebase using Cloud Function? 使用云功能创建pdf文件并将其上传到firebase存储? (可以上传本地文件,但不能从云功能上传) - Create and upload pdf file to firebase storage using cloud functions? (can upload locally file, but not from cloud functions) 如何使用 Cloud Functions 中的“onFinalize”将 300Mb JSON 文件从 Firebase 存储导入数据库? - How to import 300Mb JSON file from Firebase Storage to Database using 'onFinalize' in Cloud Functions? 如何使用Firebase云功能Node.js访问Firebase存储 - How to access Firebase storage with Firebase cloud functions Node.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM