我遇到的问题是试图让我的程序播放使用默认 android 录音机录制的 .amr 文件。我还下载了一个 mp3 录音机并尝试播放,但它也不起作用。我已经下载了运行良好的 .amr 和 .mp3 文件,只是那些记录下来的文件似乎不起作用。
代码转储:
private static final String recording = new String(Environment.getExternalStorageDirectory().getPath()) + File.separatorChar + "My Documents" + File.separatorChar + "My Recordings";
ArrayList<String> songList = new ArrayList<String>();
private ListView playList;
private VideoView videoView;
private MediaController mediaController;
private void loadPlayList()
{
songList.clear();
File home = new File(recording);
if (home.listFiles( new AmrFilter()).length > 0) {
for (File file : home.listFiles(new AmrFilter())) {
songList.add(file.getName());
}
}
if (home.listFiles( new Mp3Filter()).length > 0) {
for (File file : home.listFiles(new Mp3Filter())) {
songList.add(file.getName());
}
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, songList);
playList.setAdapter(adapter);
}
class AmrFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
// TODO Auto-generated method stub
return (name.endsWith(".amr"));
}
}
private void refreshPlayList()
{
songList.clear();
File home = new File(SD_PATH);
if (home.listFiles( new Mp3Filter()).length > 0) {
for (File file : home.listFiles(new Mp3Filter())) {
songList.add(file.getName());
}
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, songList);
playList.setAdapter(adapter);
}
private void playFile(String currentFile) throws IllegalArgumentException, SecurityException, IllegalStateException, IOException {
videoView.setVideoPath(currentFile);
videoView.start();
playBtn.setVisibility(View.VISIBLE);
// Set the progress max
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
playBar.setMax(videoView.getDuration());
startSeekbar.setMax(videoView.getDuration());
startSeekbar.setProgress(videoView.getCurrentPosition());
stopSeekbar.setMax(videoView.getDuration());
stopSeekbar.setProgress(videoView.getDuration());
int msec = videoView.getDuration();
int time[] = secondsToMinutes(msec);
totalPlayTime.setText(time[0] + ":" + time[1] + ":" + time[2]);
}
});
handler.postDelayed(runner, 1000);
}
logcat 错误是:
07-01 05:51:45.363: E/MediaPlayer(2912): error (1, -2147483648)
07-01 05:51:45.383: E/MediaPlayer(2912): Error (1,-2147483648)
07-01 05:51:45.383: D/VideoView(2912): Error: 1,-2147483648
我不确定问题是什么,但仅限于我记录的问题。我不认为这是文件权限,因为 Android mp3 播放器可以播放 mp3 录音。
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.jahed.medialooper.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>