Android How to record video using CWAC Camera library - android

I use following code for record video but recorded video file is not save or store in sdcard and can i record video in portrait mode.i got this code from link https://github.com/commonsguy/cwac-camera
if (!isRecording()) {
try {
record();
getActivity().invalidateOptionsMenu();
} catch (Exception e) {
Log.e(getClass().getSimpleName(),
"Exception trying to record", e);
Toast.makeText(getActivity(), e.getMessage(),
Toast.LENGTH_LONG).show();
}
} else {
try {
stopRecording();
getActivity().invalidateOptionsMenu();
} catch (Exception e) {
Log.e(getClass().getSimpleName(),
"Exception trying to stop recording", e);
Toast.makeText(getActivity(), e.getMessage(),
Toast.LENGTH_LONG).show();
}
}

Related

How to color part of the java code in android studio ?

there is some way i can color in some color part of my code (not the output, the actually code ) in android studio ?
something like this :
case R.id.buttonbackup:
Toast.makeText(this, "first", Toast.LENGTH_SHORT).show();
try {
Toast.makeText(this, "before try", Toast.LENGTH_SHORT).show();
BackUpContacts();
DeleteAllContacts();
Toast.makeText(this, "after try", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
Toast.makeText(this, "EX", Toast.LENGTH_SHORT).show();
e.printStackTrace();
Toast.makeText(this,e.getStackTrace().toString() , Toast.LENGTH_SHORT).show();
} catch (Exception e) {//this the part i want to color
e.printStackTrace();
}
break;
i want to color all the part of the catch . there is some way to do that ?

Android: media player play from url :Failed to open file error

I am trying to implement a simple media player in android that contains only two buttons one for play another for pause
Play
String url = " http://host/audio/01_-_Pat.mp3";
public void onClick(View v) {
try{
mPlayer.setDataSource(url);
mPlayer.setOnPreparedListener(MainActivity.this);
mPlayer.prepareAsync();
}catch (Exception e)
{
Log.v("Error", String.valueOf(e));
Toast.makeText(getApplicationContext(), "Exception", Toast.LENGTH_LONG).show();
}
mPlayer.start();
}
I didn't get any exception on this code but i will get this error
*
Failed to open file ' http://host.com/audio/01_-_Pat.mp3'. (No such
file or directory)
*
Actually the url is valid and it contains the audio
Add this line to your code:
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
String url = " http://host/audio/01_-_Pat.mp3";
public void onClick(View v) {
try{
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mPlayer.setDataSource(url);
mPlayer.setOnPreparedListener(MainActivity.this);
mPlayer.prepareAsync();
}catch (Exception e)
{
Log.v("Error", String.valueOf(e));
Toast.makeText(getApplicationContext(), "Exception", Toast.LENGTH_LONG).show();
}
mPlayer.start();
}

How can i save a song from my app in android? [duplicate]

This question already has answers here:
Downloading an mp3 file from server in android
(3 answers)
Closed 7 years ago.
i am unable to download the song from internet but i can listen the song but i want to my app to perform as, when i am clicking the play button it should download that song too.
playbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
mPlayer = new MediaPlayer();
if(web[position] == web[0]){
if(mPlayer.isPlaying()){
mPlayer.stop();
mPlayer.prepareAsync();
mPlayer.seekTo(0);
}
else{
Uri myUri1 = Uri.parse("http://sound21.mp3slash.net/320/indian/bajrangibhaijaan/01%20-%20Selfie%20Le%20Le%20Re%20-%20Bajrangi%20Bhaijaan%20[Songspk.LINK].mp3");
try {
mPlayer.setDataSource(getContext(), myUri1);
} catch (IllegalArgumentException e) {
Toast.makeText(getContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (SecurityException e) {
Toast.makeText(getContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IllegalStateException e) {
Toast.makeText(getContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
try {
mPlayer.prepare();
} catch (IllegalStateException e) {
Toast.makeText(getContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(getContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
}
mPlayer.start();
playbtn.setText("Pause");
}
You mean when you click button , start playing and downloading?
Use DownloadManager to download the audio file.
http://developer.android.com/reference/android/app/DownloadManager.html

Android: won't play rtp stream

I want to make an app which plays the sound from an server.
Receiving and playing from the internet works, but with my JMF-Programm it does not work (Error (-38,0)).
here is my code-snippet from the app:
MediaPlayer mPlayer = new MediaPlayer();
// String url
// ="http://programmerguru.com/android-tutorial/wp-content/uploads/2013/04/hosannatelugu.mp3";
String url = "rtp://192.168.32.29:22222/audio/16";
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
AudioManager audioManager = (AudioManager) this
.getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, volume);
try {
mPlayer.setDataSource(url);
} catch (IllegalArgumentException e) {
Toast.makeText(getApplicationContext(),
"You might not set the URI correctly!", Toast.LENGTH_LONG)
.show();
} catch (SecurityException e) {
Toast.makeText(getApplicationContext(),
"You might not set the URI correctly!", Toast.LENGTH_LONG)
.show();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(),
"You might not set the URI correctly!", Toast.LENGTH_LONG)
.show();
} catch (IOException e) {
e.printStackTrace();
}
try {
mPlayer.prepare();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(),
"You might not set the URI correctly!", Toast.LENGTH_LONG)
.show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(),
"You might not set the URI correctly!", Toast.LENGTH_LONG)
.show();
}
mPlayer.start();
when I use "http://programmerguru.com/android-tutorial/wp-content/uploads/2013/04/hosannatelugu.mp3" it works, but "rtp://192.168.32.29:22222/audio/16" sends me error (-38,0)
Can someone help me?
Thanks

Playing sound from SDCard with MediaPlayer?

Let me explain clearly:
I have folder named "Sounds" and there are some .ogg files to play.
I got the folder path using Environment.getExternalStorageDirectory().getAbsolutePath() + mySoundsPath;.
I got all list from that folder and save it to array: List<String> soundList;
My question is:
How to call the sound from soundList that i created so they all can be played??
Should it need to decoded(like images, decoded to Bitmap)??
Sorry for my grammar.
Thanks in advance.
Use the below link for the reference
http://developer.android.com/reference/android/media/MediaPlayer.html
and you can try small code sample as well
http://davanum.wordpress.com/2007/12/29/android-videomusic-player-sample-from-local-disk-as-well-as-remote-urls/
public void play(String path) {
count++;
playFile=path;
//showNotification();
new NotificationPanel(activity);
if(mediaPlayer!=null && mediaPlayer.isPlaying()){
Log.d("*****begin*****", "playing");
stopPlaying();
Log.d("*****begin*****", "stoping");
} else{
Log.d("*****begin*****", "nothing");
}
Uri myUri1 = Uri.parse(path);
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource(activity, myUri1);
} catch (IllegalArgumentException e) {
Toast.makeText(activity, "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (SecurityException e) {
Toast.makeText(activity, "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IllegalStateException e) {
Toast.makeText(activity, "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
try {
mediaPlayer.prepare();
} catch (IllegalStateException e) {
Toast.makeText(activity, "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(activity, "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
}
mediaPlayer.start();
}
private void stopPlaying() {
if (mediaPlayer != null) {
mediaPlayer.stop();
mediaPlayer.release();
mediaPlayer = null;
}
}

Categories

Resources