MediaPlayer.setDataSource 导致有效文件出现 IOException

2023-11-30

这段代码曾经有效。然后,也许我在某个地方改变了一些东西(或者如果我对 Android 很了解的话,更新会在媒体播放器中引入一个错误)。它停止工作了some设备!特别是我的 Nexus S (2.3.6)。

文件test.m4a(17 775 201 字节)已由应用下载。为了验证其完整性,我将其复制到 SD 并在我的 PC 上播放。没问题!还将其与原始文件进行二进制比较,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();
}

Q:什么可能会导致这种情况IOException for setDataSourceFD文件什么时候确实有效?

更新:这是一个 98 kB 的音频文件,我无法在 Nexus S (2.3.6) 上播放: http://www.2shared.com/audio/wUKoRiQk/test.html

我的一个朋友运行一些中兴设备(2.2),它似乎可以工作。我不明白!


我想告诉您 MediaPlayer 正在正常运行和工作。以下是我的全部假设。别把他们太当回事。

您的 test.m4a 文件以 MediaPlayer 无法解码的格式进行编码,因此会抛出一条错误,指出它无法创建 MediaPlayer 供您使用。似乎您用计算机上的某些 FFmpeg 编解码器对其进行了编码。如果您尝试在不使用 FFmpeg 等高级编解码器的情况下创建文件会更好,因为 Android 无法即时解码高级编解码器。

但是,我不知道为什么有些智能手机可以播放 M4A 文件,而其他智能手机则不能。我建议您为所有 Android 项目使用 Audacity 已经安装的简单 OGG 格式,因为 Audacity 拥有的 OGG 编解码器对于 Android 来说足够简单,可以即时解码。我并不是说许多开发人员主要使用 OGG,只是说 OGG 在使用简单的编解码器时似乎在 MediaPlayer 和 SoundPool 方面没有太多问题。需要更多研究...

甚至我的书《Beginning Android 4 Game Development》也依赖于 OGG 文件。

下面是我的证明。这是我从您的链接中使用的文件“test.m4a”。我让它无限循环运行,使其成为 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)

现在,这是我编写的代码,如下所示:

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();
            }
        }
    }
}

请注意代码片段顶部附近的最终 String 变量。如果我用以下内容替换该行:

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

并将您的“test.m4a”文件重新编码为 Ogg Vorbis 文件,并且代码中没有其他更改,我可以很好地播放 OGG 文件。以下是 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!

然后就停在这里了。没有循环。

更多证据支持我的答案:

链接1:Android SDK参考(一定要看状态图,非常重要!)

和一张图片(“test.m4a”的图像和重新编码为 OGG 文件的文件,并排放置。):

Image of your "test.m4a" and your file re-encoded into an OGG file, placed side-by-side.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

MediaPlayer.setDataSource 导致有效文件出现 IOException 的相关文章

  • Visual Studio 不允许我在 Android 物理设备上进行调试

    我正在使用 Xamarin 和 Visual Studio 2013 开发 Android 应用程序 我已将 Android 小程序连接到计算机 Sansung Kies 识别了该设备 Adb 也能识别它 因为当我输入 adb device
  • 在 Android 中创建和使用 9 补丁图像

    我最近听说了 9 补丁图像 我知道它是 9 平铺的并且是可拉伸的 我想了解更多 如何创建 9 块图像 有什么工具吗 我可以通过 AndroidSDK 或代码创建它吗 9 patch 相对于普通 png 的主要优点 它是否可以根据屏幕动态 自
  • 单击 RecyclerView 内的 ImageView 时更改图像资源

    每当我单击它时 单击图像 而不是项目 我都会尝试更改回收器视图内特定位置的设备图像资源 我尝试将 setOnClickListener 放入 onBindViewHolder 方法中 但只有最后一个项目受到影响 这是我的回收者视图 http
  • 如何检测和管理来电(Android)?

    我想创建一个应用程序 可以检测来电并在一定数量的蜂鸣声 响铃 后启动我的自定义活动 我的意思是在 2 或 3 或 5 声蜂鸣声 响铃 后我的activity被触发 我该怎么做 Thanks 我认为您无法计算自来电开始以来电话响了多少次 无法
  • 显示警报或收到通知时的视图

    我正在关注this http tokudu com 2010 how to implement push notifications for android 显示的教程通知 on an 安卓设备 当我在设备上运行该应用程序时 状态栏上会出现
  • 访问角落里的存储

    我能找到的与文件存储有关的最接近文档的是这个帖子 http nookdeveloper zendesk com entries 20257971 updated what are the size constraints on my app
  • 如何在 Android 上创建 YouTube 的双击手势?

    我在 Android 上有 exoplayer 的应用程序 我已经创建了 youtube双击手势用动画向前或向后跳跃 10 秒 如何在双击时创建具有波纹效果的半圆 像这样 这个怎么做 我也想实现这样的功能 所以我自己编写了它来 复制 You
  • 使用 Android 播放任意音调

    有没有办法让Android发出任意频率的声音 意思是 我不想预先录制声音文件 我环顾四周 音调发生器 http developer android com reference android media ToneGenerator html
  • Android Studio - 如何关闭“单词‘word’中的拼写错误?”

    当命名变量或给出字符串参数时 Android Studio 似乎对我如何标记事物有问题 有办法把它关掉吗 是的 打开Preferences gt Editor gt Inspections gt Spelling gt 关闭Typo并按OK
  • android 确定设备是否采用从右到左的语言/布局

    有没有办法确定设备是否使用从右到左的语言 例如阿拉伯语 而不是从左到右的语言 英语 与较旧的 API 级别 低至 10 兼容的东西是必要的 SOLUTION 我最终在接受的答案中使用了 xml 方法 接下来 我还添加了此处指示的代码 以应对
  • 获取可以共享数据的应用程序列表

    此代码显示默认共享对话框 Intent sharingIntent new Intent Intent ACTION SEND sharingIntent setType text html sharingIntent putExtra a
  • 从手机访问本地主机[关闭]

    这个问题不太可能对任何未来的访客有帮助 它只与一个较小的地理区域 一个特定的时间点或一个非常狭窄的情况相关 通常不适用于全世界的互联网受众 为了帮助使这个问题更广泛地适用 访问帮助中心 help reopen questions 我正在使用
  • 如何在Android Compose中使用otf类型字体文件?

    我正在学习使用 Android Jetpack Compose 现在我有一个正则 otf字体文件在资产 字体 我想在文本中使用它 java lang RuntimeException Font asset not found commonu
  • 删除Android所有语言中的字符串

    我有一个包含多个翻译的应用程序 我想删除一些字符串 我怎样才能重构并删除它们一次 例如在默认情况下strings xml文件并自动将删除传播到其他翻译的其他 strings xml 文件 您可以通过 Android Studio 中的 翻译
  • Android:打开和关闭SQLite数据库

    我正在开发Android应用程序 我经常在其中访问本地数据库 该数据库可以从不同的主题访问 因此我遇到了数据库的协调问题 我使用以下open and close method public void open mDb mDbHelper g
  • 内部存储的安全性如何?

    我需要的 对于 Android 我需要永久保存数据 但也能够编辑 并且显然是读取 它 用户不应访问此数据 它可以包含诸如高分之类的内容 用户不得对其进行编辑 我的问题 我会 并且已经 使用过Internal Storage 但我不确定它实际
  • 检测 ListView(或 ScrollView)内的滚动位置

    我正在构建一个聊天室应用程序 其中每 X 秒就会轮询一次新事件 每次发生这种情况时 此代码都会使用新数据更新 RoomAdapter ArrayAdapter 的自定义子类 并将其滚动到底部 RoomAdapter adapter Room
  • 在 Android 布局 xml 文件中使用字符串格式参数 [重复]

    这个问题在这里已经有答案了 我在 String xml 文件中定义了一个使用格式参数的字符串 即
  • 如何在Android中解析xml类型的HTTPResponse

    我有一个 Android 应用程序 我使用 POST 方法来获取响应 这是我的代码 HttpResponse httpResponse httpclient execute httppost HttpEntity resEntity htt
  • 异步更新后更新Android Listview

    我正在将 HTTP 调用从同步调用转换为异步调用 由于连接在后台运行 因此当我最初设置列表适配器时 数据不存在 如何在 HTTP 调用后更新列表适配器 我尝试了一些方法 例如在数据发送回之前不设置适配器并再次设置适配器 但没有任何效果 这是

随机推荐