I'm trying to edit tags of audio files and for that I'm using JaudioTagger. But a problem exists and I can't figure it out.
I'm getting this error:
java.lang.NoSuchMethodError: No virtual method toPath()Ljava/nio/file/Path; in class Ljava/io/File; or its super classes (declaration of 'java.io.File' appears in /system/framework/core-oj.jar)
And my code for getting tags of audio files :
File path = new File(songInfoModel.getData());
Log.e("Path: ", path.toString());
try {
AudioFile f = AudioFileIO.read(path);
Tag tag = f.getTag();
String artist = tag.getFirst(FieldKey.ARTIST);
tag.getFirst(FieldKey.ALBUM);
tag.getFirst(FieldKey.TITLE);
tag.getFirst(FieldKey.COMMENT);
tag.getFirst(FieldKey.YEAR);
tag.getFirst(FieldKey.TRACK);
tag.getFirst(FieldKey.DISC_NO);
tag.getFirst(FieldKey.COMPOSER);
tag.getFirst(FieldKey.ARTIST_SORT);
Log.e("Artist: ",artist);
} catch (CannotReadException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (TagException e) {
e.printStackTrace();
} catch (ReadOnlyFileException e) {
e.printStackTrace();
} catch (InvalidAudioFrameException e) {
e.printStackTrace();
}
Related
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 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.
Hello Im trying to save the language save by the user in my game
I have made a test to see if the script create the file and read it good.
Im using ini4j to store the value of language in a ini file.
I have no file, on the 1st start, programm create the empty file in the Local directory and fill it with value (language=fr) for test.
On 2nd start, the programm check if the file exist, then open it to read the value
The problem is that the 'lang' variable seems to be empty when it read it by my function sic_Language.setLanguage(String text);
My code
String lang;
Wini ini;
//Read
if (Gdx.files.local("mygame.ini").exists()) {
//Open file
try {
ini = new Wini(Gdx.files.local("mygame.ini").file());
} catch (InvalidFileFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//Read values
lang = ini.get("interface", "language");
sic_Language.setLanguage(lang); //Set language
}
//Write
else {
//Create file
try {
Gdx.files.local("mygame.ini").file().createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
//Open file
try {
ini = new Wini(Gdx.files.local("mygame.ini").file());
} catch (InvalidFileFormatException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
//Write values
ini.put("interface", "language", "fr");
try {
ini.store();
} catch (IOException e) {
e.printStackTrace();
}
sic_Language.setLanguage("fr"); //Set language
}
Following is my piece of code:\
public void LoadProjectFile(String Filename) throws Exception
{
// m_Renderer.m_Project=new Project();
refresh_project();
m_Renderer.m_SelectedProjectPath = Filename;
try {
m_Renderer.m_Project.load_file(Filename);
}
catch (Exception e)
{
//Exception a = e.getMessage();
String a= e.getMessage();
throw new Exception(a);
}
//AppFuncs.m_GisProject=m_Renderer.m_Project;
}
try
{
Map.this.mGLView.LoadProjectFile(AppFuncs.g_path);
Map.this.mGLView.requestRender();
}
catch (Exception e)
{
br=1;
b=e.getMessage();
}
Load project file throws an exception which i recieve in Map class. This exception contains message: Java.lang.exception: java.lang.exception: file not found.
I want to show only "File not found" message. so how should i get this message out from an exception?
Catch all types of exceptions instead of base Exception:
try {
m_Renderer.m_Project.load_file(Filename);
}
catch (FileNotFoundException e)
{
String a= "File not found"
throw new Exception(a);
}
catch (SomeOhterException e){
String a= "Some other message"
throw new Exception(a);
}
//at the end, but it shouldn't be necessary
catch (Exception e){
String a= "Something happend we don't know what"
throw new Exception(a);
}
Shortly: Use different class for different exception to show correct information rahter than using exception message.
Just catch the FileNotFoundException instead of an Exception.
For example:
try {
//whatever
} catch (FileNotFoundException e) {
System.out.println("File not found");
}
From this codesnippet:
try {
EncryptionUtils smimeUtils = EncryptionManager.getEncryptionUtils(EncryptionManager.SMIME);
char[] smimePw = new String("hello world").toCharArray();
EncryptionKeyManager smimeKeyMgr = smimeUtils.createKeyManager();
smimeKeyMgr.loadPrivateKeystore(privateKeyStore, smimePw);
} catch (NoSuchProviderException e) {
Log.e("NoSuchProvider: ", e.getMessage());
} catch (CertificateException e) {
Log.e("Certificate: ", e.getMessage());
} catch (KeyStoreException e) {
Log.e("KeyStore: ", e.getMessage());
} catch (NoSuchAlgorithmException e) {
Log.e("No Such Algorithm: ", e.getMessage());
} catch (IOException e) {
Log.e("IO: ", e.getMessage());
}
I try to load the S/MIME encryption manager, but this code throws an NoSuchProviderException telling me this:
No provider configured for S/MIME
I'm following this guide, which is telling me to add the following .jar-files:
javamail-crypto.jar
bcprov-jdk14-122.jar
bcmail-jdk14-122.jar
I couldn't find the extact version with the ending -122 but I included the following jar-files to my build path:
bcprov-jdk14-147
bcmail-jdk14-147
javamail-crypto
javamail-crypto-bouncycastle-smime
But it still throws the exception, could anybody give me a hint on how to solve this issue?