title: Access videos both in internal storage and external SD card - Android
body: <p>I've developed a simple android app, which will pull videos from 
       path="storage/MicroSD/Videos" and present them in a list view, upon selecting the video, selected video will be played. The videos located in Storage/MicroSD/Videos are played. But videos in other path are not fetched. Please give some idea, how to get videos from all paths(Internal storage and external storage). Additionally if I run the same app on different phones, the SD card path differs like <code>Storage/SD Card o/videos</code>.
  Now is my question: How can I get a <code>File</code>-object pointing to the default video-directory of any device programmatically?</p>
  
  <p>Main activity </p>
  
  <pre><code>    public class MainActivity extends Activity {
  
      private ListView mListView;
      private List&lt;String&gt; fileNameList;
      public  String path="storage/MicroSD/Videos";
      private File file;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      file = Environment.getExternalStorageDirectory();
      fileNameList = getFileListfromSDCard();
      final ListView listView = (ListView) findViewById(R.id.list);
      ArrayAdapter&lt;String&gt; adapter1 = new ArrayAdapter&lt;String&gt; (this,android.R.layout.simple_list_item_1, android.R.id.text1, fileNameList);
      listView.setAdapter(adapter1);
      listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                  int position, long id) {
              int itemPosition = position;
              String itemValue = (String)   listView.getItemAtPosition(position);
              Intent intent = new Intent(MainActivity.this, com.video.videolibrary.SelectedVideo.class);
              intent.putExtra("id", id);
              intent.putExtra("itemValue", itemValue);
              intent.putExtra("path", path);
              startActivity(intent);
          }
  
          });
  
      Button button = (Button) findViewById(R.id.btn_Online);
      // Capture button clicks
      button.setOnClickListener(new OnClickListener() {
          public void onClick(View arg0) {
             Intent myIntent = new Intent(MainActivity.this,com.video.videolibrary.SelectedVideo.class);
              startActivity(myIntent);
          }
      });
  
      }
  
      private List&lt;String&gt; getFileListfromSDCard() {
  
      File files = new File(path);
      FileFilter filter = new FileFilter() {
          private final List&lt;String&gt; exts = Arrays.asList("mp4","MP4");
          @Override
          public boolean accept(File pathname) {
              String ext;
              String path = pathname.getPath();
              ext = path.substring(path.lastIndexOf(".") + 1);
              return exts.contains(ext);
          }
      };
  
      final File [] filesFound = files.listFiles(filter);
      List&lt;String&gt; flLst = new ArrayList&lt;String&gt;();
      if (filesFound != null &amp;&amp; filesFound.length &gt; 0) {
          for (File file : filesFound) {
              flLst.add(file.getName());
           }
      }
      return flLst;
      }
  
      }
  </code></pre>
  
  <p>Selected video class</p>
  
  <pre><code>        public class SelectedVideo extends Activity {
          VideoView view;AudioManager audioManager;
          @Override
          protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.selected_video);
          view = (VideoView)findViewById(R.id.videoView1);
         Bundle bundle = getIntent().getExtras();
         String path=bundle.getString("path");
         String itemValue = bundle.getString("itemValue");
        view.setVideoURI(Uri.parse(path+"/"+itemValue ));
        VideoView videoView = (VideoView) findViewById(R.id.videoView1);
        MediaController mediaController = new MediaController(this);
        mediaController.setAnchorView(videoView);
        Uri uri = Uri.parse(path+"/"+itemValue);
        DisplayMetrics dm = new DisplayMetrics();
        this.getWindowManager().getDefaultDisplay().getMetrics(dm);
        int height = dm.heightPixels;
        int width = dm.widthPixels;
       videoView.setMinimumWidth(width);
       videoView.setMinimumHeight(height);
       videoView.setMediaController(mediaController);
       videoView.setVideoURI(uri);
       videoView.requestFocus();
       audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
       int maxVolume =    audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
       int curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
       SeekBar volControl = (SeekBar)findViewById(R.id.volbar);
       volControl.setMax(maxVolume);
       volControl.setProgress(curVolume);
       volControl.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
  
          @Override
          public void onStopTrackingTouch(SeekBar arg0) {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public void onStartTrackingTouch(SeekBar arg0) {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2)    {
              // TODO Auto-generated method stub
              audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, arg1, 0);
          }
          });
  
          Button stopbutton = (Button) findViewById(R.id.btn_stop);
          stopbutton.setOnClickListener(new View.OnClickListener() {
          public void onClick(View v) {
              view.pause();
  
              }
          });
  
          Button playbutton = (Button) findViewById(R.id.btn_play);
          playbutton.setOnClickListener(new View.OnClickListener() {
          public void onClick(View v) {
              Bundle bundle = getIntent().getExtras();
              String itemValue = bundle.getString("itemValue");
              Toast.makeText(getApplicationContext(),
                      itemValue, Toast.LENGTH_LONG)
                      .show();
              view.start();
          }
          });
  
          Button backbutton = (Button) findViewById(R.id.btn_back);
          backbutton.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
              view.stopPlayback();
              startActivity(new Intent(SelectedVideo.this, MainActivity.class));
              }
          });
  
          }
          @Override
          public void onConfigurationChanged(Configuration newConfig) {
          super.onConfigurationChanged(newConfig);
      }
      }
  </code></pre>
  
  <p>Android Manifest file
              
              
              </p>
  
  <pre><code>        &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
          &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
          &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
          &lt;uses-permission android:name="android.permission.read_external_storage" /&gt;
          &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/video_library"
          android:label="@string/app_name"
          android:theme="@style/AppTheme"
          android:configChanges="orientation|keyboardHidden"&gt;
          &lt;activity
          android:name="com.video.videolibrary.MainActivity"
          android:label="@string/app_name"&gt;
  
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity
          android:name=".SelectedVideo"&gt;
          &lt;/activity&gt;
          &lt;/application&gt;
  
          &lt;/manifest&gt;
  </code></pre>