Html5页面播放M4a音频文件
时间:2023-12-30 08:34:57 来源:[db:出处] 作者:[db:作者] 阅读:
业务场景:
手机app端录音,然后上传至后台服务器,前端从后台服务器获取录音,在PC端WEB页面播放。
实际问题:
首先app录音文件默认是m4a格式,而在PC端WEB H5页面,<audio>标签并没有明确写着支持m4a格式,如果app端生成的录音不做相关设置,而用默认设置,在H5上确实是播放不了的。
其实一开始,我没有想太多,也是想着把m4a文件转成mp3给前台用。
在网上查了一番,很多都说用jave-1.0.2.2.jar,然而其实这个包很旧,而且在windows上是可以转,但centos8上不支m4a格式转码,在系统上有兼容性问题。信我,别用它。
然后又在码库里找了比较靠谱的是这个包,这里附个链接: https://github.com/a-schild/jave2,这个包也是基于ffmpeg的,提供了支持win64、osx64、linux64的依赖,建义在maven打包时,根据开发或生产环境的不同,打包时引用相应环境的依赖。
下面附上我的m4a转mp3的java代码:
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com</groupId>
<artifactId>test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<jave.version>2.7.1</jave.version>
</properties>
<dependencyManagement>
<dependencies>
<!--录音转换,jave-all-deps 包涵了所有平台的依赖,由于打包太大,建议打包时选指定的依赖-->
<!--<dependency>-->
<!--<groupId>ws.schild</groupId>-->
<!--<artifactId>jave-all-deps</artifactId>-->
<!--<version>${jave.version}</version>-->
<!--</dependency>-->
<!--录音转换,指定平台依赖,jave-core必需指定-->
<dependency>
<groupId>it.sauronsoftware</groupId>
<artifactId>jave</artifactId>
<groupId>ws.schild</groupId>
<artifactId>jave-core</artifactId>
<version>${jave.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<!--激活profile配置,用来切换不同环境的配置-->
<profiles>
<profile>
<id>dev</id>
<properties>
<profiles.actives>dev</profiles.actives>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
<activeByDefault>false</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>ws.schild</groupId>
<artifactId>jave-nativebin-linux64</artifactId>
<version>${jave.version}</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>pro</id>
<properties>
<profiles.actives>pro</profiles.actives>
</properties>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>ws.schild</groupId>
<artifactId>jave-nativebin-linux64</artifactId>
<version>${jave.version}</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>test</id>
<properties>
<profiles.actives>test</profiles.actives>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>ws.schild</groupId>
<artifactId>jave-nativebin-win64</artifactId>
<version>${jave.version}</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
本文配套模板、静态源码可前往艾立兹素材库alisucai.com下载
发表评论
共有0条评论
扫码关注公众号
获取全套技术教程