我遇到的问题是尝试让我的程序播放使用默认的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>
答案 0 :(得分:0)
在视频视图中播放声音文件并不是一个好主意。 VideoView将播放您可以轻松播放.mp4 .3gp的视频文件
尝试使用MediaPlayer