title: Android MediaRecorder recorded MPEG4 AAC audio files header incomplete
body: <p>I've got this android app (compileSdkVersion 23, minSdkVersion 16, targetSdkVersion 23) that records audio files using Android MediaRecorder.</p>
  
  <p>This is the way I start recording</p>
  
  <pre><code>mMediaRecorder = new MediaRecorder();
  mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
  mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
  mMediaRecorder.setAudioChannels(2);
  mMediaRecorder.setMaxDuration(mMaxRecordLength);
  mMediaRecorder.setAudioSamplingRate(44100);
  mMediaRecorder.setAudioEncodingBitRate(96000);
  mMediaRecorder.setOutputFile(mFileName);
  mMediaRecorder.prepare();
  mMediaRecorder.start();
  </code></pre>
  
  <p>and the way I stop recording</p>
  
  <pre><code>mMediaRecorder.stop();
  mMediaRecorder.reset();
  mMediaRecorder.release();
  </code></pre>
  
  <p><strong>THE PROBLEM:</strong></p>
  
  <p>when the recorded audio is longer than 1 minute and 50 seconds the header of the file seems to miss some information about the file content; I need these files to be played on a player that checks the informations inside the files (not only the file name extension) and, in this way, it's not able to recognize my recorded files when the duration is greater than 1:50 minutes.</p>
  
  <p>I recorded many files of many lenghts to understand what was going on, at the end I opened the files with a Hex Editor and this is what I found:</p>
  
  <ul>
  <li><p>FILE LENGHT 1:50 MINUTES OR LESS [<strong>GOOD FILE</strong>]:</p>
  
  <pre><code>....ftypmp42....isommp42..T.moov...lm
  
  vhd..................................
  
  ..................................@..
  
  ................................ymeta
  
  ...!hdlr........mdta................+
  
  keys............mdtacom.android.versi
  
  on...%ilst............data........6.0
  
  .1..S.trak...\tkhd...................
  
  .....................................
  
  ................@.............Scmdia.
  
  .. mdhd...............D.Jk........,hd
  
  lr........soun............SoundHandle
  
  ...S.minf....smhd...........$dinf....
  
  dref............url ......R.stbl...[s
  
  tsd...........Kmp4a..................
  
  .......D.....'esds...........@......w
  
  ...w............stts.................
  
  .....................................
  
  .....................................
  
  .....................................
  
  .....................................
  
  .....................................
  
  .....................................
  
  
  
          [CUT of so many dots and not much more]
  
  
  .....................................
  
  .....................................
  
  .....................................
  
  ......V...#........stsc..............
  
  ..........stco..........T....'free...
  
  ..............................A.mdat.
  @"....------------------------------
  
  -------------------------------------
  
  -------------------------------------
  
  -------------------------------------
  
  -------------------------------------
  
  -------------------------------------
  
  -------------------------------------
  
  ---------------.....6.tfZ...........(
  
  .Q*k...P..@.........?.H.....H\a...H=.
  
  .?.H.R..4a...7.....cTB~O.._e.......
  
  ......Z!.=s462.e.]."b...|a..[...uK...
  
  ...g.. .q.W,..6[...KO.R.j.5@W....B9dj
  
  1B....UK,.K3[-.=..;3...x.3.;r.u....|
  
  .)......."..e.YA.r..Y@.f..y...&lt;.R.).,
  
  .:.....&lt;..)..UT..X5.Q)..UTb2...5.....
  
  ...C.b=.7.O....yk.M...gH.=.`z.0..X..4
  
  S....j.G.\....|...DI.d....QE...6*....
  
  T....TD....Q*...|..~..z.........:.W.v
  
  ...w..m.9n......Yw..(PRRWm..Z.*..&amp;.f.
  
  .....\;[.c]YY#[53AC9.=..R.j...)5.....
  
  ...:.....R.A'&amp;jYR...SEb....Ef..f.cEy.
  
  v.J3.d...P../2.....-.d..MR.;4jb..)EbA
  
  r.......Q%5.......2.A..,!.EEe?.tO... 
  
  ..e......C.$......N.Q..QB..I1i%...3T.
  
  ...C..d"Q.*2..&lt;........S.4...{H...]..
  
  ....!4.N...Mr... ..ze"..%=..~....r`F;
  
  ....2.......M.....6)..4...a .*.\.....
  
  .P.JE].EM.....}X.My~..z..k.;^_.......
  N...._...=..:..pd5.._H..... L.?...nk.
  
  W.n1.Ct^....m...?WnR..........`F{.~.Y
  
  2..V....`\.GCL......)1..&lt;..4...l))...
  
  8%..0J....g..V....9.;..H'.%4...!.E%.P
  
  .W ....x...8...........BL.Y..1.A.eL.
  
  ...Xf.&amp;...'w....c...nY.&lt;7 .z.........
  
  .)....a..!.7O.........O...X....8...6
  
  )......A1./-.fq.Wc-WWK..J.r.:.G.|_6..
  
  _.&lt;....T-...A.y...........hw..m..F.
  
  .F.........n....L..D...m.e..n..S)....
  
  ...ia...@....F..............v...I....
  
  .s;bb&amp;...J.&amp;.!w.)..@.M.Z[*.:e=.....(.
  
  .1.1I.&amp;...........r.f...xR..!....H...
  
  [Y.......A}..#..`*..+.....S.A...C...
  
  TYtI;.y2.w....u.P./.J.3..."....[2V..K
  
  ...C...6*....B..#u....u..%".T.R.D.}.'
  
  .nZ..\.`.............o.........3..md
  
  ...A.!J.$....sF.S-...........=/]Mg...
  
  ...]].......zm.....DE.d.e=.T...B.....
  
  ...[..s&gt;.+:0......O...:..A8..S....8..
  
  6W)....Ue..s.....`eC......,'\LzMa...
  
  ...w........_.+I.q.u-g...X.o(.....w..
  
  .,.)..&gt;t..rH8E......I...H.C.i.S.-..8.
  
  p..6*.....Vn....X.*A..........$..@..q
  
  \..|.Cl..2..B.........zi.p.q.3....)..
  
  -..m%..B.].pm..f...~a)x...R.E;.c.....
  
  ..=P......l|.........:.+Mj...}.b6.N..
  
  W.......kY..,v6`....EH_p...d..X..w.p.
  
  
          [and so on]
  </code></pre></li>
  </ul>
  
  <hr>
  
  <ul>
  <li><p>FILE LENGHT 1:51 MINUTES OR MORE [<strong>BAD FILE</strong>]:</p>
  
  <pre><code>....ftypmp42....isommp42..T.free.....
  
  .....................................
  
  .....................................
  
  .....................................
  
  .....................................
  
  .....................................
  
  .....................................
  
  .....................................
  
  .....................................
  
  .....................................
  
  .....................................
  
  .....................................
  
  .....................................
  
  .....................................
  
  .....................................
  
  .....................................
  
  .....................................
  
  .....................................
  
  .....................................
  
  .....................................
  
  .....................................
  
  .....................................
  
  
  
          [CUT of so many dots and nothing else]
  
  
  
  .....................................
  
  .....................................
  
  ..............................kumdat.
  @"....------------------------------
  
  -------------------------------------
  
  -------------------------------------
  
  -------------------------------------
  
  -------------------------------------
  
  -------------------------------------
  
  -------------------------------------
  
  ---------------.....6-......"0P&amp;&amp;D...
  
  Q*.t(J..d.....5x...Y.}m..'...Z`....~.
  
  ..w...d.J.N....y./.\..|U:&gt;....Ol.}[(.
  
  ..Qe.v.\...gq..7..N..5..K.Au&gt;......&gt;3
  
  .cr.I.....a....=Y..A..9As........U.[.
  
  ..RK..15#[g... .....@.....F"....@8...
  
  &gt;Fb.~&lt;.nY...n#..S..#...W0....|..0...S
  
  ...Q]$t..J..$_PN.._y..I...}.=..t....
  
  VfP..|?p?]N...6-t8M...P...\.."!.*....
  
  ........U2.&gt;7......s...~n...[..%....)
  
  ..o..W...V.+.-.r*....E....C&amp;.z..l.}..
  
  Qzr.G...|.D.....^.u.6^5q..`....J..8..
  
  ._.....kIV?%.T.......&amp;......Bg$.(.N.O
  
  .N. d,E).2..d...E/.-.!..d.....H.`*,..
  
  ..vr....-0...@^....dUME!.l....K..m...
  
  ...T.......
  
  A.....Y..\..Os-#X..j^.....R|n.......
  
  ^...9..._U..D.s.
  
  .e.F^.,....8..6)V(."..aA.p.(..9.....L
  
  .Q..w.t.R.....EK%8w...1{...Uyo.....PN
  
  .p..........w..~.V.1...y.#.i...).....
  .6.@..(9n..&amp;u%.o..q..&lt;.Z7.......&amp;Q.B.
  
  M....&lt;..A...nM..b8...E .=..C..;\...$ 
  
  .....lD..`0...H..z....A.e........C..c
  
  ..zv...d...1.Qy..p.(L.3"A.g../.....7.
  
  .......3.j+_%b.G......QX'....'..,.3.j
  
  .T.........SZ^.tIe..X...Z/......Z..2.
  
  S.8..6).....Ac.."..sZ....uQ...b.[.:^.
  
  .6G+..}....n7.|F..T9._.2"N.g....*....
  
  ."R..iZ....9.Z..B.s$...&lt;.N.:...L...
  
  ......9w.x...Dt..3,Iy........85....(.
  
  .'..9..F*.w..p..&amp;#....P...)...&amp;....H.
  
  p.....KL.
  
  .@.....z...-.:[...A5.9@....kb...T.ke.
  
  a_~.4.#P.Or..$.I...9..8...Q[A.Xu+..f.
  
  .&amp;9...6.4.&lt;...A.. ..72.}9.r.TT...P...
  
  ,n.+....N........Mx.~z..s}.7..nw.,..
  
  .Q.v...z_x........+q.{.~M._....DL...
  
  i.9y..Y6v(..3h.....5.t..d.c....7..*(
  
  pt..3T..=1(."...,.Y..1c....5.....I6..
  
  V.J....-..$4Z.o.E3..1....w,.(..K&amp;...|
  
  ..0s.....w.T~...f......y.Tq.$.r5{....
  
  .FB...,......./...Ig-5%..B`$.Y.oF...
  
  ..6*.x....a8.,b....2Ew......"RT..M.V.
  
  .Z..N...}...F._......3....2&lt;...r..SI"
  
  ..`.......s[.$.T...Q.h$b{.k-x..]..+..
  
  .YA.)p. $&amp;..Du.....wWZ....B_$o...a:..
  
  j2.._.;2n.&amp;p....qy~.wQ,.E..ag9..7}.
  
  .....5.P.kC..yzx^...9.&lt;.z...D]TS..4Z.
  
  
          [and so on]
  </code></pre></li>
  </ul>
  
  <p>As you can see in the BAD FILE, after the first line there is a bunch of dots where in the GOOD FILE there are informations.</p>
  
  <p>Can you explain me what's going on and what could I do to fix my problem?</p>