gpt4 book ai didi

android - 在内部存储上播放文件时 MediaPlayer 错误 -2147483648

转载 作者:IT老高 更新时间:2023-10-28 22:22:07 24 4
gpt4 key购买 nike

我正在使用 Audio Capture sample on android.com在实际设备上录制和播放音频。 (摩托罗拉触摸板和三星 Galaxy S)。

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

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

录制和播放作品。

但如果我将音频文件设置为

mFile = getFilesDir().getAbsolutePath();

OR

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

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

录制似乎有效,但播放失败

ERROR/MediaPlayer(4559): error (1, -2147483648)

什么函数会返回正确的内部存储目录来保存音频文件以便只在我的应用程序中播放

有问题的代码在我的 onCreate 函数中。 (在示例中,它们在构造函数中,但我将其移至 onCreate,因为否则 getFilesDir() 和 getDir() 没有上下文可以工作。)

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);
// ...
}

当我录制到外部存储(并且播放正常)时,日志如下所示:

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

当我记录到内部存储(并且失败)时,日志如下所示:

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

日志的记录部分在我看来大致相同,所以我认为是记录,但除了播放之外我不知道如何检查文件。 ;-)

使用 getDir() 时的错误日志类似。

最佳答案

Thanks to gtkandroid :

而不是 mPlayer.setDataSource(mFile); 我这样做了:

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

关于android - 在内部存储上播放文件时 MediaPlayer 错误 -2147483648,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6380765/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com