Click here to Skip to main content
14,428,597 members
   

Android

 
QuestionDialog with Landscape Orientation Pin
Django_Untaken4-Jul-18 21:16
MemberDjango_Untaken4-Jul-18 21:16 
Questionput orders from android and receive from PHP Pin
AndroidVH22-Jun-18 21:13
MemberAndroidVH22-Jun-18 21:13 
SuggestionRe: put orders from android and receive from PHP Pin
Richard MacCutchan22-Jun-18 22:27
communityengineerRichard MacCutchan22-Jun-18 22:27 
GeneralRe: put orders from android and receive from PHP Pin
AndroidVH22-Jun-18 22:58
MemberAndroidVH22-Jun-18 22:58 
GeneralRe: put orders from android and receive from PHP Pin
Richard MacCutchan23-Jun-18 0:14
communityengineerRichard MacCutchan23-Jun-18 0:14 
SuggestionRe: put orders from android and receive from PHP Pin
David Crow24-Jun-18 11:36
MemberDavid Crow24-Jun-18 11:36 
GeneralRe: put orders from android and receive from PHP Pin
AndroidVH24-Jun-18 19:58
MemberAndroidVH24-Jun-18 19:58 
QuestionHow to broadcast audio 3gp format over wifi converting audio file in udp packets? Pin
Member 1114560021-Jun-18 19:36
MemberMember 1114560021-Jun-18 19:36 
I have to record a live audio/vedio and convert it into udp packets and broadcast it over wifi but not working after recording.

This is my code

public class MainActivity extends AppCompatActivity {

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

init();
random = new Random();
startAudioButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(checkPermission()) {
audioSavePathInDevice = Environment.getExternalStorageDirectory().getAbsoluteFile() + "/" + createRandomFile(5) + "Recording.3gp";
mediaRecorderReady();
try {
mediaRecorder.prepare();
mediaRecorder.start();
startListener();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
startAudioButton.setEnabled(false);
stopAudioButton.setEnabled(true);

Toast.makeText(getApplicationContext(), "Recording Started ", Toast.LENGTH_SHORT).show();
}else{
requestPermission();
}
}
});

stopAudioButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"Recording Completed",Toast.LENGTH_SHORT).show();
mediaRecorder.stop();
stopAudioButton.setEnabled(false);
buttonPlayLastRecordAudio.setEnabled(true);
stopAudioButton.setEnabled(true);
buttonStopPlayingRecording.setEnabled(false);

Toast.makeText(getApplicationContext(),"Recording Completed",Toast.LENGTH_SHORT).show();
}
});

buttonPlayLastRecordAudio.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) throws IllegalArgumentException,
SecurityException, IllegalStateException {
try{
startAudioButton.setEnabled(false);
stopAudioButton.setEnabled(false);
buttonStopPlayingRecording.setEnabled(true);
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(audioSavePathInDevice);
mediaPlayer.prepare();
mediaPlayer.start();

Toast.makeText(getApplicationContext(),"Recording Playing",Toast.LENGTH_SHORT).show();


}catch (IOException e){
e.printStackTrace();
}
}
});

buttonStopPlayingRecording.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
stopAudioButton.setEnabled(false);
stopAudioButton.setEnabled(true);
buttonStopPlayingRecording.setEnabled(false);
buttonPlayLastRecordAudio.setEnabled(true);

if(mediaPlayer != null){
mediaPlayer.stop();
mediaPlayer.release();
mediaRecorderReady();
}
}
});
}

private void init() {
startAudioButton = ( Button)findViewById(R.id.button);
stopAudioButton = ( Button)findViewById(R.id.button2);
buttonPlayLastRecordAudio = (Button) findViewById(R.id.button3);
buttonStopPlayingRecording = (Button) findViewById(R.id.button4);
stopAudioButton.setEnabled(false);
buttonPlayLastRecordAudio.setEnabled(false);
buttonStopPlayingRecording.setEnabled(false);
}

private void mediaRecorderReady() {
mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
mediaRecorder.setOutputFile(audioSavePathInDevice);
}

private String createRandomFile(int i) {

StringBuilder stringBuilder = new StringBuilder( i );
int j =0;
while (j<i){
stringbuilder.append(randomaudiofilename.charat(random.nextint(randomaudiofilename.length())));
="" j++;
="" }
="" return="" stringbuilder.tostring();
="" }

="" private="" void="" startlistener()="" {
="" create="" listener="" thread
="" listen="true;
" thread="" listenthread="new" thread(new="" runnable()="" {

="" <a="" href="https://www.codeproject.com/Members/override">@Override
public void run() {

try {

Log.i(LOG_TAG, "Listener started!");
DatagramSocket socket = new DatagramSocket(BROADCAST_PORT);
byte[] buffer = new byte[BUF_SIZE];
DatagramPacket packet = new DatagramPacket(buffer, BUF_SIZE);

while(LISTEN) {

try {
socket.send(packet);
Log.i(LOG_TAG, "Listening for packets");
socket.receive(packet);
String data = new String(buffer, 0, packet.getLength());
Log.i(LOG_TAG, "Packet received from "+ packet.getAddress() +" with contents: " + data);
// String action = data.substring(0, 4);

}
catch(SocketTimeoutException e) {
if(!IN_CALL) {

Log.i(LOG_TAG, "No reply from contact. Ending call");
endCall();
return;
}
}
catch(IOException e) {

}
}
Log.i(LOG_TAG, "Listener ending");
socket.disconnect();
socket.close();
return;
}
catch(SocketException e) {

Log.e(LOG_TAG, "SocketException in Listener");
endCall();
}
}
});
listenThread.start();
}

private void stopListener() {
// Ends the listener thread
LISTEN = false;
}

private void endCall() {
// Ends the chat sessions
stopListener();
if(IN_CALL) {

call.endCall();
}

finish();
}

}


When i am using only MediaRecorder for recording it working but when i try for udp packet conversion it not ,basically not getting how to club recording and udp packet code.

modified 22-Jun-18 5:26am.

SuggestionRe: How to broadcast audio 3gp format over wifi converting audio file in udp packets? Pin
Richard MacCutchan21-Jun-18 22:03
communityengineerRichard MacCutchan21-Jun-18 22:03 
QuestionFetching JSON data in recyclerview using retrofit and implement scroll to load or infinitescroll Pin
Arindam Mukherjee20-Jun-18 20:29
MemberArindam Mukherjee20-Jun-18 20:29 
QuestionCurrent Android Studio // Is it 2017 ? Pin
C-P-User-313-Jun-18 23:41
MemberC-P-User-313-Jun-18 23:41 
AnswerRe: Current Android Studio // Is it 2017 ? Pin
Richard Deeming14-Jun-18 3:36
communityengineerRichard Deeming14-Jun-18 3:36 
AnswerRe: Current Android Studio // Is it 2017 ? Pin
Ganza Charles20-Jun-18 23:42
MemberGanza Charles20-Jun-18 23:42 
GeneralRe: Current Android Studio // Is it 2017 ? Pin
C-P-User-311-Nov-18 21:46
MemberC-P-User-311-Nov-18 21:46 
Question(ANDROID) -->How can data be send from the run method of a thread in a service to a client using Handler and Messeger? Pin
Member 119110659-Jun-18 23:36
MemberMember 119110659-Jun-18 23:36 
AnswerRe: (ANDROID) -->How can data be send from the run method of a thread in a service to a client using Handler and Messeger? Pin
Richard MacCutchan10-Jun-18 5:18
communityengineerRichard MacCutchan10-Jun-18 5:18 
GeneralRe: (ANDROID) -->How can data be send from the run method of a thread in a service to a client using Handler and Messeger? Pin
Member 1191106510-Jun-18 10:24
MemberMember 1191106510-Jun-18 10:24 
GeneralRe: (ANDROID) -->How can data be send from the run method of a thread in a service to a client using Handler and Messeger? Pin
Richard MacCutchan10-Jun-18 23:06
communityengineerRichard MacCutchan10-Jun-18 23:06 
SuggestionRe: (ANDROID) -->How can data be send from the run method of a thread in a service to a client using Handler and Messeger? Pin
David Crow11-Jun-18 3:16
MemberDavid Crow11-Jun-18 3:16 
QuestionAddition,Sub,Mul & divide issue Pin
Member 1126111131-May-18 3:22
MemberMember 1126111131-May-18 3:22 
AnswerRe: Addition,Sub,Mul & divide issue Pin
Richard MacCutchan2-Jun-18 3:44
communityengineerRichard MacCutchan2-Jun-18 3:44 
QuestionXamarin WebView please help. Pin
Member 1335044424-May-18 7:03
MemberMember 1335044424-May-18 7:03 
AnswerRe: Xamarin WebView please help. Pin
David Crow24-May-18 10:34
MemberDavid Crow24-May-18 10:34 
GeneralRe: Xamarin WebView please help. Pin
Member 1335044425-May-18 12:07
MemberMember 1335044425-May-18 12:07 
QuestionRe: Xamarin WebView please help. Pin
David Crow28-May-18 16:59
MemberDavid Crow28-May-18 16:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.