内部存储播放文件时

内部存储播放文件时

本文介绍了内部存储播放文件时,MediaPlayer的错误-2147483648的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是音频捕获样本的android.com 录制和回放音频在实际设备上。 (摩托罗拉触摸板,和三星Galaxy S)。

I'm using the Audio Capture sample on android.com to record and play back audio on actual devices. (Motorola touch pad, and Samsung Galaxy S).

当我定义的音频文件路径为

When I define the audio file path as

mFile = Environment.getExternalStorageDirectory().getAbsolutePath();

录制和回放的作品。

record and playback works.

但是,如果我设置音频文件作为

But if I set the audio file as

mFile = getFilesDir().getAbsolutePath();

OR

mFile = getDir("media", Context.MODE_PRIVATE).getAbsolutePath();

mFile = getDir("media", Context.MODE_WORLD_READABLE).getAbsolutePath();

记录似乎工作,但回放失败,

record seems to work, but playback fails with

ERROR / MediaPlayer的(4559):错误(1,-2147483648)

什么函数将返回正确的内部存储的目录保存播放的的音频文件只能在我的应用程序的?

What function will return the correct internal storage directory to save audio files for playback only within my app?

在code的问题是在我的的onCreate 功能。 (在这个例子中,他们有它的构造,但我把它移到的onCreate否则getFilesDir()和GETDIR()没有上下文来上班。)

The code in question is in my onCreate function. (In the example, they have it in the Constructor, but I moved it to onCreate because otherwise getFilesDir() and getDir() have no context to work.)

public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

//  mFile = Environment.getExternalStorageDirectory().getAbsolutePath();     // OK
//  mFile = getFilesDir().getAbsolutePath();                                 // BAD
//  mFile = getDir("media", Context.MODE_PRIVATE).getAbsolutePath();         // BAD
    mFile = getDir("media", Context.MODE_WORLD_READABLE).getAbsolutePath();  // BAD
    mFile += "/audiorecordtest.3gp";
    Log.e(LOG_TAG,mFile);
//  ...
}

当我记录到外部存储(和回放正常工作),日志是这样的:

When I record to external storage (and playback works properly), the log looks like this:

06-17 10:07:30.890: DEBUG/AudioHardwareTegra(85): getInputBufferSize: returns 320 for rate 8000
06-17 10:07:30.900: INFO/MPEG4Writer(85): limits: 2147483647/0 bytes/us, bit rate: 12200 bps and the estimated moov size 3072 bytes
06-17 10:07:30.960: DEBUG/AudioHardwareTegra(85): setDriver_l: Analog mic? yes. Bluetooth? no.
06-17 10:07:31.100: WARN/AudioFlinger(85): RecordThread: buffer overflow
06-17 10:07:31.100: INFO/MPEG4Writer(85): setStartTimestampUs: 86380
06-17 10:07:31.100: INFO/MPEG4Writer(85): Earliest track starting time: 86380
06-17 10:07:34.350: DEBUG/MPEG4Writer(85): Stopping Audio track
06-17 10:07:34.450: INFO/MPEG4Writer(85): Received total/0-length (167/0) buffers and encoded 167 frames. - audio
06-17 10:07:34.450: INFO/MPEG4Writer(85): Audio track drift time: -20309 us
06-17 10:07:34.450: DEBUG/MPEG4Writer(85): Stopping Audio track source
06-17 10:07:34.470: DEBUG/MPEG4Writer(85): Audio track stopped
06-17 10:07:34.470: DEBUG/MPEG4Writer(85): Stopping writer thread
06-17 10:07:34.470: DEBUG/MPEG4Writer(85): 0 chunks are written in the last batch
06-17 10:07:34.470: DEBUG/MPEG4Writer(85): Writer thread stopped
06-17 10:07:34.470: DEBUG/MPEG4Writer(85): Stopping Audio track
06-17 10:07:34.470: WARN/MediaRecorder(4472): mediarecorder went away with unhandled events
06-17 10:07:40.310: INFO/StagefrightPlayer(85): setDataSource('/mnt/sdcard/audiorecordtest.3gp')
06-17 10:07:46.590: DEBUG/AudioHardwareTegra(85): AudioStreamOutTegra::flush()
06-17 10:07:46.670: DEBUG/AudioHardwareTegra(85): AudioStreamOutTegra::flush() returns

当我记录到内部存储器中(和失败),日志是这样的:

When I record to internal storage (and it fails), the log looks like this:

06-17 10:08:28.380: DEBUG/AudioHardwareTegra(85): getInputBufferSize: returns 320 for rate 8000
06-17 10:08:28.380: INFO/MPEG4Writer(85): limits: 2147483647/0 bytes/us, bit rate: 12200 bps and the estimated moov size 3072 bytes
06-17 10:08:28.440: DEBUG/AudioHardwareTegra(85): setDriver_l: Analog mic? yes. Bluetooth? no.
06-17 10:08:28.970: WARN/AudioFlinger(85): RecordThread: buffer overflow
06-17 10:08:28.970: INFO/MPEG4Writer(85): setStartTimestampUs: 83095
06-17 10:08:28.970: INFO/MPEG4Writer(85): Earliest track starting time: 83095
06-17 10:08:34.020: DEBUG/MPEG4Writer(85): Stopping Audio track
06-17 10:08:34.080: WARN/AudioFlinger(85): RecordThread: buffer overflow
06-17 10:08:34.090: INFO/MPEG4Writer(85): Received total/0-length (257/0) buffers and encoded 257 frames. - audio
06-17 10:08:34.090: INFO/MPEG4Writer(85): Audio track drift time: -385311 us
06-17 10:08:34.090: DEBUG/MPEG4Writer(85): Stopping Audio track source
06-17 10:08:34.090: DEBUG/MPEG4Writer(85): Audio track stopped
06-17 10:08:34.090: DEBUG/MPEG4Writer(85): Stopping writer thread
06-17 10:08:34.090: DEBUG/MPEG4Writer(85): 0 chunks are written in the last batch
06-17 10:08:34.090: DEBUG/MPEG4Writer(85): Writer thread stopped
06-17 10:08:34.090: DEBUG/MPEG4Writer(85): Stopping Audio track
06-17 10:08:34.100: WARN/MediaRecorder(4559): mediarecorder went away with unhandled events
06-17 10:08:40.740: INFO/StagefrightPlayer(85): setDataSource('/data/data/my.record.test/files/audiorecordtest.3gp')
06-17 10:08:40.740: ERROR/MediaPlayer(4559): error (1, -2147483648)
06-17 10:08:40.740: ERROR/AudioRecordTest(4559): prepare() failed

日志的记录部分看起来基本上是一样的我,所以我认为它的录音,但我不知道如何检查该文件以任何方式,除了发挥它。 ; - )

The recording sections of the log look largely the same to me, so I think it's recording, but I don't know how to check the file in any way besides play it. ;-)

错误日志类似,当我使用GETDIR()。

The error log is similar when I use getDir().

推荐答案

Thanks到gtkandroid :

而不是的mPlayer.setDataSource(MFILE); 我这样做:

FileInputStream fileInputStream = new FileInputStream(mFile);
mPlayer.setDataSource(fileInputStream.getFD());
fileInputStream.close();
mPlayer.prepare();

这篇关于内部存储播放文件时,MediaPlayer的错误-2147483648的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 23:25