Browsing the sdcard for videos

Quickly share your Android Code Snippets here...

Browsing the sdcard for videos

Postby Jhon » Wed Mar 03, 2010 7:41 am

public void FindVideosInSdcard(String aDirectoryName)
{
iCurrentPath = iCurrentPath + "/" + aDirectoryName;

File lFile = new File(iCurrentPath);

String[] lTotalFiles = lFile.list();

for(int i = 0; i < lTotalFiles.length; i++)
{
File lTempFile = new File(iCurrentPath + "/" + lTotalFiles[i]);
if(lTempFile.isDirectory())
{
lTempFile = null;
FindVideosInSdcard(lTotalFiles[i]);
}
else
{
String lVideoFile = iCurrentPath + "/" + lTotalFiles[i];
if(lVideoFile.endsWith("3gp") || lVideoFile.endsWith("mp4"))
{
iAllFilePaths.add(lVideoFile);
}
}
lTempFile = null;
}

String lTemp = "/" + aDirectoryName;
int lEnd = iCurrentPath.indexOf(lTemp);
if(lEnd != -1)
iCurrentPath = iCurrentPath.substring(0, lEnd);
lFile = null;
}


With above function we can browse the Videos of 3gp and .mp4 format in sdcard.
Happy Journey
Jhon
Jhon
Freshman
Freshman
 
Posts: 9
Joined: Wed Sep 09, 2009 4:06 pm

Top

Postby joshmmo » Mon Mar 22, 2010 8:55 am

gosh sorry for being such a noob, I just have a few questions. I would love to use this, however I want to use it for mp3s instead of videos.

Now im assuming I can just change line

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. if(lVideoFile.endsWith("3gp") || lVideoFile.endsWith("mp4"))
  3.  
  4.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

to
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. if(lVideoFile.endsWith("mp3"))
  3.  
  4.  
Parsed in 0.047 seconds, using GeSHi 1.0.8.4


right?

So i have a few more noob questions cause I really dont know that much about java but im trying to make my first app. I am using eclipse, and this is my current code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class SyncActivity extends Activity implements OnClickListener {
  3.  
  4.         Button buttonSync, buttonBrowseMusicPhone;
  5.  
  6.        
  7.  
  8.         /** Called when the activity is first created. */
  9.  
  10.     @Override
  11.  
  12.     public void onCreate(Bundle savedInstanceState) {
  13.  
  14.         super.onCreate(savedInstanceState);
  15.  
  16.         setContentView(R.layout.main);
  17.  
  18.        
  19.  
  20.         buttonSync = (Button)findViewById(R.id.buttonSync);
  21.  
  22.         buttonBrowseMusicPhone = (Button)findViewById(R.id.buttonBrowseMusicPhone);
  23.  
  24.        
  25.  
  26.         // Define button listeners
  27.  
  28.         buttonBrowseMusicPhone.setOnClickListener(this);
  29.  
  30.     }
  31.  
  32.  
  33.  
  34.         @Override
  35.  
  36.         public void onClick(View src) {
  37.  
  38.                 switch(src.getId()) {
  39.  
  40.                 case R.id.buttonBrowseMusicPhone:
  41.  
  42.                         public void FindVideosInSdcard(String aDirectoryName)
  43.  
  44.                         {
  45.  
  46.                         iCurrentPath = iCurrentPath + "/" + aDirectoryName;
  47.  
  48.  
  49.  
  50.                         File lFile = new File(iCurrentPath);
  51.  
  52.  
  53.  
  54.                         String[] lTotalFiles = lFile.list();
  55.  
  56.  
  57.  
  58.                         for(int i = 0; i < lTotalFiles.length; i++)
  59.  
  60.                         {
  61.  
  62.                         File lTempFile = new File(iCurrentPath + "/" + lTotalFiles[i]);
  63.  
  64.                         if(lTempFile.isDirectory())
  65.  
  66.                         {
  67.  
  68.                         lTempFile = null;
  69.  
  70.                         FindVideosInSdcard(lTotalFiles[i]);
  71.  
  72.                         }
  73.  
  74.                         else
  75.  
  76.                         {
  77.  
  78.                         String lVideoFile = iCurrentPath + "/" + lTotalFiles[i];
  79.  
  80.                         if(lVideoFile.endsWith("3gp") || lVideoFile.endsWith("mp4"))
  81.  
  82.                         {
  83.  
  84.                         iAllFilePaths.add(lVideoFile);
  85.  
  86.                         }
  87.  
  88.                         }
  89.  
  90.                         lTempFile = null;
  91.  
  92.                         }
  93.  
  94.  
  95.  
  96.                         String lTemp = "/" + aDirectoryName;
  97.  
  98.                         int lEnd = iCurrentPath.indexOf(lTemp);
  99.  
  100.                         if(lEnd != -1)
  101.  
  102.                         iCurrentPath = iCurrentPath.substring(0, lEnd);
  103.  
  104.                         lFile = null;
  105.  
  106.                         }
  107.  
  108.                         break;
  109.  
  110.                 }
  111.  
  112.                 // TODO Auto-generated method stub
  113.  
  114.                
  115.  
  116.         }
  117.  
  118. }
  119.  
  120.  
Parsed in 0.041 seconds, using GeSHi 1.0.8.4


So ive called my buttons so I can use them, however eclipse gives me errors with " FindVideosInSdcard" "iCurrentPath" and "iAllFilePaths"

im assuming I have to call those just like I did with my buttons "buttonBrowseMusicPhone" but I just dont really understand what "FindVideosInSdcard" and all that other stuff.

Hopefully you understand what im trying to get across.

Thanks for the help guys!!
joshmmo
Freshman
Freshman
 
Posts: 6
Joined: Sun Mar 21, 2010 9:59 pm

Top

Return to Code Snippets for Android

Who is online

Users browsing this forum: No registered users and 4 guests