@try {
FILE*fwav =fopen([wavPathc StringUsingEncoding:NSASCIIStringEncoding],"rb")
fseek(fwav, 1024*4, SEEK_CUR)//跳过源文件的信息头,不然在开头会有爆破音
FILE*fmp3 =fopen([mp3Path cStringUsingEncoding:NSASCIIStringEncoding],"wb")
lame=lame_init()
lame_set_in_samplerate(lame, 22050.0)//设置wav的采样率
// lame_set_num_channels(lame, 2)//声道,不设置默认为双声道
lame_set_brate(lame, 16)//比特率
lame_set_VBR(lame, vbr_default)
lame_init_params(lame)
// const int PCM_SIZE = 640 * 2//双声道*2 单声道640即可
// const int MP3_SIZE = 8800//计算公式wav_buffer.length * 1.25 + 7200
const int PCM_SIZE =8192//双声道*2 单声道640即可
const int MP3_SIZE = 8192//计算公式wav_buffer.length * 1.25 + 7200
short int pcm_buffer[PCM_SIZE*2]
unsigned char mp3_buffer[MP3_SIZE]
int read, write
do {
read =fread(pcm_buffer, sizeof ( short int ), PCM_SIZE, fwav)
if (read ==0) {
write =lame_encode_flush(lame, mp3_buffer, MP3_SIZE)
} else {
write =lame_encode_buffer_interleaved(lame, pcm_buffer, read/2, mp3_buffer, MP3_SIZE)
// write = lame_encode_buffer_interleaved(lame, pcm_buffer, read, mp3_buffer, MP3_SIZE)
}
fwrite(mp3_buffer, write,1, fmp3)
} while (read !=0)
lame_close(lame)
fclose(fmp3)
fclose(fwav)
} @catch (NSException *exception) {
NSLog(@"catch exception")
} @finally {
block()
}
解决办法是1、聊天页面登录im,注册监听事件,当我发起音视频通话时,我先发送一条自定义消息,对方利用监听事件收到自定义消息后,自动跳转到直播间。2、我或者对方退出直播间后,能让im的事件监听到对方已结束通话或者挂断或者未接等操作,然后显示在聊天页面上。这样就可以记录监听事件。
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)