LibVLC Android playMRL method Exception Catch - vlc-android

We are trying the Android VLC LIb from the URL.
We won't able to catch exception if play rtsp stream fails.
Code: mMediaPlayer.play();
How can we catch exception if anything fails in calling above method.

Just explored bit more, It seems Latest version of Android VLC SDK Wrapper 1.9.8 have support of tracking events.(https://github.com/mrmaffen/vlc-android-sdk)
Code:
try {
options = new ArrayList<String>();
options.add("-vvv"); // verbosity
options.add("--extraintf=logger");
options.add("--verbose=0");
options.add("--log-verbose=0");
options.add("--rtsp-tcp");
mLibVLC = new LibVLC(options);
mMediaPlayer = new MediaPlayer(mLibVLC);
mMediaPlayer.setEventListener(mPlayerListener);
videoView.setVideoPath(mMediaUrl);
videoView.setVideoURI(Uri.parse(mMediaUrl));
videoView.setMediaController(new MediaController(this));
videoView.setOnPreparedListener(new android.media.MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(android.media.MediaPlayer mp) {
Log.d("TAG", "OnPrepared called");
}
});
videoView.start();
} catch (Exception e){
Log.e(TAG, e.toString());
}
Logs attached below:

Related

How to use method documentoPDF() without BeanCreatingException

Someone could tell why mi app doesn't start when i put the method documentoPDF() in my springboot app? I reach the line that causes the error (the one after the try declaration) but I do not know why and how to solve, any suggestion? if I remove this invoking my app starts normally...
public void documentopPDF(){
Document document = new Document();
try{
PdfWriter.getInstance(document, new FileOutputStream("table.pdf"));
} catch(FileNotFoundException e1){
e1.printStackTrace();
} catch (DocumenmtException e2) {}
e2.printStackTrace();
}

Is there a way to batch upload a collection of InputStreams to Amazon S3 using the Java SDK?

I am aware of the TransferManager and the .uploadFileList() and .uploadFileDirectory() methods, however they accept java.io.File types as arguments. I have a collection of byte array input streams containing jpeg image data. I don't want to create in-memory files to store this data before I upload it either.
So what I need is essentially what the S3 client's PutObjectRequest does but for a collection of InputStream objects. Also, if one upload fails, I want to abort the whole thing and not upload anything, much like how a database transaction will reverse the changes if something goes wrong along the way.
Is this possible with the Java SDK?
Before I share an answer, please consider upgrading...
fyi - TransferManager is deprecated, now supported as TransferManagerBuilder in JAVA AWS SDK, please consider upgrading if TransferManagerBuilder Object suits your needs.
now since you asked about TransferManager, you could either 1) copy the code below and replace the functionality/arguments with your custom in memory handling of the input stream and handle it in your custom function... or; 2) further below is another sample, try to use this as-is...
Github source modify with with inputstream and issue listed here
private def uploadFile(is: InputStream, s3ObjectName: String, metadata: ObjectMetadata) = {
try {
val putObjectRequest = new PutObjectRequest(bucketName, s3ObjectName,
is, metadata)
// TransferManager supports asynchronous uploads and downloads
val upload = transferManager.upload(putObjectRequest)
upload.addProgressListener(ExceptionReporter.wrap(UploadProgressListener(putObjectRequest)))
} catch {
case e: Exception => throw new RuntimeException(e)
}
}
Bonus, Nice custom answer here using sequence input streams
public void combineFiles() {
List<String> files = getFiles();
long totalFileSize = files.stream()
.map(this::getContentLength)
.reduce(0L, (f, s) -> f + s);
try {
try (InputStream partialFile = new SequenceInputStream(getInputStreamEnumeration(files))) {
ObjectMetadata resultFileMetadata = new ObjectMetadata();
resultFileMetadata.setContentLength(totalFileSize);
s3Client.putObject("bucketName", "resultFilePath", partialFile, resultFileMetadata);
}
} catch (IOException e) {
LOG.error("An error occurred while combining files. {}", e);
}
}
private Enumeration<? extends InputStream> getInputStreamEnumeration(List<String> files) {
return new Enumeration<InputStream>() {
private Iterator<String> fileNamesIterator = files.iterator();
#Override
public boolean hasMoreElements() {
return fileNamesIterator.hasNext();
}
#Override
public InputStream nextElement() {
try {
return new FileInputStream(Paths.get(fileNamesIterator.next()).toFile());
} catch (FileNotFoundException e) {
System.err.println(e.getMessage());
throw new RuntimeException(e);
}
}
};
}

IText keep pfm file open in Ubuntu

We have a web app running on Tomcat/Ubuntu and using iText7.1.8 to generate pdf documents (Invoices). We noticed that our Tomcat crashed many times and then after investigations found that it was iText the problem. Here is the exception
SEVERE: Socket accept failed
org.apache.tomcat.jni.Error: 24: Too many open files
at org.apache.tomcat.jni.Socket.accept(Native Method)
at org.apache.tomcat.util.net.AprEndpoint$Acceptor.run(AprEndpoint.java:992)
at java.lang.Thread.run(Thread.java:745)
When we run this command: sudo ls -l /proc/Tomcat-PID/fd we notice that most of the files opened are with extension .pfm (ex: /usr/share/fonts/type1/gsfonts/n022004l.pfm) and never released. This number continue to increase till reaches the max number of opened files.
Here is the code in Java used to generate the pdf.
public static File convertToPDF(File pdfFile,URL webURL){
InputStream htmlStream=null;
FileOutputStream pdfStream=null;
try {
htmlStream=webURL.openStream();
pdfStream=new FileOutputStream(pdfFile);
ConverterProperties properties = new ConverterProperties();
properties.setFontProvider(new DefaultFontProvider(true, true, true));
HtmlConverter.convertToPdf(htmlStream, pdfStream,properties);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
if(htmlStream!= null){
htmlStream.close();
}
if(pdfStream!= null){
pdfStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return pdfFile;
}
Should we use a singleton to avoid multi instance, of this process which generates pdf, and the multiple files opened?
Environment:
Ubuntu 14.04
Tomcat 7.0.52
Java 1.7.0_80-b15
itext 7.1.8
Thank you
Fixed issue.
Use a singleton to get converter properties:
private static ConverterProperties properties;
private static DefaultFontProvider defaultFontProvider;
...
defaultFontProvider= new DefaultFontProvider(true, true, true);
properties.setFontProvider(defaultFontProvider);

System.MissingMethodException Method 'System.Net.Http.HttpClientHandler.set_Proxy' not found

This is a Xamarin solution and I am getting the error found in this message's title. Of course, I can easily confirm that there is a Proxy property on HttpClientHandler in the PCL project. And the solution builds without error. Only when I run does it produce this error (on either Droid or iOS) and does so at the point where it invokes the method in the PCL which instantiates the HttpClient. Note that it doesn't even get to that method. The error appears on the application start-up method; e.g., UIApplication.Main()
If I comment out the handler and instantiate HttpClient without a handler, it works fine as long as I'm on the open internet. But I'm trying to get this to work from behind a proxy.
Further investigation showed that the device projects had no references to System.Net.Http. So I added these -- and it indicates Xamarin.iOS and Xamarin.Android as the packages -- but it still produces the error.
I'm not clear what the error is telling me but I believe it means that the device project can't see System.Net.Http.HttpClientHandler?
private HttpClient GetHttpClient()
{
WebProxy proxy = new WebProxy(ProxyConfig.Url)
{
Credentials = new NetworkCredential(ProxyConfig.Username, ProxyConfig.Password)
};
// At runtime, when GetHttpClient is invoked, it says it cannot find the Proxy setter
HttpClientHandler handler = new HttpClientHandler
{
Proxy = proxy,
UseProxy = true,
PreAuthenticate = true,
UseDefaultCredentials = false,
};
HttpClient client = new HttpClient(handler);
// This works when not behind a proxy
//HttpClient client = new HttpClient();
return client;
}
public async Task GetWeatherAsync(double longitude, double latitude, string username)
{
// MissingMethodException is thrown at this point
var client = GetHttpClient();
client.BaseAddress = new Uri(string.Format("http://api.geonames.org/findNearByWeatherJSON?lat={0}&lng={1}&username={2}", latitude, longitude, username));
try
{
var response = await client.GetAsync(client.BaseAddress);
if (response.IsSuccessStatusCode)
{
var JsonResult = response.Content.ReadAsStringAsync().Result;
var weather = JsonConvert.DeserializeObject<WeatherResult>(JsonResult);
SetValues(weather);
}
else
{
Debug.WriteLine(response.RequestMessage);
}
}
catch (HttpRequestException ex)
{
Debug.WriteLine(ex.Message);
}
catch (System.Net.WebException ex)
{
Debug.WriteLine(ex.Message);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
Add the Microsoft.Net.Http NuGet package to your platform project too. If you run into an issue adding this, try installing the latest Microsoft.Bcl.Build package first. Then, after that is installed, add the HTTP package.

OAuthException not catched with C# FacebookSDK

I try to get my code working with catching certain errors. I store the token for a user after he or she grants permission to my app (this is a WP7 app). When I try to post on the wall by using the stored token it works. When I remove the permissions on facebook it throws an OAuthException. I can't catch it it seems. My app just crashes. This is the code I used:
private object PostToFacebook()
{
_fbApp = new FacebookClient(_appsettings.faceBookToken);
FacebookAsyncCallback callback = new FacebookAsyncCallback(this.postResult);
var parameters = new Dictionary<string, object>();
parameters.Add("message", "message on wall");
try
{
_fbApp.PostAsync("me/feed", parameters, callback);
}
catch (Exception ex)
{
}
return null;
}
private void postResult(FacebookAsyncResult asyncResult)
{
if (asyncResult.Error == null)
{
status = "succes";
}
else
{
status = "error" + asyncResult.Error.Message;
}
}
The try catch doesn't catch anything and the generic exception handler in my app.xaml.cs either.
Any ideas how to catch this error so I can ask the user to authenticate again?
Put your try..catch in the callback.
You can also catch exceptions globally by handling the UnhandledException event on the App object.

Resources