本文介绍了获得媒体标题从文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用进口的java.io.File; 从我的SD卡导入所有的音乐文件,
现在,我想用Mediastore文件的标题的,但我该怎么做呢?
这是code我现在用的。

I used import java.io.File; to import all music files from my sdcard,Now i want the Title's of the files using Mediastore but how do I do that?This is the code I Use now.

public class ListFiles extends ListActivity {
 private List<String> directoryEntries = new ArrayList<String>();


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent i = getIntent();
    File directory = new File(i.getStringExtra("directory"));

    if (directory.isDirectory()){
        File[] files = directory.listFiles();

        Arrays.sort(files, new Comparator<File>(){
            public int compare(File f1, File f2) {
                return -Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
            }
        });

        this.directoryEntries.clear();
        for (File file : files) {
            this.directoryEntries.add(file.getName());  
        }

        ArrayAdapter<String> directoryList = new ArrayAdapter<String>(this,R.layout.file_row, this.directoryEntries);
    this.setListAdapter(directoryList);
    }

}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
File clickedFile = new File(this.directoryEntries.get(position));
Intent i = getIntent();
i.putExtra("clickedFile", clickedFile.toString());
setResult(RESULT_OK, i);
finish();
}

}

感谢。

推荐答案

我已经做了视频文件的使用:类概述 - 媒体提供者包含在内部和外部存储设备的元数据作为所有可用的媒体。

I have done that for Video files using MediaStore : Class Overview - The Media provider contains meta data for all available media on both internal and external storage devices.

您可以参考这两个例子来了解使用MediaStore的
列表中选择音频

You can refer these two example to understand the use of MediaStoreList Video and List Audio

这篇关于获得媒体标题从文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 14:50