gpt4 book ai didi

android - 如何从 ListView 播放录制的音频文件

转载 作者:行者123 更新时间:2023-11-30 03:03:16 27 4
gpt4 key购买 nike

我正在开发一个通话录音应用程序。它记录通话并将其保存在手机内存(文件管理器)中,保存音频文件后,我设法在 ListView 中显示录制的文件。知道当我单击列表上的文件播放它时会出现准备失败错误。我正在发布代码。

    protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.mylist);
mp = new MediaPlayer();
// this will show the recorded files into ListVIew
myList = new ArrayList<String>();
files = new File(Environment.getExternalStorageDirectory()
+ "/Audio File/");
File list[] = files.listFiles();
for (int i = 0; i < list.length; i++) {
myList.add(list[i].getName());
}

adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, myList);
listView.setAdapter(adapter);

listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {

try {
playSong(files + myList.get(position));
} catch (Exception e) {
Log.d("PlaySong", "Error in Playing song "+e.toString());
}

// just for checking the position of item in list
Object listItem = listView.getItemAtPosition(position);
Toast.makeText(MainActivity.this, "" + listItem,
Toast.LENGTH_SHORT).show();
}

private void playSong(String string) throws IllegalArgumentException, SecurityException, IllegalStateException, IOException {

mp.reset();
mp.setDataSource(string);
mp.prepare();
mp.start();
}

});
}

错误是

  03-07 14:40:25.866: I/SurfaceTextureClient(15355): [STC::queueBuffer] this:0x4f11d050,             api:1, last queue time elapsed :11282 ms
03-07 14:40:25.866: I/SurfaceTextureClient(15355): [0x4f11d050] frames:2, duration:11.356000, fps:0.176113
03-07 14:40:25.916: V/Provider/Setting(15355): from settings cache , name = sound_effects_enabled value = 0
03-07 14:40:25.918: D/MediaPlayer(15355): mPlayerID = 48
03-07 14:40:25.927: E/MediaPlayer(15355): error (1, -2147483648)
03-07 14:40:25.927: D/PlaySong(15355): Error in Playing song java.io.IOException: Prepare failed.: status=0x1

最佳答案

我只建议您在上一个问题中编写此代码,因此下面可能是导致问题的主要问题。

尝试声明你的

files = new File(Environment.getExternalStorageDirectory()+ "/Audio File/");

作为一个

private static final String files = new String(
Environment.getExternalStorageDirectory() + "/Audio File/");

您已将路径声明为文件,因此请将其更改为字符串然后尝试。

关于android - 如何从 ListView 播放录制的音频文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22246592/

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