欢迎来到天天文库
浏览记录
ID:38780946
大小:16.72 KB
页数:6页
时间:2019-06-19
《关于采用UDP协议传输音频的代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、关于采用UDP协议传输音频的代码请高手指教package,importpackagecom.android.test;importjava.io.File;importjava.net.DatagramPacket;importjava.net.DatagramSocket;importjava.net.InetAddress;importandroid.app.Activity;importandroid.media.AudioFormat;importandroid.media.AudioManager;
2、importandroid.media.AudioRecord;importandroid.media.AudioTrack;importandroid.media.AudioTrack.OnPlaybackPositionUpdateListener;importandroid.media.MediaRecorder;importandroid.os.AsyncTask;importandroid.os.Bundle;importandroid.util.Log;importandroid.view.Vie
3、w;importandroid.view.View.OnClickListener;importandroid.widget.Button;importandroid.widget.TextView;publicclassTestRecroderUDPextendsActivityimplementsOnClickListener{/**Calledwhentheactivityisfirstcreated.*/ButtonstartRecording,stopRecording,startPlaying,s
4、topPlaying;booleanisRecording=false;//是否录放的标记booleanisPlaying=false;RecordAudiorecordTask;PlayAudioplayTask;TextViewstatusTextView;FilerecordingFile;byte[]tmpBuf=null;@OverridepublicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState)
5、; setContentView(R.layout.main); statusTextView=(TextView)this.findViewById(R.id.TextView); startRecording=(Button)this.findViewById(R.id.startRecording); startRecording.setOnClickListener(this); stopRecording=(Button)this.findViewById(R.id.stopRecordi
6、ng); stopRecording.setOnClickListener(this); startPlaying=(Button)this.findViewById(R.id.startPlaying); startPlaying.setOnClickListener(this); stopPlaying=(Button)this.findViewById(R.id.stopPlaying); stopPlaying.setOnClickListener(this); stopRecording
7、.setEnabled(false); startPlaying.setEnabled(false); stopPlaying.setEnabled(false);/** Filepath=newFile(Environment.getExternalStorageDirectory() .getAbsolutePath()); path.mkdirs(); try{ recordingFile=File.createTempFile("recording",".pcm",path); }ca
8、tch(IOExceptione){ thrownewRuntimeException("CouldnotcreatefileonSDcard",e); } */}@OverridepublicvoidonClick(Viewv){ //TODOAuto-generatedmethodstub if(v==startRecording){ record(); }elseif(v==st
此文档下载收益归作者所有