Change details of an mp3 using either java or C++ - java

I am trying to cleanup my mp3 collection and I have a bunch of songs that have the artist at the beginning of the song or numbers so I wanted to know if there is a way take the number from the filename and put it into the details (track number) of the file. I already know how to read files from folders I am just not sure how to change the details of a file if possible.

Have you considered using Mp3Tag it's a very nice application that actually has tools for analyzing file names and putting the details in to the tags.

Related

Can I save a text file without giving users ability to modify it?

I'm working on a game and I am at that part that I want to save the game progress into a text file (or maybe a properties file would be good too), but I'd like to save that file to a place that is not reachable for the players. I was thinking about saving it to a source folder inside the program, but I am not able to save or load a text file from there, only images. Could anybody suggest something how/where to save the game stats that players can not just go into the settings file and modify their score or level or something like that?
With the properties file my only problem is the saving, where I need an output stream or a writer to save it, what I', not able to get
Assuming your player's pc has a regular hard drive with regular standards then:
If the game is offline(and maybe later synced with a server) then the answer is NO; if your app can access the file so does the user; even if you encrypt the data written to the save file people can just reverse engineer your app and get the keys and algorithms and modify the file; to put it simply you can only complicate it, their access to save files is inevitable.
If your game is only possible to be played online then you can do sanity check for every action of the players and save the progress in an inaccessible by players manner;
About the read only, been asked before:
create a read-only file
For the second one, keep in mind that as you know the path to the file and the name of it, the user don't. Saving the file using "scary" name, in un-trivial path will protect the file from any changes for a while

Use metadata to uniquely identify files

Hello need to know how to identify the audio file in the storage of a device, the question is as follows:
I am developing a music player and am storing some playback data in the database that are attached to each audio file individually, from time to time the application checks for changes in the user's audio library (on sdcard or internal memory) and inserts the new songs (if any) in the database, the problem is I can not identify if the database already exists because I can not get a common identifier, I tried to use the music path in the storage but in some cases the music name has banned characters that prevent me from using in sqlite so the question is:
How to identify an audio file?
EDIT1:
I think my question was not very clear, what I wanted was a way to individually identify each audio file using for example some metadata of the file that was unique to it and could not be repeated such as the creation date of the file in milliseconds, or any other metadata that is unique to each file, like a fingerprint.
I'm testing a solution that I find not if it is is ideal, I take the path of the file and use the Base64 class to encode it:
String path = "/storage/emulated/0/Download/Disturbed-Ten Thousand Fists.mp3";
Base64.encodeToString(path.getBytes(), Base64.DEFAULT);'
result is: L3N0b3JhZ2UvZW11bGF0ZWQvMC9Eb3dubG9hZC9EaXN0dXJiZWQtVGVuIFRob3VzYW5kIEZpc3Rz
Lm1wMw
The size varies depending on the path but String gets only letters and numbers that are accepted in the database and the result is always the same for each path. What you tink about it?
An audio file can be identified by the extension. A list (not complete) of formats that is used can be found on Wikipedia Audio_file_format
Your best option would probably be to check the file extension and make a list of known extension types related to audio.
This does not, however, cover cases such as an MP4 file with audio and no video.
For the purpose of this, I will assume you already have a variable, either hard coded or in a loop/list, which is the File object you wish to check.
File audioFile;
//this is just for readability, do not write in your code as this should be replaced with the variable you have which is storing the audio file File.
String name = audioFile.getName();
//This is where you can do your logic. The name also returns the extension of the file so you can make sure your music player can handle the file extension, and also check the characters in the name
//Here is an example of detecting the ' character
if(name.contains("'")){
//do something
}
Please let me know if you have further questions!
You must clicked all file format in the file type frame then choose the insert file with audio format such mp3, real, wmp.

Organizing data in java (on a mac)

I'm writing a tool to analyze stock market data. For this I download data and then save all the data corresponding to a stock as a double[][] 20*100000 array in a data.bin on my hd, I know I should put it in some database but this is simply performance wise the best method.
Now here is my problem: I need to do updates and search on the data:
Updates: I have to append new data to the end of the array as time progresses.
Search: I want to iterate over different data files to find a minimum or calculate moving averages etc.
I could do both of them by reading the whole file in and update it writing or do search in a specific area... but this is somewhat overkill since I don't need the whole data.
So my question is: Is there a library (in Java) or something similar to open/read/change parts of the binary file without having to open the whole file? Or searching through the file starting at a specific point?
RandomAccessFile allows seeking into particular position in a file and updating parts of the file or adding new data to the end without rewriting everything. See the tutorial here: http://docs.oracle.com/javase/tutorial/essential/io/rafs.html
You could try looking at Random Access Files:
Tutorial: http://docs.oracle.com/javase/tutorial/essential/io/rafs.html
API: http://docs.oracle.com/javase/6/docs/api/java/io/RandomAccessFile.html
... but you will still need to figure out the exact positions you want to read in a binary file.
You might want to consider moving to a database, maybe a small embedded one like H2 (http://www.h2database.com)

Reading and editing .wav (or flac) details in Java

I have tons of ripped .wav files (I'm ready to convert them into flacs if it's easier) which details I want to insert in a MySQL database. When I right click the .wav files in Windows Explorer (not the browser) and select Properties -> Details I can see some details about the song. For example the artist, genre and duration. How can I read and edit these details in Java?
To get durration information, see this link: Java - reading, manipulating and writing WAV files
Essentially, a WAV file is broken up into chunks, which either contain audio data, or describe the audio data in some way, or provide information about it. If the reader doesn't understand one of those chunks it is able to skip it, which allows placing a lot of different kinds of information in the file. One of those chunks contains information like the samplerate, number of channels and total number of sample frames, from which you can calculate the length.
For artist, genre and so on... well there's no standard chunk for that, so if that's really in the file, and not in the windows db somewhere, it's probably stored in ID3 tags embedded in the WAV. I don't know for sure what the chunkID is for ID3, but it's probably "id3 ", or "ID3 " (including the space). You coud probably figure this out by searching for strings of length 4 or more in the file -- usually data chunks are in the beginning and audio is at the end. (on unix/macos I would use the "strings" command, maybe with "head") ID3 tags are standard for MP3, and you can figure out how to parse them by googling. To get to them, you'll need to understand WAV files first, at least enough to know what chunks are, chunkIds, how to skip chunks you don't care about, and so on.
I don't know of a library that will read ID3 tags in WAV files in Java, so you'll either have to write one, or wrap one written in another language. I suspect libsndfile will work, but it doesn't have an MP3 reader, so maybe not. You could also try SOX. You can also check out http://javamusictag.sourceforge.net/ which I've never used, but it came up in a search.
good luck!
I ended up converting them into flac files and using JAudiotagger. Thanks for the responses, this time I ended up this way.
http://www.jthink.net/jaudiotagger/

Any existing java library to delete , edit , add certain line in a file with swing in Jmenu?

I am now using Fileutils to access a file to retrieve lines of phone number.
But now I need to add phone number , delete phone number and edit phone number in the file. I do know how to do it with JMenu , but i keep wondering , do anyone create a library for this?
I would suggest you to go for DB .
FILE IO in such case is very ugly coding.
and then also if you want to do it.
to modify content you need to create other file read from older and modify it in memory and write it back to new file.
If you don't want to go for DB, which is the best idea, you should maybe.
Read the whole file and store in a Collection
then, you remove the phone number, and then write it again on file overwriting.
It's definitely much more work. But it works too.
Reminding that the class of the ObjectType needs to implements Serializible.

Categories