Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
安德烈亚斯的答案是执行此操作的正确方法,但该代码无法获取绝对文件路径。
这会导致
mMediaPlayer.prepare();
抛出IOException:准备失败。状态=0x1
。下面是获取文件路径和文件名的代码:
现在我们有了绝对路径,我们不需要再次获取路径。所以:
使用:
而不是:
请确保在列表视图 OnItemClickListener 中
。要仅获取曲目的标题(看起来比带有扩展名的整个文件名更优雅),请使用:
而不是:
Andreas answer is the right way to do this but that code does not get the absolute file path.
This causes the
mMediaPlayer.prepare();
to throwIOException: Prepare failed. status=0x1
.Here is the code to get the file path along with the file name:
Now that we have the absolute path, we don't need to get the path again. So:
Make sure to use:
instead of:
in the listview OnItemClickListener.
To get only the title of the track (Looks more elegant than the whole file name with extension) use:
instead of:
我不完全确定是什么原因导致了您提到的问题,但请尝试此代码。
I'm not entirely sure exactly what causes the problems you mention, but try this code.
那里的代码有超级错误。
getView
没有任何意义。 gc() 在那里做什么?!所有 moveToPosition() 调用是怎么回事?这是重写的代码
The code there is super-buggy.
The
getView
doesn't make any sense. What is that gc() doing there?! What's with the all moveToPosition() calls.Here's the code rewritten
试试这个代码
try this code