【发布时间】:2013-06-12 13:12:47
【问题描述】:
我正在开发我的第一个 Android 应用。它是录音应用程序。我正在像这样使用 MediaRecord 录制声音:
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(mFileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
mRecorder.prepare();
} catch (IOException e) {
Log.e(LOG_TAG, "prepare() failed");
}
mRecorder.start();
我还有另一个活动可以播放这些录制的声音(.3gpp 文件)。在这个活动中,有一个包含我录制的声音的 ListView。我想用手机上安装的任何音乐播放器播放声音。这是我的代码:
(此代码来源:https://stackoverflow.com/a/3367231/556169)
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File((String) ((TextView) item).getText());
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent);
但我收到“音乐播放器无法播放此媒体类型”错误。
当我浏览这些音频文件并通过我的文件资源管理器播放它们时,它运行良好(意思是,我正在成功录制声音)。但是当我在我的应用程序中使用 Intent 时,我得到了错误。
附加
我不能使用MediaStore.INTENT_ACTION_MUSIC_PLAYER,因为它已被弃用。
我不能使用 Intent.CATEGORY_APP_MUSIC因为它需要 min API lvl 15 。我的项目的最低 API 级别应该是 8。
【问题讨论】:
标签: android android-intent audio-player android-music-player