1

I try to make a media player and a video library for a school project, and I need to extract metadata from a .MP4 and .AVI to store in a XML files and can edit this metadata.

I did some research and I didn't find what I'm looking for, because I need a native Java library, and not a library that we need to install in our IDE.

And I have make my media player with JavaFX, and JavaFX can not read .avi media. So I need to convert this .avi to .mp4 is it possible to do this in Java with a native library?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Madarra
  • 23
  • 4
  • *"I need a native java library, and not a library that we need to install in our IDE"* what do you mean? You mean something that is part of the standard library? – Federico klez Culloca Apr 26 '22 at 07:18
  • Yes exactly, sorry if it wasn't very clear. – Madarra Apr 26 '22 at 07:22
  • Does this answer your question? [Get the metadata of a file](https://stackoverflow.com/questions/10824027/get-the-metadata-of-a-file) – Alex Apr 26 '22 at 07:24
  • I don't know I need to try, but I need to have the title, the autor,date and other basic information from a mp4 – Madarra Apr 26 '22 at 07:30
  • Yes it work, but that's not the metadata I want. – Madarra Apr 26 '22 at 09:28
  • I still don't understand your request for "a native library". You will most certainly not find that in the Java standard library. But so what. Nobody writes real-world software which is just based on the Java standard library. What's the problem with using some external library? – mipa Apr 26 '22 at 09:29
  • it is a constraint to create my mediaplayer fix by my professor. Me too I don't understand why... – Madarra Apr 26 '22 at 09:48
  • @Madarra Maybe your teacher wants you to use only the standard Java APIs instead of some third party APIs, is it what (s)he meant? – gouessej Apr 26 '22 at 14:12
  • Yes its was that, I have asked him what a really want. Because i didn't really understand what's is the difference with standard Java APIs and third party APIs. Thanks for your response. – Madarra Apr 26 '22 at 16:22

2 Answers2

1

I'm not quite clear what is meant by "native java library". Java itself (JDK / JRE) does not support parsing of media meta data. The only possibility would be to use a third party library like "Apache Tika":

How to read MP3 file tags

wrf
  • 56
  • 4
  • Thanks for your response, I will use this my professor said it was allowed tu use this library. – Madarra Apr 26 '22 at 16:25
1

You can do this with the Java standard library.

public class YourClass {

    Path yourFile = ...;
    BasicFileAttributes attr = Files.readAttributes(yourFile, BasicFileAttributes.class);
    
    System.out.println("creationTime: " + attr.creationTime());
    System.out.println("lastAccessTime: " + attr.lastAccessTime());
    System.out.println("lastModifiedTime: " + attr.lastModifiedTime());
    
    System.out.println("isDirectory: " + attr.isDirectory());
    System.out.println("isOther: " + attr.isOther());
    System.out.println("isRegularFile: " + attr.isRegularFile());
    System.out.println("isSymbolicLink: " + attr.isSymbolicLink());
    System.out.println("size: " + attr.size());
}

This is platform dependent and may throw exceptions or return unexpected results.

Read more at Managing Metadata (File and File Store Attributes).

David Kariuki
  • 1,522
  • 1
  • 15
  • 30