-2

======================MainPlay================================================= ====This is the first where all the files are displayed and can select file to play======

package com.example.droid;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.app.ListActivity;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;


public class mainplay extends ListActivity {


          private ArrayList<Video> videoList;
          private ListView videoView;


        @Override
        protected void onCreate(Bundle savedInstanceState){
            super.onCreate(savedInstanceState);
            setContentView(R.layout.videoplaylist);

            videoView = (ListView)findViewById(android.R.id.list);  
            videoList = new ArrayList<Video>();
            getVideoList();


            Collections.sort(videoList, new Comparator<Video>(){
                  public int compare(Video a, Video b){
                    return a.getTTL().compareTo(b.getTTL());
                  }
                }); 

            VideoAdapter VAdp = new VideoAdapter(this, videoList);
            videoView.setAdapter(VAdp);

        }




        public void getVideoList(){
            //retrieve video info   
            ContentResolver videoResolver = getContentResolver();
            Uri videoUri = android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
            Cursor videoCursor = videoResolver.query(videoUri, null, null, null, null);

            if(videoCursor!=null && videoCursor.moveToFirst()){
                  //get columns
                  int titleColumn = videoCursor.getColumnIndex
                    (android.provider.MediaStore.Video.Media.TITLE);
                  int idColumn = videoCursor.getColumnIndex
                    (android.provider.MediaStore.Video.Media._ID);

                  //add videos to list
                  do {
                    long thisId = videoCursor.getLong(idColumn);
                    String thisTitle = videoCursor.getString(titleColumn);
                    Log.e("video", thisTitle);
                    videoList.add(new Video(thisId, thisTitle));
                  }
                  while (videoCursor.moveToNext());


                  ListView listView = ( ListView ) findViewById(android.R.id.list);
                  OnItemClickListener itemClick = new OnItemClickListener(){

                      @Override
                      public void onItemClick(AdapterView<?> parent, View v,
                              int position, long id) {

                          Intent Droid=new Intent(mainplay.this,DroidActivity.class);
                          startActivity(Droid);


                      }

                  };
                  listView.setOnItemClickListener(itemClick);
            }

        }

}

==================SECOND SCREEN======================= ======This the screen where the video should play once the item is selected on mainplay=====

package com.example.droid;

import android.support.v7.app.ActionBarActivity;
import android.app.ProgressDialog;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.MediaController;
import android.widget.VideoView;

public class DroidActivity extends ActionBarActivity {

    ProgressDialog pDialog;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_droid);

        pDialog = new ProgressDialog(DroidActivity.this);
        pDialog.setTitle("Loading");
        pDialog.setMessage("Please Wait. . .");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);

        pDialog.show();


        VideoView vidView = (VideoView)findViewById(R.id.myVid);
        Uri vid = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.vdroid);
        vidView.setVideoURI(vid);

        MediaController vidControl = new MediaController(this);
        vidControl.setAnchorView(vidView);
        vidView.setMediaController(vidControl);
        vidView.start();

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.droid, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
SrZues
  • 3
  • 7

1 Answers1

0

Well its only one example of Solution. send bundle with the Video ID (i am Assuming that Column Id is unique) Example :

Bundle bundle = new Bundle();
bundle.putInt("VIDEO_ID",video_id);
Intent Droid=new Intent(mainplay.this,DroidActivity.class);
Droid.putExtra(bundle);                          
startActivity(Droid);

this will send the choice to the other Activity

on the DriodActivity

on the onStart/OnResume use this

int value = getIntent().getExtras().getString("VIDEO ID") 

now load the Video from the list by the columid you sent. by moving over the list and when columnId is equal to the selected video id ..

Itzik Samara
  • 2,278
  • 1
  • 14
  • 18