0

我一直忙于学校和所有这些,目前正在开发一个我想使用的 android 多媒体应用程序。我创建了一个列表,并且能够过滤 sdcard 上的文件(.mp3s 和 .mp4s),但我遇到了问题。当从列表中选择时(我创建了一个类并将其命名为“AllMediaActivity”。在此活动中,整个媒体文件已从 sdcard 中提取)基于其扩展名。

请我对此感到困惑,我写了一些代码,但我被困在某个地方。下面是有问题的代码,请问我哪里出错了?

package com.src.imagine.playmedia;

import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.HashMap;

    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.ListAdapter;
    import android.widget.ListView;
    import android.widget.SimpleAdapter;
    import android.widget.Toast;

    import com.actionbarsherlock.app.SherlockListActivity;

    public class AllPlayListActivity extends SherlockListActivity {
        // All the lists
        public ArrayList<HashMap<String, String>> aMediaList = new ArrayList<HashMap<String, String>>();
        Intent in;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.playlist);

        ArrayList<HashMap<String, String>> aMediaListData = new ArrayList<HashMap<String, String>>();

        AllMediaManager amm = new AllMediaManager();
        // getting all the songs from sdcard
        this.aMediaList = amm.getPlayList();

        // lopping through the playlist
        for (int i = 0; i < aMediaList.size(); i++) {
        // creating new HashMap
        HashMap<String, String> media = aMediaList.get(i);

        // adding HashList to ArrayList
        aMediaListData.add(media);
        }

        // Adding menuItems to ListView
        ListAdapter adapter = new SimpleAdapter(this, aMediaListData,
        R.layout.playlist_item, new String[] { "mediaTitle" },
        new int[] { R.id.songTitle });

        setListAdapter(adapter);

        // selecting single ListView item
        ListView lv = getListView();
        // listening to single listitem click
        lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
        int position, long id) {
        // getting listitem index
        final int mediaIndex = position;
        @SuppressWarnings("unused")
        class FileExtensionFilter implements FilenameFilter {
        public boolean accept(File dir, String name) {
        if (name.endsWith(".mp3") || name.endsWith(".MP3")) {

        // Starting new intent
        in = new Intent(getApplicationContext(),HomeAudioActivity.class);
            // Sending mediaIndex to the audioPlayerActivity
        in.putExtra("songIndex", mediaIndex);
        setResult(100, in);
        // closing playlistview
        finish();
        } else if (name.endsWith(".mp4")
        || name.endsWith(".MP4")
        || name.endsWith(".h.264 avc")
        || name.endsWith(".H.264 AVC")
        || name.endsWith(".h.263")
        || name.endsWith(".H.263")
        || name.endsWith(".mpeg-4 sp")
        || name.endsWith(".MPEG-4 SP")
        || name.endsWith(".mpeg-4")
        || name.endsWith(".MPEG-4")
        || name.endsWith(".vp8")
        || name.endsWith(".VP8")) {
        // Starting new Intent
        in = new Intent(getApplicationContext(), HomeVideoActivity.class);
        // Sending mediaIndex to the videoPlayerActivity
        in.putExtra("videoIndex", mediaIndex);
        setResult(100, in);
        // closing playlistView
        finish();
        } else {
        Toast.makeText(getApplicationContext(),
        "Unsupported video format",Toast.LENGTH_SHORT).show();
        }
        return false;
        }
        }

        }
        });

        }
            }
4

2 回答 2

0

http://www.androidsnippets.com/open-file-with-default-application-using-intents

谷歌->“android在默认应用程序中打开文件”->这篇文章。

可能有帮助。

于 2013-11-11T13:59:44.130 回答
0

您编写了从未使用过的 FileExtensionFilter 类。我不确定您是否获得所有媒体列表。

您可以参考这里了解更多详情。

于 2013-11-11T14:09:07.103 回答