MediaPlayer.setDataSource causa IOException para un archivo válido

Este código solía funcionar. Entonces, tal vez cambié algo, en algún lugar (o si sé que Android es correcto, una actualización introdujo un error en el reproductor multimedia). ¡Dejó de funcionar en algunos dispositivos! Especialmente mi Nexus S (2.3.6).

El archivo test.m4a (17 775 201 bytes) fue descargado por la aplicación. Para verificar su integridad, lo copié a la tarjeta SD y lo reproduje en mi PC. ¡No hay problema! También lo comparó binariamente con el archivo original, y coincidió al 100%.

 try { _mediaPlayer = new MediaPlayer(); _mediaPlayer.setOnCompletionListener(this); _mediaPlayer.setOnPreparedListener(this); _mediaPlayer.setOnSeekCompleteListener(this); _mediaPlayer.setOnBufferingUpdateListener(this); _mediaPlayer.setOnInfoListener(this); _mediaPlayer.setOnErrorListener(this); // I even tried reading the file from SD card. Same error... File file = new File("/data/data/com.mycompany.myapp/files/MediaCache/Test.m4a"); // file.isFile() == true // file.length() == expected value! FileInputStream is = new FileInputStream(file); _mediaPlayer.setDataSource(is.getFD()); // Throws! // If I use the filename as parameter, it throws later when preparing the media player... _mediaPlayer.prepareAsync(); } catch (Exception e) { // java.io.IOException: setDataSourceFD failed.: status=0x80000000 e.printStackTrace(); } 

P: ¿Qué podría causar esta IOException para setDataSourceFD cuando el archivo es realmente válido?

ACTUALIZACIÓN: Aquí hay un archivo de audio de 98 kB que no puedo reproducir en mi Nexus S (2.3.6): http://www.2shared.com/audio/wUKoRiQk/test.html

Un amigo mío ejecuta algún dispositivo ZTE (2.2) y parece funcionar. ¡No lo entiendo!

Me gustaría decirte que MediaPlayer se está ejecutando y funcionando correctamente. A continuación están todas mis hipótesis. No los tomes demasiado en serio.

Es su archivo test.m4a que está codificado en un formato tal que MediaPlayer no puede decodificar, por lo tanto, arroja un error al decir que no puede crear el MediaPlayer para que lo use. Parece que lo codificaste en algunos códecs FFmpeg que tenías en tu computadora. Sería mejor si intentara crear el archivo sin utilizar códecs avanzados como FFmpeg, ya que Android no puede decodificar códecs avanzados sobre la marcha.

Sin embargo, no tengo la respuesta de por qué algunos teléfonos inteligentes pueden reproducir su archivo M4A, mientras que otros no. Mi sugerencia para usted es usar un formato OGG simple que Audacity ya haya instalado, para todos sus proyectos Android, porque el códec OGG que tiene Audacity es lo suficientemente simple como para que Android decodifique sobre la marcha. No pretendo que muchos desarrolladores usen principalmente OGG, solo que OGG no parece tener muchos problemas con MediaPlayer y SoundPool al usar códecs simples. Necesita más investigación …

Incluso mi libro, Beginning Android 4 Game Development, depende de los archivos OGG.

Aquí está mi prueba a continuación. Este es el archivo “test.m4a” que estoy usando desde su enlace. Lo hice para que funcione en un ciclo sin fin, por lo que es una prueba de evidencia 100%:

 03-18 01:05:22.826: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:22.826: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:22.936: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:22.936: I/MediaPlayer(1289): IOException... 03-18 01:05:22.936: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:22.936: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:23.037: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:23.046: I/MediaPlayer(1289): IOException... 03-18 01:05:23.046: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:23.046: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:23.146: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:23.146: I/MediaPlayer(1289): IOException... 03-18 01:05:23.146: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:23.156: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:23.256: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:23.256: I/MediaPlayer(1289): IOException... 03-18 01:05:23.256: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:23.256: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:23.366: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:23.366: I/MediaPlayer(1289): IOException... 03-18 01:05:23.366: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:23.366: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:23.476: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:23.476: I/MediaPlayer(1289): IOException... 03-18 01:05:23.476: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:23.476: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:23.586: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:23.586: I/MediaPlayer(1289): IOException... 03-18 01:05:23.586: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:23.586: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:23.696: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:23.696: I/MediaPlayer(1289): IOException... 03-18 01:05:23.696: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:23.696: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:23.806: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:23.806: I/MediaPlayer(1289): IOException... 03-18 01:05:23.806: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:23.806: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:23.917: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:23.917: I/MediaPlayer(1289): IOException... 03-18 01:05:23.917: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:23.917: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:24.026: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:24.026: I/MediaPlayer(1289): IOException... 03-18 01:05:24.026: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:24.026: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:24.136: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:24.136: I/MediaPlayer(1289): IOException... 03-18 01:05:24.136: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:24.136: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:24.246: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:24.246: I/MediaPlayer(1289): IOException... 03-18 01:05:24.246: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:24.246: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:24.356: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:24.356: I/MediaPlayer(1289): IOException... 03-18 01:05:24.356: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:24.356: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:24.466: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:24.466: I/MediaPlayer(1289): IOException... 03-18 01:05:24.466: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:24.466: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:24.856: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:24.856: I/MediaPlayer(1289): IOException... 03-18 01:05:24.856: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:24.856: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:25.017: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:25.017: I/MediaPlayer(1289): IOException... 03-18 01:05:25.017: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:25.017: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:25.146: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:25.157: I/MediaPlayer(1289): IOException... 03-18 01:05:25.157: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:25.157: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:25.266: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:25.266: I/MediaPlayer(1289): IOException... 03-18 01:05:25.266: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:25.266: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:25.376: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:25.376: I/MediaPlayer(1289): IOException... 03-18 01:05:25.376: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:25.376: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:25.486: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:25.486: I/MediaPlayer(1289): IOException... 03-18 01:05:25.486: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:25.486: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:25.586: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:25.586: I/MediaPlayer(1289): IOException... 03-18 01:05:25.586: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:25.586: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:25.696: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:25.696: I/MediaPlayer(1289): IOException... 03-18 01:05:25.696: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:25.696: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:25.806: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:25.806: I/MediaPlayer(1289): IOException... 03-18 01:05:25.806: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:25.806: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:25.916: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:25.916: I/MediaPlayer(1289): IOException... 03-18 01:05:25.916: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:25.916: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:26.026: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:26.026: I/MediaPlayer(1289): IOException... 03-18 01:05:26.026: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:26.026: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:26.136: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:26.136: I/MediaPlayer(1289): IOException... 03-18 01:05:26.136: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:26.136: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:26.246: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:26.246: I/MediaPlayer(1289): IOException... 03-18 01:05:26.246: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:26.246: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:26.356: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:26.356: I/MediaPlayer(1289): IOException... 03-18 01:05:26.356: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:26.356: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:26.466: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:26.466: I/MediaPlayer(1289): IOException... 03-18 01:05:26.466: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:26.466: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:26.577: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:26.577: I/MediaPlayer(1289): IOException... 03-18 01:05:26.577: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:26.577: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:26.697: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:26.697: I/MediaPlayer(1289): IOException... 03-18 01:05:26.697: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:26.697: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:26.807: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:26.807: I/MediaPlayer(1289): IOException... 03-18 01:05:26.807: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:26.807: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:26.917: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:26.917: I/MediaPlayer(1289): IOException... 03-18 01:05:26.917: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:26.917: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:27.027: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:27.027: I/MediaPlayer(1289): IOException... 03-18 01:05:27.027: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:27.027: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:27.137: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:27.137: I/MediaPlayer(1289): IOException... 03-18 01:05:27.137: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:27.137: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:27.236: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:27.236: I/MediaPlayer(1289): IOException... 03-18 01:05:27.236: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:27.236: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:27.347: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:27.347: I/MediaPlayer(1289): IOException... 03-18 01:05:27.347: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:27.347: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:27.457: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:27.457: I/MediaPlayer(1289): IOException... 03-18 01:05:27.457: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:27.457: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:27.567: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:27.567: I/MediaPlayer(1289): IOException... 03-18 01:05:27.567: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:27.567: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:27.677: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:27.677: I/MediaPlayer(1289): IOException... 03-18 01:05:27.677: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:27.677: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:27.787: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:27.787: I/MediaPlayer(1289): IOException... 03-18 01:05:27.787: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:27.787: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:27.907: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:27.907: I/MediaPlayer(1289): IOException... 03-18 01:05:27.907: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:27.907: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:28.007: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:28.017: I/MediaPlayer(1289): IOException... 03-18 01:05:28.017: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:28.017: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:28.127: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:28.127: I/MediaPlayer(1289): IOException... 03-18 01:05:28.127: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:28.127: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:28.237: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:28.237: I/MediaPlayer(1289): IOException... 03-18 01:05:28.237: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:28.237: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:28.347: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:28.347: I/MediaPlayer(1289): IOException... 03-18 01:05:28.347: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:28.347: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:28.457: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:28.457: I/MediaPlayer(1289): IOException... 03-18 01:05:28.457: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:28.457: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:28.567: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:28.567: I/MediaPlayer(1289): IOException... 03-18 01:05:28.567: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:28.567: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:28.677: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:28.677: I/MediaPlayer(1289): IOException... 03-18 01:05:28.677: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:28.677: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:28.787: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:28.787: I/MediaPlayer(1289): IOException... 03-18 01:05:28.787: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:28.787: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:28.907: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:28.907: I/MediaPlayer(1289): IOException... 03-18 01:05:28.907: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:28.907: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:29.017: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:29.017: I/MediaPlayer(1289): IOException... 03-18 01:05:29.017: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:29.017: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:29.127: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:29.127: I/MediaPlayer(1289): IOException... 03-18 01:05:29.127: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:29.127: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:29.237: E/MediaPlayer(1289): Unable to to create media player 03-18 01:05:29.237: I/MediaPlayer(1289): IOException... 03-18 01:05:29.237: D/MediaPlayer(1289): Making sure it is in IDLE state... 03-18 01:05:29.237: D/MediaPlayer(1289): Setting Data Source... 03-18 01:05:29.327: D/dalvikvm(1289): Calling exit(1) 

Ahora, aquí está el código que hice, que se muestra a continuación:

 package nttu.edu.test; import java.io.IOException; import android.app.Activity; import android.content.res.AssetFileDescriptor; import android.content.res.AssetManager; import android.media.MediaPlayer; import android.os.Bundle; import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.widget.TextView; public class MediaPlayerTest extends Activity implements OnTouchListener { MediaPlayer player = null; TextView tv; public final String fileName = "sounds/test.m4a"; AssetManager asset; AssetFileDescriptor afd; public void onCreate(Bundle b) { super.onCreate(b); tv = new TextView(this); tv.setOnTouchListener(this); tv.setText("Touch to start playing the music."); Log.d("MediaPlayer", "Creating MediaPlayer."); player = new MediaPlayer(); try { asset = this.getAssets(); afd = asset.openFd(fileName); } catch (Exception e) { } while (true) { try { Log.d("MediaPlayer", "Making sure it is in IDLE state..."); player.reset(); Log.d("MediaPlayer", "Setting Data Source..."); player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); Log.d("MediaPlayer", "Now initialized. Preparing it."); player.prepare(); break; } catch (IllegalArgumentException e) { Log.i("MediaPlayer", "IllegalArgumentException..."); } catch (IllegalStateException e) { Log.i("MediaPlayer", "IllegalStateException..."); } catch (IOException e) { Log.i("MediaPlayer", "IOException..."); } } try { afd.close(); } catch (IOException e) { } setContentView(tv); Log.d("MediaPlayer", "Everything is prepared and ready to play the music file."); } public boolean onTouch(View v, MotionEvent e) { if (e.getAction() == MotionEvent.ACTION_UP) { Log.d("MediaPlayer", "Playing the audio."); if (player.getAudioSessionId() != 0) { player.start(); Log.d("MediaPlayer", "Success!"); } } return true; } protected void onResume() { super.onResume(); } protected void onPause() { super.onPause(); if (player.getAudioSessionId() != 0) { player.pause(); if (isFinishing()) { player.stop(); player.release(); } } } } 

Observe la variable String final cerca de la parte superior del fragmento de código. Si reemplazo esa línea con esto:

 public final String fileName = "sounds/test.ogg"; 

Y vuelve a codificar tu archivo “test.m4a” en un archivo Ogg Vorbis, y no hay otros cambios en el código, puedo reproducir el archivo OGG muy bien. Aquí están los registros de cambios para el archivo OGG:

 03-18 01:14:21.547: D/gralloc_goldfish(1335): Emulator without GPU emulation detected. 03-18 01:14:23.467: D/dalvikvm(1335): GC_CONCURRENT freed 50K, 4% free 5952K/6151K, paused 7ms+3ms 03-18 01:14:24.647: D/MediaPlayer(1335): Creating MediaPlayer. 03-18 01:14:24.657: D/MediaPlayer(1335): Making sure it is in IDLE state... 03-18 01:14:24.657: D/MediaPlayer(1335): Setting Data Source... 03-18 01:14:24.707: D/MediaPlayer(1335): Now initialized. Preparing it. 03-18 01:14:24.927: D/MediaPlayer(1335): Everything is prepared and ready to play the music file. 03-18 01:14:26.797: D/MediaPlayer(1335): Playing the audio. 03-18 01:14:26.817: D/MediaPlayer(1335): Success! 

Y luego se detiene aquí. No hay bucle dando vueltas.

Más evidencia para apoyar mi respuesta:

Enlace 1: Referencia del SDK de Android (¡Mire el diagtwig de estado, muy importante!)

Y una imagen (Imagen de su “test.m4a” y su archivo recodificado en un archivo OGG, colocados uno al lado del otro):

Imagen de su

¿Has probado usar setDataSource (FileDescriptor fd, offset largo, long length)?

Encontré esto después de googlear algo que sugiere que setDataSource (FileDescriptor) podría causar problemas con IOException. Parece extraño que no pudo averiguar la longitud del archivo por sí solo …

El análisis del archivo test.m4a revela que el archivo no tiene ningún encabezado M4A. Se ve exactamente como un archivo RAW AAC, que no es compatible con Android. Debe haber algo de AAC no estándar adicional en el teléfono ZTE Blade.

Yo diría que esta es la respuesta exacta a esta pregunta, con la ayuda de algunas respuestas aquí. ¿Cómo divido los puntos de recompensa?

Solución muy simple de esto. Primero configure FileInputStream usando su ruta. Después de esto, configure FileDescriptor en setDataSource. Vamos a ver

  MediaPlayer mp = new MediaPlayer(); String audioStoragePath =Environment.getExternalStorageDirectory() +"/Download/audio.mp3"; //File sdIconStorageDir = new File(iconsStoragePath); Log.d("AudioStartService"," path " + audioStoragePath); try { FileInputStream is = new FileInputStream(audioStoragePath); mp.setDataSource(is.getFD()); mp.prepare(); mp.start(); } catch (Exception e) { e.printStackTrace(); } 

es trabajo para mi