Re: [mpg123-devel] mpg123_length not correct
Brought to you by:
sobukus
From: Sven B. <s.b...@gm...> - 2018-02-17 22:20:57
|
Hello Thomas, thanks for your mail. I changed the method like this: protected override bool OnGetData(out short[] samples) { this.mutex.WaitOne(); log.debug("OnGetData called"); if (this.mp3Handle != IntPtr.Zero) { byte[] buffer = new byte[this.bufferSize]; IntPtr done = IntPtr.Zero; int result = MPGImport.mpg123_read(this.mp3Handle, buffer, buffer.Length, out done); log.debug("result = " + result); if ((result != (int)MPGImport.mpg123_errors.MPG123_OK) && (result != (int)MPGImport.mpg123_errors.MPG123_DONE) && (result != (int)MPGImport.mpg123_errors.MPG123_NEW_FORMAT)) { samples = null; log.error("Error during reading samples: " + MPGImport.mpg123_strerror(this.mp3Handle)); this.mutex.ReleaseMutex(); } else { log.debug("decoded " + done.ToInt32().ToString() + " byte"); samples = new short[done.ToInt32() / 2]; Buffer.BlockCopy(buffer, 0, samples, 0, done.ToInt32()); } } else { samples = null; } this.mutex.ReleaseMutex(); return (samples != null); } Now I get result = -10 sometimes at the end of a track. Do you know, why this happens? I took a look in the documentation, where it says "MPG123_NEED_MORE Message: For feed reader: "Feed me more!" (call mpg123_feed() or mpg123_decode() with some new input data)." But I can't call with new data, since I'm reaching the end of the file. Thanks for your help. Sincerely Sven -----Ursprüngliche Nachricht----- Von: Thomas Orgis [mailto:th...@or...] Gesendet: Sonntag, 11. Februar 2018 10:10 An: mpg...@li...; Sven Baus Betreff: Re: [mpg123-devel] mpg123_length not correct Hi, there is something weird with the variable done. First, you mix up the return of the count of decoded bytes with the actual return value of mpg123_read(). You get MPG123_OK or MPG123_DONE, or any other of the state/error codes as function return value. The last parameter is also supposed to be the address of a variable to write to ... not just a pointer to nowhere. You call a method on a null pointer there, as it seems (done.toInt). Alrighty then, Thomas -- Diese Nachricht wurde von meinem Android-Gerät mit K-9 Mail gesendet. --- Diese E-Mail wurde von AVG auf Viren geprüft. http://www.avg.com |