用java做一个可视化小程序,可以录音并予以保存。

用java做一个可视化小程序,可以录音并予以保存。,第1张

import javaioByteArrayInputStream;

import javaioByteArrayOutputStream;

import javaioFile;

import javaioInputStream;

import orgeclipseswtSWT;

import orgeclipseswtwidgets;

import orgeclipseswtevents;

import javaxsoundsampledAudioFileFormat;

import javaxsoundsampledAudioFormat;

import javaxsoundsampledAudioInputStream;

import javaxsoundsampledAudioSystem;

import javaxsoundsampledDataLine;

import javaxsoundsampledSourceDataLine;

import javaxsoundsampledTargetDataLine;

public class RecordPlay {

boolean stopCapture = false; // 控制录音标志

AudioFormat audioFormat; // 录音格式

// 读取数据:从TargetDataLine写入ByteArrayOutputStream录音

ByteArrayOutputStream byteArrayOutputStream;

int totaldatasize = 0;

TargetDataLine targetDataLine;

// 播放数据:从AudioInputStream写入SourceDataLine播放

AudioInputStream audioInputStream;

SourceDataLine sourceDataLine;

private Button captureBtn;

private Button stopBtn;

private Button playBtn;

private Button saveBtn;

private Label myLabel;

private Shell shell;

private Display display;

public RecordPlay() {

super();

display = new Display();

shell = new Shell(display);

shellsetSize(350, 150);

shellsetText("录音机程序");

//

myLabel = new Label(shell, SWTNONE);

myLabelsetBounds(38, 21, 100, 18);

myLabelsetText("录音机");

// 创建按钮

captureBtn = new Button(shell, SWTNONE);

captureBtnsetBounds(30, 61, 60, 18);

captureBtnsetText("录音");

captureBtnsetEnabled(true);

stopBtn = new Button(shell, SWTNONE);

stopBtnsetBounds(100, 61, 60, 18);

stopBtnsetText("停止");

stopBtnsetEnabled(false);

playBtn = new Button(shell, SWTNONE);

playBtnsetBounds(170, 61, 60, 18);

playBtnsetText("播放");

playBtnsetEnabled(false);

saveBtn = new Button(shell, SWTNONE);

saveBtnsetBounds(240, 61, 60, 18);

saveBtnsetText("保存");

saveBtnsetEnabled(false);

// 注册录音事件

captureBtnaddSelectionListener(new SelectionListener() {

public void widgetSelected(SelectionEvent event) {

captureBtnsetEnabled(false);

stopBtnsetEnabled(true);

playBtnsetEnabled(false);

saveBtnsetEnabled(false);

// 开始录音

capture();

}

public void widgetDefaultSelected(SelectionEvent event) {

// textsetText("No worries!");

}

});

// 注册停止事件

stopBtnaddSelectionListener(new SelectionListener() {

public void widgetSelected(SelectionEvent event) {

captureBtnsetEnabled(true);

stopBtnsetEnabled(false);

playBtnsetEnabled(true);

saveBtnsetEnabled(true);

// 停止录音

stop();

}

public void widgetDefaultSelected(SelectionEvent event) {

// textsetText("No worries!");

}

});

// 注册播放事件

playBtnaddSelectionListener(new SelectionListener() {

public void widgetSelected(SelectionEvent event) {

// 播放录音

play();

}

public void widgetDefaultSelected(SelectionEvent event) {

// textsetText("No worries!");

}

});

// 注册保存事件

saveBtnaddSelectionListener(new SelectionListener() {

public void widgetSelected(SelectionEvent event) {

// 保存录音

save();

}

public void widgetDefaultSelected(SelectionEvent event) {

// textsetText("No worries!");

}

});

}

public void start() {

shellopen();

while (!shellisDisposed()) {

if (!displayreadAndDispatch()) {

displaysleep();

}

}

}

public static void main(String[] args) {

RecordPlay label = new RecordPlay();

labelstart();

}

// (1)录音事件,保存到ByteArrayOutputStream中

private void capture() {

try {

// 打开录音

audioFormat = getAudioFormat();

DataLineInfo dataLineInfo = new DataLineInfo(

TargetDataLineclass, audioFormat);

targetDataLine = (TargetDataLine) AudioSystemgetLine(dataLineInfo);

targetDataLineopen(audioFormat);

targetDataLinestart();

// 创建独立线程进行录音

Thread captureThread = new Thread(new CaptureThread());

captureThreadstart();

} catch (Exception e) {

eprintStackTrace();

Systemexit(0);

}

}

// (2)播放ByteArrayOutputStream中的数据

private void play() {

try {

// 取得录音数据

byte audioData[] = byteArrayOutputStreamtoByteArray();

// 转换成输入流

InputStream byteArrayInputStream = new ByteArrayInputStream(

audioData);

AudioFormat audioFormat = getAudioFormat();

audioInputStream = new AudioInputStream(byteArrayInputStream,

audioFormat, audioDatalength / audioFormatgetFrameSize());

DataLineInfo dataLineInfo = new DataLineInfo(

SourceDataLineclass, audioFormat);

sourceDataLine = (SourceDataLine) AudioSystemgetLine(dataLineInfo);

sourceDataLineopen(audioFormat);

sourceDataLinestart();

// 创建独立线程进行播放

Thread playThread = new Thread(new PlayThread());

playThreadstart();

} catch (Exception e) {

eprintStackTrace();

Systemexit(0);

}

}

// (3)停止录音

public void stop() {

stopCapture = true;

}

// (4)保存文件

public void save() {

// 取得录音输入流

AudioFormat audioFormat = getAudioFormat();

byte audioData[] = byteArrayOutputStreamtoByteArray();

InputStream byteArrayInputStream = new ByteArrayInputStream(audioData);

audioInputStream = new AudioInputStream(byteArrayInputStream,

audioFormat, audioDatalength / audioFormatgetFrameSize());

// 写入文件

try {

File file = new File("d:/myjava/testwav");

AudioSystem

write(audioInputStream, AudioFileFormatTypeWAVE, file);

} catch (Exception e) {

eprintStackTrace();

}

}

// 取得AudioFormat

private AudioFormat getAudioFormat() {

float sampleRate = 160000F;

// 8000,11025,16000,22050,44100

int sampleSizeInBits = 16;

// 8,16

int channels = 1;

// 1,2

boolean signed = true;

// true,false

boolean bigEndian = false;

// true,false

return new AudioFormat(sampleRate, sampleSizeInBits, channels, signed,

bigEndian);

}

class PlayThread extends Thread {

byte tempBuffer[] = new byte[10000];

public void run() {

try {

int cnt;

// 读取数据到缓存数据

while ((cnt = audioInputStreamread(tempBuffer, 0,

tempBufferlength)) != -1) {

if (cnt > 0) {

// 写入缓存数据

sourceDataLinewrite(tempBuffer, 0, cnt);

}

}

// Block等待临时数据被输出为空

sourceDataLinedrain();

sourceDataLineclose();

} catch (Exception e) {

eprintStackTrace();

Systemexit(0);

}

}

}

class CaptureThread extends Thread {

// 临时数组

byte tempBuffer[] = new byte[10000];

public void run() {

byteArrayOutputStream = new ByteArrayOutputStream();

totaldatasize = 0;

stopCapture = false;

try {// 循环执行,直到按下停止录音按钮

while (!stopCapture) {

// 读取10000个数据

int cnt = targetDataLineread(tempBuffer, 0,

tempBufferlength);

if (cnt > 0) {

// 保存该数据

byteArrayOutputStreamwrite(tempBuffer, 0, cnt);

totaldatasize += cnt;

}

}

byteArrayOutputStreamclose();

} catch (Exception e) {

eprintStackTrace();

Systemexit(0);

}

}

}

}

小程序设置虚拟号录音功能可以通过集成第三方语音API实现,用户可以在通话过程中开启录音存储通话内容。在实现过程中需要考虑用户隐私保护,应提供录音提示功能以增强用户知情权和控制权;同时,对于录音内容的存储应遵守法律法规,并制定明确的个人信息保护政策。另外,为了提升用户体验,还应该考虑录音文件保存路径、录音格式支持、录音时长限制等因素。最后,需要定期进行维护,确保录音功能的稳定和安全。

有上翻的动画,有商品展示,有分享,以及跳到视频库。之前网上找了很多,说swiper不能套video,现在已经可以了,第二种是把封面平铺下来,滚动的是封面那种,效果不好

首先用一个cover-view来控制上下滚空,监听touch事件,让swiper的index+1或者-1

swiper包裹这video,swiper不能自动滚动,但是必须要设置衔接的属性。

js里面onshow的那个地方是我们点击tabbar的时候不需要再次调接口,做的处理,如果不是tabbar,可以直接再onload里面调后端数据

注意的是,在开发中,只要不是本地的视频,掉了接口,然后ios的前两个视频就是黑屏,后来加上了custom-cache="{{false}}">就解决了

注意的另一个兼容的是,只有cover-view才能覆盖再原生video之上,像轮播购买记录的那个地方,cover-view不能包swiper,所有有的手机是被视频遮住的

如果不妨到tabbar里的话,就是全屏播放了,头部自定义,然后左右两边也没有黑色没撑满了

你好呀~

可以先确认下是不是超出了内存。

查看内存:点小程序击右下角我的-上方内存条,即可看到自己的内存。

如果超出,则需要够买小打卡年绘员,或者删除文件、降低内存至对应内存下;

如果没有超出,录音依然无法播放,可以联系小打卡客服人员。

联系客服路径:小程序左上角三个横线-设置-帮助与反馈,即可联系客服。输入“人工”后即可联系到人工客服!

以上就是关于用java做一个可视化小程序,可以录音并予以保存。全部的内容,包括:用java做一个可视化小程序,可以录音并予以保存。、小程序设置虚拟号录音功能、微信小程序模仿抖音,全屏播放且有流畅的动画等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/10164945.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存