1

I have a .m4a file that needs to be of mime type "audio/mp4" currently it is "video/mp4".

When I execute "file Rooo.m4a -i"

Rooo.m4a: video/mp4; charset=binary

Is it possible to change it manually at runtime?

Jezer Crespo
  • 2,152
  • 3
  • 24
  • 27

1 Answers1

0

I suppose (from command file Rooo.m4a -i) that you're using some linux OS. Java uses normal linux configuration where file types are guessed by /etc/mime.types and $HOME/.mime.types. Are you really sure you need to change it at runtime? Possible solution is to change system mime.types; this page can be useful in it.

If you're sure you probably need to check documentation for Files.probeContentType method. It states that you need to define your own FileTypeDetector subclasses and list them in META-INF/services.

File type detectors are typically installed by placing them in a JAR file on the application class path or in the extension directory, the JAR file contains a provider-configuration file named java.nio.file.spi.FileTypeDetector in the resource directory META-INF/services, and the file lists one or more fully-qualified names of concrete subclass of FileTypeDetector that have a zero argument constructor.

Defining you own FileTypeDetector should solve the problem because it checks file type before the default one does.

See also: Getting A File's Mime Type In Java

Community
  • 1
  • 1
Sergey Fedorov
  • 2,169
  • 1
  • 15
  • 26