MediaPlayer.setDataSource导致IOException异常的有效文件 [英] MediaPlayer.setDataSource causes IOException for valid file

查看:2860
本文介绍了MediaPlayer.setDataSource导致IOException异常的有效文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这code用来工作。然后,我可能改变了一些东西,某个地方(或者,如果我知道Android的权利,更新推出的媒体播放器中的错​​误)。它停止了工作的部分的设备!尤其是我的Nexus S(2.3.6)。

This code used to work. Then, maybe I changed something, somewhere (or if I know Android right, an update introduced a bug in the media player). It stopped working on some devices! Especially my Nexus S (2.3.6).

文件 test.m4a (17 775 201个字节),被下载的应用程序。为了验证它的完整性,我把它复制到SD,发挥它在我的电脑上。没问题!也与原来的文件的二进制相比它,它匹配的100%。

The file test.m4a (17 775 201 bytes) was downloaded by the app. To verify its integrity, I copied it to the SD and played it on my PC. No problem! Also binary-compared it with the original file, and it matched 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();
}

问:什么可能会导致这样 IOException异常 setDataSourceFD 时,该文件确实是有效吗?

Q: What might cause this IOException for setDataSourceFD when the file is indeed valid?

更新:这里有一个98 kb的音频文件,我不能在我的Nexus S玩(2.3.6): <一href="http://www.2shared.com/audio/wUKoRiQk/test.html">http://www.2shared.com/audio/wUKoRiQk/test.html

min的一位朋友运行了一些中兴通讯设备(2.2),它似乎工作。我不明白!

A friend of min runs some ZTE device (2.2) and it seems to work. I don't get it!

推荐答案

我想告诉你,MediaPlayer正在运行和正常工作。下面是我所有的假设。不要把他们看得太重。

I would like to tell you that MediaPlayer is running and working correctly. Below are all my hypothesis. Don't take them too seriously.

这是你的test.m4a文件,它是连接codeD的格式,这样的MediaPlayer无法去code,因此抛出一个错误,指出它不能创建的MediaPlayer供您使用。 好像你连接$ C $光盘,它在一些FFmpeg的codeCS你有你的电脑上。如果你试图在不使用先进的codeCS比如FFmpeg的创建文件,这将是更好,因为Android无法去code先进的$ C $飞CCS。

It is your test.m4a file that is encoded in a format such that MediaPlayer can't decode, therefore throwing out an error saying that it can't create the MediaPlayer for you to use. Seems like you encoded it in some FFmpeg codecs you had on your computer. It would be better if you tried creating the file without using advanced codecs such as FFmpeg, as Android can't decode advanced codecs on the fly.

不过,我并没有回答为什么有些智能手机可以发挥你的M4A文件,而其他人则不能。我的建议对你是使用Audacity的已经安装,您的所有的Andr​​oid项目的一个简单的OGG格式,由于OGG codeC什么Audacity的了,是很简单的为Android脱code的飞行。我并不是说,很多开发者都使用多数OGG,只是OGG似乎并不有很多的问题,用简单的codeCS时的MediaPlayer和的Soundpool。需要更多的研究...

However, I do not have the answer to why some smartphones can play your M4A file, while others can't. My suggestion for you is to use a simple OGG format that Audacity already has installed, for all of your Android projects, because the OGG codec what Audacity has, is simple enough for Android to decode on the fly. I'm not claiming that many devs are using mostly OGG, just that OGG doesn't seem to have a lot of problems with MediaPlayer and SoundPool when using simple codecs. Needs more researching...

即使我的书,开始安卓4.0游戏开发,取决于OGG文件。

Even my book, Beginning Android 4 Game Development, depends on OGG files.

下面是我下面的证明。这是文件test.m4a我从你的链接使用。我做了它,使它运行在一个无限循环,使其成为一个100%证明的证据:

Here's my proof below. This is the file "test.m4a" I'm using from your link. I made it so that it runs in a endless loop, making it a 100% proof of evidence:

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)

现在,这里的code我做了,如下图所示:

Now, here's the code I made, shown below:

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

注意接近code段的顶部,最后一个字符串变量。如果我更换符合这样的:

Notice the final String variable near the top of the code snippet. If I replace that line with this:

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

和重新连接code你的test.m4a文件到的Ogg Vorbis文件,并在code没有其他变化,我可以播放OGG文件就好了。以下是该OGG文件更改日志:

And re-encode your "test.m4a" file to an Ogg Vorbis file, and no other changes in the code, I can play the OGG file just fine. Here are the change logs for the OGG file:

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!

然后就到此为止。有没有循环绕来绕去。

And then it stops here. There's no looping going around.

更多的证据来支持我的回答:

链接1:Android的SDK参考(不要看状态图,很重要!)

和图片(你的test.m4a和您的文件重新连接codeD到OGG文件,图片放在并排侧。):

And a picture (Image of your "test.m4a" and your file re-encoded into an OGG file, placed side-by-side.):

这篇关于MediaPlayer.setDataSource导致IOException异常的有效文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆