I had used 4 VideoView in my Activity.If uri1 is available and other uri's are not available means all video view shows uri1's video.
If other uri's are available but uri1 is not up means all videoview's are not showing anything. Guide me to solve this issue.
String uri1="rtsp://admin:admin#Serverurl1"
String uri2="rtsp://admin:admin#Serverurl2"
String uri3="rtsp://admin:admin#Serverurl3"
String uri4="rtsp://admin:admin#Serverurl4"
videoview1.setVideoURI(Uri.parse(uri1));
videoview2.setVideoURI(Uri.parse(uri2));
videoview3.setVideoURI(Uri.parse(uri3));
videoview4.setVideoURI(Uri.parse(uri4));
Thanks in advance.
You can try this:
vv1=(VideoView)findViewById(R.id.vv1);
vv2=(VideoView)findViewById(R.id.vv2);
vv3=(VideoView)findViewById(R.id.vv3);
vv4=(VideoView)findViewById(R.id.vv4);
try {
vv1.setVideoURI(Uri.parse(url1));
vv1.requestFocus();
vv1.start();
} catch (Exception e) {
// TODO: handle exception
}
try {
vv2.setVideoURI(Uri.parse(url2));
vv2.requestFocus();
vv2.start();
} catch (Exception e) {
// TODO: handle exception
}
try {
vv3.setVideoURI(Uri.parse(url3));
vv3.requestFocus();
vv3.start();
} catch (Exception e) {
// TODO: handle exception
}
try {
vv4.setVideoURI(Uri.parse(url4));
vv4.requestFocus();
vv4.start();
} catch (Exception e) {
// TODO: handle exception
}
Related
If trying to open Password Protected PDF with PdfRenderer API, gives SecurityException and handled accordingly, inside catch block and thenonDestroy basic clean up is done, and comes back to home activity and then navigating a simple non-protected PDF than again the same exception occurs.
Please note, this happens only once any protected file got opened.
Refer below code:
#Override
protected PdfRenderer doInBackground(Uri... uri) {
Uri uriToProcess = uri[0];
try {
contentResolver=getContentResolver();
parcelFileDescriptor = contentResolver.openFileDescriptor(uriToProcess, "r");
if(parcelFileDescriptor!=null && mPdfRenderer==null) {
mPdfRenderer = new PdfRenderer(parcelFileDescriptor);
}
} catch (FileNotFoundException e) {
exceptionMsg="Sorry! No such file or directory found";
handleExceptionInUI(exceptionMsg, progressDialog);
Log.e("$$$$ FNFException", e.toString());
} catch (IOException e) {
exceptionMsg="Sorry! Something went wrong with IO";
handleExceptionInUI(exceptionMsg, progressDialog);
Log.e("$$$$ IOException", e.toString());
} catch (SecurityException e) {
if (parcelFileDescriptor!=null) {
try {
parcelFileDescriptor.close();
parcelFileDescriptor = null;
contentResolver=null;
} catch (IOException e1) {
e1.printStackTrace();
}
}
if (mPdfRenderer!=null){
mPdfRenderer.close();
mPdfRenderer=null;
}
exceptionMsg="Password protected file, This can't be opened";
handleExceptionInUI(exceptionMsg, progressDialog);
Log.e("$$$$ SecurityException", e.toString());
} catch (Exception e) {
exceptionMsg="Sorry! Something went wrong.";
handleExceptionInUI(exceptionMsg, progressDialog);
Log.e("$$$$ EXCEPTION", e.toString());
}
return mPdfRenderer;
}
Any help cordially appreciated.
I had the same problem with my app. The way I solved it was using an https://github.com/TomRoush/PdfBox-Android and load the document and check for password protection. After no InvalidPasswordException has been thrown the file can be safely loaded with the PdfRenderer.
I am using a MediaPlayer that grabs videos from URLs:
try {
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(this, uri);
}catch (FileNotFoundException e){
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
When I try and set a datasource with a url, that for instance, has been taken down, I get the following error in my logcat:
Couldn't open file on client side; trying server side:
java.io.FileNotFoundException: No content provider:
http://example.com/examplevideo.mp4
However, my catch{} does not trap this in the following code above, which I need it to do so I can display an error message etc...
Is there any way to catch this FileNotFoundException in my code?
Thanks in advance
I don't know how to catch this specific exception. But you can use following to catch any type of exception.
try {
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(this, uri);
}catch (FileNotFoundException e){
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
try {
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(this, uri);
}catch (FileNotFoundException e){
e.printStackTrace();
} catch (IOException e) {
Log.i("your tag",e.toString());
}
and look at the log with the tag you whant
Thanks all for replies.
I forgot to mention that the file is from an external server, but have adopted an approach similar to what Pramod suggested, but altered to suit my needs.
/**
* Checks if an external file on a server exists.
* #param urlString The file URL
* #return true if file exists, false if does not
*/
public boolean checkExternalFileExists(String urlString){
try {
URL url = new URL(urlString);
int response = ((HttpURLConnection)url.openConnection()).getResponseCode();
return response == HttpURLConnection.HTTP_OK;
}
catch (FileNotFoundException e) {
return false;
}catch (MalformedURLException e) {
return false;
} catch (IOException e) {
return false;
}
}
Thanks
I used this code to play a mp3 file. Its playing in any device without Samsung... I search a lot but can't solved this problem. Please can anyone give any method to play mp3 in any device.
//Not working in Samsung Device
MediaPlayer mMediaPlayer;
void playSound()
{
try {
mMediaPlayer = MediaPlayer.create(this, R.raw.recipe_tune);
mMediaPlayer.start();
} catch (Exception e) {
// TODO: handle exception
}
}
Call prepare method before starting player and also print exception in your logcat and also catch like this,
try {
//code lies here
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
I am new to android trying to make a custom video controller from an opensource snippet, i have added comments where i thought were necessary for understanding the code a little better, hope it will be helpfull
public void playVideo(){
if(videoview.isPlaying()){
videoview.stopPlayback();
}
try {
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
File file = new File(path);//path is a string
FileInputStream inputStream = new FileInputStream(file);//log says warning is here
player.setDataSource(inputStream.getFD());
inputStream.close();
player.setOnPreparedListener(this);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Thanks in advance!!
To get an InputStream for a raw resource, use openRawResource(int).
Possibly you could also use MediaPlayer.create(Context,int) to directly create a MediaPlayer with a given resource identifier.
I want to play 2 or more videoview at same time but only one play why?
can ı do this with mediaplayer?
Must I use thread?
VideoView vv1,vv2,vv3,vv4;
vv1=(VideoView)findViewById(R.id.vv1);
vv2=(VideoView)findViewById(R.id.vv2);
vv3=(VideoView)findViewById(R.id.vv3);
vv4=(VideoView)findViewById(R.id.vv4);
try {
vv1.setVideoURI(Uri.parse(dizi[0].toString()));
vv1.requestFocus();
vv1.start();
} catch (Exception e) {
// TODO: handle exception
}
try {
vv2.setVideoURI(Uri.parse(dizi[1].toString()));
vv2.requestFocus();
vv2.start();
} catch (Exception e) {
// TODO: handle exception
}
try {
vv3.setVideoURI(Uri.parse(dizi[2].toString()));
vv3.requestFocus();
vv3.start();
} catch (Exception e) {
// TODO: handle exception
}
try {
vv4.setVideoURI(Uri.parse(dizi[3].toString()));
vv4.requestFocus();
vv4.start();
} catch (Exception e) {
// TODO: handle exception
}