{
  "id": "1",
  "title": "How a Minecraft mod led me to build my own Java media library from scratch",
  "canonicalUrl": "https://dev.tamkungz.me/blog/2026-03-14-how-a-minecraft-mod-led-me-to-build-my-own-java-media-library-from-scratch",
  "jsonUrl": "https://dev.tamkungz.me/blog/2026-03-14-how-a-minecraft-mod-led-me-to-build-my-own-java-media-library-from-scratch.json",
  "author": {
    "name": "TamKungZ_",
    "url": "https://dev.tamkungz.me"
  },
  "language": "en",
  "languageName": "English",
  "textDirection": "ltr",
  "category": "Project Story",
  "tags": [
    "CodecMedia",
    "Java",
    "media parsing",
    "Minecraft modding",
    "OpenAL"
  ],
  "publishedDate": "2026-03-14",
  "updatedDate": "2026-11-07",
  "readingTimeMinutes": 3,
  "wordCount": 542,
  "image": "https://dev.tamkungz.me/assets-image/blog/banner.webp",
  "summary": "A project story about how debugging MP3 playback in a Minecraft mod led TamKungZ_ to build CodecMedia, a Java media probing and validation library.",
  "excerpt": "I wasn't trying to build another media converter. What I actually wanted was something that could answer a much simpler question: \"Is this file really what it claims to be?\" Tha...",
  "keywords": [
    "CodecMedia",
    "Java media library",
    "media validation",
    "MP3 parser",
    "Minecraft modding",
    "OpenAL",
    "TamKungZ_"
  ],
  "markdown": "I wasn't trying to build another media converter.\n\nWhat I actually wanted was something that could answer a much simpler question:\n\n**\"Is this file really what it claims to be?\"**\n\nThat sounds obvious until you start looking at media files beyond their extensions.\n\nA file named `song.mp3` isn't necessarily a valid MP3. Some players will happily play malformed files. Others won't. Some libraries reject them entirely. Extensions don't tell the whole story.\n\nThat realization eventually became **CodecMedia**.\n\n---\n\nIt started while I was building a Minecraft mod.\n\nI wanted to play MP3 files directly through OpenAL instead of Minecraft's built-in audio system. To do that, I needed a low-level MP3 decoder, so I used **Zoom JLayer**, a pure Java decoder from the early 2000s.\n\nIt worked...\n\n...until it didn't.\n\nSome MP3 files decoded perfectly. Others failed completely, even though they played fine in normal media players.\n\nInstead of assuming it was a bug, I started reading JLayer's source code.\n\nThat was when I discovered something I had never really thought about before.\n\nNot every MP3 file is structured the same way.\n\nDifferent bitrate modes, different frame layouts, optional headers, metadata blocks—everything is described by the bytes inside the file, not by its filename.\n\nThe more I looked, the more interesting it became.\n\nEventually I wasn't trying to decode MP3 anymore.\n\nI was trying to understand how media formats actually describe themselves.\n\n---\n\nThat curiosity eventually expanded beyond MP3.\n\nWAV.\n\nFLAC.\n\nOGG.\n\nAIFF.\n\nEach format has its own signature, internal structure, metadata layout, and validation rules.\n\nInstead of relying on file extensions, I started reading the actual binary structures directly.\n\nThat became the foundation of CodecMedia.\n\n---\n\nToday, CodecMedia focuses primarily on **probing and validating media files** by parsing their actual byte structure.\n\nRather than asking \"Does this filename end with `.mp3`?\", it asks questions like:\n\n* Does the file contain a valid format signature?\n* Is the container structure correct?\n* Are the headers internally consistent?\n* Can the streams actually be identified?\n* Is the metadata structurally valid?\n\nBecause of that, CodecMedia can identify media types from the file itself instead of trusting the extension.\n\nUsing it is straightforward.\n\n```java\nCodecMediaEngine engine = CodecMedia.createDefault();\n\nProbeResult probe = engine.probe(Path.of(\"song.mp3\"));\n\nSystem.out.println(probe.mimeType());\nSystem.out.println(probe.durationMillis());\nSystem.out.println(probe.streams().get(0).codec());\nSystem.out.println(probe.streams().get(0).sampleRate());\n```\n\nIf you want to verify that a file is structurally valid before processing it, validation is equally simple.\n\n```java\nValidationResult validation = engine.validate(\n    Path.of(\"song.mp3\"),\n    new ValidationOptions(true, 64L * 1024L * 1024L)\n);\n\nSystem.out.println(validation.valid());\nSystem.out.println(validation.errors());\n```\n\nCodecMedia currently understands formats including MP3, WAV, FLAC, OGG (Vorbis and Opus), AIFF/AIFC, and several others.\n\n---\n\nCodecMedia also contains basic media conversion features.\n\nHowever, conversion is not its primary goal.\n\nThere are already excellent projects like FFmpeg that provide far more complete transcoding capabilities.\n\nCodecMedia is designed differently.\n\nIts primary purpose is to inspect, identify, and validate media by understanding the file's binary format directly, while providing lightweight utilities around that information.\n\n---\n\nI don't expect CodecMedia to replace existing media frameworks.\n\nThere are plenty of mature solutions available.\n\nThe reason I built it wasn't because those tools weren't good enough.\n\nI built it because I wanted to understand what happens underneath them.\n\nReading binary structures, interpreting headers, validating file layouts, and implementing support myself taught me far more than simply calling an external library ever could.\n\nCodecMedia is the result of that exploration.\n\nIf it also ends up being useful to someone else, that's a nice bonus.\n\nMaven Central: https://central.sonatype.com/artifact/me.tamkungz.codecmedia/codecmedia\n\nGitHub: https://github.com/CodecMediaLib/codecmedia-java\n",
  "html": "<p>I wasn’t trying to build another media converter.</p>\n<p>What I actually wanted was something that could answer a much simpler question:</p>\n<p><strong>“Is this file really what it claims to be?”</strong></p>\n<p>That sounds obvious until you start looking at media files beyond their extensions.</p>\n<p>A file named <code>song.mp3</code> isn’t necessarily a valid MP3. Some players will happily play malformed files. Others won’t. Some libraries reject them entirely. Extensions don’t tell the whole story.</p>\n<p>That realization eventually became <strong>CodecMedia</strong>.</p>\n<hr>\n<p>It started while I was building a Minecraft mod.</p>\n<p>I wanted to play MP3 files directly through OpenAL instead of Minecraft’s built-in audio system. To do that, I needed a low-level MP3 decoder, so I used <strong>Zoom JLayer</strong>, a pure Java decoder from the early 2000s.</p>\n<p>It worked…</p>\n<p>…until it didn’t.</p>\n<p>Some MP3 files decoded perfectly. Others failed completely, even though they played fine in normal media players.</p>\n<p>Instead of assuming it was a bug, I started reading JLayer’s source code.</p>\n<p>That was when I discovered something I had never really thought about before.</p>\n<p>Not every MP3 file is structured the same way.</p>\n<p>Different bitrate modes, different frame layouts, optional headers, metadata blocks—everything is described by the bytes inside the file, not by its filename.</p>\n<p>The more I looked, the more interesting it became.</p>\n<p>Eventually I wasn’t trying to decode MP3 anymore.</p>\n<p>I was trying to understand how media formats actually describe themselves.</p>\n<hr>\n<p>That curiosity eventually expanded beyond MP3.</p>\n<p>WAV.</p>\n<p>FLAC.</p>\n<p>OGG.</p>\n<p>AIFF.</p>\n<p>Each format has its own signature, internal structure, metadata layout, and validation rules.</p>\n<p>Instead of relying on file extensions, I started reading the actual binary structures directly.</p>\n<p>That became the foundation of CodecMedia.</p>\n<hr>\n<p>Today, CodecMedia focuses primarily on <strong>probing and validating media files</strong> by parsing their actual byte structure.</p>\n<p>Rather than asking “Does this filename end with <code>.mp3</code>?”, it asks questions like:</p>\n<ul>\n<li>Does the file contain a valid format signature?</li>\n<li>Is the container structure correct?</li>\n<li>Are the headers internally consistent?</li>\n<li>Can the streams actually be identified?</li>\n<li>Is the metadata structurally valid?</li>\n</ul>\n<p>Because of that, CodecMedia can identify media types from the file itself instead of trusting the extension.</p>\n<p>Using it is straightforward.</p>\n<pre><code class=\"hljs language-java\"><span class=\"hljs-type\">CodecMediaEngine</span> <span class=\"hljs-variable\">engine</span> <span class=\"hljs-operator\">=</span> CodecMedia.createDefault();\n\n<span class=\"hljs-type\">ProbeResult</span> <span class=\"hljs-variable\">probe</span> <span class=\"hljs-operator\">=</span> engine.probe(Path.of(<span class=\"hljs-string\">&quot;song.mp3&quot;</span>));\n\nSystem.out.println(probe.mimeType());\nSystem.out.println(probe.durationMillis());\nSystem.out.println(probe.streams().get(<span class=\"hljs-number\">0</span>).codec());\nSystem.out.println(probe.streams().get(<span class=\"hljs-number\">0</span>).sampleRate());\n</code></pre>\n<p>If you want to verify that a file is structurally valid before processing it, validation is equally simple.</p>\n<pre><code class=\"hljs language-java\"><span class=\"hljs-type\">ValidationResult</span> <span class=\"hljs-variable\">validation</span> <span class=\"hljs-operator\">=</span> engine.validate(\n    Path.of(<span class=\"hljs-string\">&quot;song.mp3&quot;</span>),\n    <span class=\"hljs-keyword\">new</span> <span class=\"hljs-title class_\">ValidationOptions</span>(<span class=\"hljs-literal\">true</span>, <span class=\"hljs-number\">64L</span> * <span class=\"hljs-number\">1024L</span> * <span class=\"hljs-number\">1024L</span>)\n);\n\nSystem.out.println(validation.valid());\nSystem.out.println(validation.errors());\n</code></pre>\n<p>CodecMedia currently understands formats including MP3, WAV, FLAC, OGG (Vorbis and Opus), AIFF/AIFC, and several others.</p>\n<hr>\n<p>CodecMedia also contains basic media conversion features.</p>\n<p>However, conversion is not its primary goal.</p>\n<p>There are already excellent projects like FFmpeg that provide far more complete transcoding capabilities.</p>\n<p>CodecMedia is designed differently.</p>\n<p>Its primary purpose is to inspect, identify, and validate media by understanding the file’s binary format directly, while providing lightweight utilities around that information.</p>\n<hr>\n<p>I don’t expect CodecMedia to replace existing media frameworks.</p>\n<p>There are plenty of mature solutions available.</p>\n<p>The reason I built it wasn’t because those tools weren’t good enough.</p>\n<p>I built it because I wanted to understand what happens underneath them.</p>\n<p>Reading binary structures, interpreting headers, validating file layouts, and implementing support myself taught me far more than simply calling an external library ever could.</p>\n<p>CodecMedia is the result of that exploration.</p>\n<p>If it also ends up being useful to someone else, that’s a nice bonus.</p>\n<p>Maven Central: <a href=\"https://central.sonatype.com/artifact/me.tamkungz.codecmedia/codecmedia\">https://central.sonatype.com/artifact/me.tamkungz.codecmedia/codecmedia</a></p>\n<p>GitHub: <a href=\"https://github.com/CodecMediaLib/codecmedia-java\">https://github.com/CodecMediaLib/codecmedia-java</a></p>\n",
  "text": "I wasn't trying to build another media converter. What I actually wanted was something that could answer a much simpler question: \"Is this file really what it claims to be?\" That sounds obvious until you start looking at media files beyond their extensions. A file named isn't necessarily a valid MP3. Some players will happily play malformed files. Others won't. Some libraries reject them entirely. Extensions don't tell the whole story. That realization eventually became CodecMedia. --- It started while I was building a Minecraft mod. I wanted to play MP3 files directly through OpenAL instead of Minecraft's built-in audio system. To do that, I needed a low-level MP3 decoder, so I used Zoom JLayer, a pure Java decoder from the early 2000s. It worked... ...until it didn't. Some MP3 files decoded perfectly. Others failed completely, even though they played fine in normal media players. Instead of assuming it was a bug, I started reading JLayer's source code. That was when I discovered something I had never really thought about before. Not every MP3 file is structured the same way. Different bitrate modes, different frame layouts, optional headers, metadata blocks—everything is described by the bytes inside the file, not by its filename. The more I looked, the more interesting it became. Eventually I wasn't trying to decode MP3 anymore. I was trying to understand how media formats actually describe themselves. --- That curiosity eventually expanded beyond MP3. WAV. FLAC. OGG. AIFF. Each format has its own signature, internal structure, metadata layout, and validation rules. Instead of relying on file extensions, I started reading the actual binary structures directly. That became the foundation of CodecMedia. --- Today, CodecMedia focuses primarily on probing and validating media files by parsing their actual byte structure. Rather than asking \"Does this filename end with ?\", it asks questions like: Does the file contain a valid format signature? Is the container structure correct? Are the headers internally consistent? Can the streams actually be identified? Is the metadata structurally valid? Because of that, CodecMedia can identify media types from the file itself instead of trusting the extension. Using it is straightforward. If you want to verify that a file is structurally valid before processing it, validation is equally simple. CodecMedia currently understands formats including MP3, WAV, FLAC, OGG (Vorbis and Opus), AIFF/AIFC, and several others. --- CodecMedia also contains basic media conversion features. However, conversion is not its primary goal. There are already excellent projects like FFmpeg that provide far more complete transcoding capabilities. CodecMedia is designed differently. Its primary purpose is to inspect, identify, and validate media by understanding the file's binary format directly, while providing lightweight utilities around that information. --- I don't expect CodecMedia to replace existing media frameworks. There are plenty of mature solutions available. The reason I built it wasn't because those tools weren't good enough. I built it because I wanted to understand what happens underneath them. Reading binary structures, interpreting headers, validating file layouts, and implementing support myself taught me far more than simply calling an external library ever could. CodecMedia is the result of that exploration. If it also ends up being useful to someone else, that's a nice bonus. Maven Central: https://central.sonatype.com/artifact/me.tamkungz.codecmedia/codecmedia GitHub: https://github.com/CodecMediaLib/codecmedia-java",
  "blog": {
    "name": "TamKungZ_ Blog",
    "url": "https://dev.tamkungz.me/blog",
    "indexJson": "https://dev.tamkungz.me/blog/index.json"
  }
}