Android Local Video Player Development-search for local videos (1)

Source: Internet
Author: User

The main content of this chapter is to search for the local video on the mobile phone and add it to the ListView list. Each table item contains the thumbnail of the video, the video playback time, and the video title, in searching for a local video (1), we first create a search function.

Video. java -- Video-related attribute classes

[Java]
Package com. zhangjie. graduation. videopalyer. videofile;
 
Import java. io. Serializable;
 
Import com. zhangjie. graduation. videopalyer. component. LoadedImage;
 
Public class Video implements Serializable {
/**
*
*/
Private static final long serialVersionUID =-7920222595800367956L;
Private int id;
Private String title;
Private String album;
Private String artist;
Private String displayName;
Private String mimeType;
Private String path;
Private long size;
Private long duration;
Private LoadedImage image;
 
/**
*
*/
Public Video (){
Super ();
}
 
/**
* @ Param id
* @ Param title
* @ Param album
* @ Param artist
* @ Param displayName
* @ Param mimeType
* @ Param data
* @ Param size
* @ Param duration
*/
Public Video (int id, String title, String album, String artist,
String displayName, String mimeType, String path, long size,
Long duration ){
Super ();
This. id = id;
This. title = title;
This. album = album;
This. artist = artist;
This. displayName = displayName;
This. mimeType = mimeType;
This. path = path;
This. size = size;
This. duration = duration;
}
 
Public int getId (){
Return id;
}
 
Public void setId (int id ){
This. id = id;
}
 
Public String getTitle (){
Return title;
}
 
Public void setTitle (String title ){
This. title = title;
}
 
Public String getAlbum (){
Return album;
}
 
Public void setAlbum (String album ){
This. album = album;
}
 
Public String getArtist (){
Return artist;
}
 
Public void setArtist (String artist ){
This. artist = artist;
}
 
Public String getDisplayName (){
Return displayName;
}
 
Public void setDisplayName (String displayName ){
This. displayName = displayName;
}
 
Public String getMimeType (){
Return mimeType;
}
 
Public void setMimeType (String mimeType ){
This. mimeType = mimeType;
}
 
Public String getPath (){
Return path;
}
 
Public void setPath (String path ){
This. path = path;
}
 
Public long getSize (){
Return size;
}
 
Public void setSize (long size ){
This. size = size;
}
 
Public long getDuration (){
Return duration;
}
 
Public void setDuration (long duration ){
This. duration = duration;
}

Public LoadedImage getImage (){
Return image;
<PRE class = java name = "code">
}

Public void setImage (LoadedImage image ){
This. image = image;
}
 
} </PRE>
<PRE> </PRE>
<P> AbstructProvider. java --- an interface to obtain a set of searched Videos </P>
<PRE class = java name = "code"> package com. zhangjie. graduation. videopalyer. videofile;
 
Import java. util. List;
 
Public interface AbstructProvider {

Public List <Video> getList ();

} </PRE>
<P> <BR>
VideoProvider. java --- implements the AbstructProvider interface and uses cursor to search video information. </P>
<PRE class = java name = "code"> package com. zhangjie. graduation. videopalyer. videofile;
 
Import java. util. ArrayList;
Import java. util. List;
 
Import android. content. Context;
Import android. database. Cursor;
Import android. provider. MediaStore;
 
Public class VideoProvider implements AbstructProvider {
Private Context context;

Public VideoProvider (Context context ){
This. context = context;
}

@ Override
Public List <Video> getList (){
List <Video> list = null;
If (context! = Null ){
Cursor cursor = context. getContentResolver (). query (
MediaStore. Video. Media. EXTERNAL_CONTENT_URI, null, null,
Null, null );
If (cursor! = Null ){
List = new ArrayList <Video> ();
While (cursor. moveToNext ()){
Int id = cursor. getInt (cursor
. GetColumnIndexOrThrow (MediaStore. Video. Media. _ ID ));
String title = cursor
. GetString (cursor
. GetColumnIndexOrThrow (MediaStore. Video. Media. TITLE ));
String album = cursor
. GetString (cursor
. GetColumnIndexOrThrow (MediaStore. Video. Media. ALBUM ));
String artist = cursor
. GetString (cursor
. GetColumnIndexOrThrow (MediaStore. Video. Media. ARTIST ));
String displayName = cursor
. GetString (cursor
. GetColumnIndexOrThrow (MediaStore. Video. Media. DISPLAY_NAME ));
String mimeType = cursor
. GetString (cursor
. GetColumnIndexOrThrow (MediaStore. Video. Media. MIME_TYPE ));
String path = cursor
. GetString (cursor
. GetColumnIndexOrThrow (MediaStore. Video. Media. DATA ));
Long duration = cursor
. GetInt (cursor
. GetColumnIndexOrThrow (MediaStore. Video. Media. DURATION ));
Long size = cursor
. GetLong (cursor
. GetColumnIndexOrThrow (MediaStore. Video. Media. SIZE ));
Video video = new Video (id, title, album, artist, displayName, mimeType, path, size, duration );
List. add (video );
}
Cursor. close ();
}
}
Return list;
}
 
} </PRE>
<P> <BR>
Finally, use the following code in the main class to obtain the final video-related information set </P>
<PRE class = java name = "code"> AbstructProvider provider = new VideoProvider (this );
List <Video> listVideos = provider. getList (); </PRE>
<P> the above listVideos contains information about all the local videos. The next chapter uses the listVideos data. <BR>
</P>
<PRE> </PRE>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.