Andyjava 0 Newbie Poster

I have been busy with school and all that and currently working on an android multimedia app i'd like to use. i created a list and was able to filter the files on the sdcard (both .mp3s and .mp4s) but i have a problem. i want the app to launch activities i created (HomeaudioActivity, which deals with .mp3 files and HomevideoActivity, which deals with video files) when selected from the list (i created a class and called it "AllMediaActivity". in this activity, the whole media files have been pulled from the sdcard) based on its extension.

please i'm confused at this, i wrote some codes and i'm stuck at somewhere. below is the code with the issue, please where did i go wrong?

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;
                    }
                }

            }
        });

    }
}

Please guys i need serious help on this

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.