Android uses Vitamio to build its own universal player (4)--Local playback (fast search, data storage) _android

Source: Internet
Author: User
Tags gety sqlite

Objective

Keywords: Vitamio, Vplayer, Android player, Android AV, Android open source player

This chapter of the Android universal player local playback of the main functions (cache playlist and A-Z quick query function) completed, and play components are not related, but the use of some practical technology, welcome to communicate!

Series

1.Android uses Vitamio to build its own universal player (1)--ready

2,Android uses Vitamio to build its own universal player (2)--gesture control brightness, volume, zoom

3.Android uses Vitamio to build its own universal player (3)--local playback (main interface, playlist)

Body

I. Objectives

1.1-A-Z quick toggle Find Movie

Use a A-Z quick lookup on your phone's contacts to find files more convenient. This is also the "learning" of the rice chat:)

1.2 Cache Scan Video List

The first use of the scan SD card, and then read from the database, the next article plus a monitor can be.

1.3 Screenshots

Second, realize

Core code:

public class Fragmentfile extends Fragmentbase implements Onitemclicklistener {private Fileadapter madapter;
 Private TextView First_letter_overlay;

 Private ImageView Alphabet_scroller; @Override public View Oncreateview (layoutinflater inflater, ViewGroup container, Bundle savedinstancestate) {View v = s
 Uper.oncreateview (Inflater, container, savedinstancestate);
 ~~~~~~~~~ Bound Control First_letter_overlay = (TextView) V.findviewbyid (R.id.first_letter_overlay);

 Alphabet_scroller = (ImageView) V.findviewbyid (R.id.alphabet_scroller);
 ~~~~~~~~~ Binding Event Alphabet_scroller.setclickable (TRUE);
 Alphabet_scroller.setontouchlistener (Asontouch);

 Mlistview.setonitemclicklistener (this);
 ~~~~~~~~~ Load Data if (new Sqlitehelper (Getactivity ()). IsEmpty ()) New Scanvideotask (). Execute ();

 else new Datatask (). Execute ();
 return v; /** Click Start Play * * @Override public void Onitemclick (adapterview<?> parent, view view, int position, long id) {fi nal PFile f = Madapter.getitem (PositiON);
 Intent Intent = new Intent (getactivity (), videoviewdemo.class);
 Intent.putextra ("path", F.path);
 StartActivity (Intent); Private class Datatask extends Asynctask<void, void, arraylist<pfile>> {@Override protected void Onpre
 Execute () {super.onpreexecute ();
 Mloadinglayout.setvisibility (view.visible);
 Mlistview.setvisibility (View.gone); } @Override protected arraylist<pfile> doinbackground (Void ... params) {return filebusiness.getallsortfiles (Geta
 Ctivity ());

 @Override protected void OnPostExecute (arraylist<pfile> result) {Super.onpostexecute (result);
 Madapter = new Fileadapter (getactivity (), Filebusiness.getallsortfiles (Getactivity ()));

 Mlistview.setadapter (Madapter);
 Mloadinglayout.setvisibility (View.gone);
 Mlistview.setvisibility (view.visible); }/** Scan SD card */private class Scanvideotask extends Asynctask<void, File, arraylist<pfile>> {private Pr
 Ogressdialog PD; Private arraylist<file> files = newArraylist<file> ();
 @Override protected void OnPreExecute () {super.onpreexecute ();
 PD = new ProgressDialog (getactivity ());
 Pd.setmessage ("Scanning video files ...");
 Pd.show (); } @Override protected arraylist<pfile> doinbackground (Void ... params) {//~ ~ Traverse Folder Eachallmedias (environment.

 getExternalStorageDirectory ());
 ~ ~ ~ ~ Storage Sqlitehelper SQLite = new Sqlitehelper (getactivity ());
 Sqlitedatabase db = Sqlite.getwritabledatabase ();

 try {db.begintransaction (); Sqlitestatement stat = db.compilestatement ("INSERT into Files (" + Filescolumns.col_title + "," + filescolumns.col_title_p
 Inyin + "," + Filescolumns.col_path + "," + Filescolumns.col_last_access_time + ") VALUES (?,?,?,?)");
 for (File f:files) {String name = Fileutils.getfilenamenoex (F.getname ());
 int index = 1;
 Stat.bindstring (index++, name);//title stat.bindstring (index++, Pinyinutils.chinenetospell (name));//title_pinyin Stat.bindstring (index++, F.getpath ());//path Stat.bindlong (index++, System.currenTtimemillis ());//last_access_time Stat.execute ();
 } db.settransactionsuccessful ();
 catch (Badhanyupinyinoutputformatcombination e) {e.printstacktrace ();
 catch (Exception e) {e.printstacktrace ();
 finally {db.endtransaction ();
 Db.close ();
 /~ ~ ~ ~ ~ Query data return Filebusiness.getallsortfiles (Getactivity ());
 } @Override protected void onprogressupdate (final file ... values) {file F = values[0];
 Files.add (f);
 Pd.setmessage (F.getname ()); /** traverse all folders to find out the video file */public void Eachallmedias (file f) {if (f!= null && f.exists () && F.isdirect
 Ory ()) {file[] files = f.listfiles ();
 if (Files!= null) {for (file File:f.listfiles ()) {if (File.isdirectory ()) {Eachallmedias (file);
 else if (file.exists () && file.canread () && fileutils.isvideooraudio (file)) {publishprogress (file);
 @Override protected void OnPostExecute (arraylist<pfile> result) {Super.onpostexecute (result); Madapter = new Fileadapter(Getactivity (), result);
 Mlistview.setadapter (Madapter);
 Pd.dismiss (); } private class Fileadapter extends Arrayadapter<pfile> {public Fileadapter (context CTX, arraylist<pfile& Gt
 L) {super (CTX, L); 
 @Override public View getview (int position, View Convertview, ViewGroup parent) {final PFile F = getitem (position);
 if (Convertview = null) {final Layoutinflater minflater = getactivity (). Getlayoutinflater ();
 Convertview = minflater.inflate (R.layout.fragment_file_item, NULL);
 ((TextView) Convertview.findviewbyid (R.id.title)). SetText (F.title);
 return convertview; }/** * A-z/private Ontouchlistener Asontouch = new Ontouchlistener () {@Override public boolean Ontouch (Vi EW V, motionevent event) {switch (event.getaction ()) {case motionevent.action_down://0 alphabet_scroller.setpressed (
 true);
 First_letter_overlay.setvisibility (view.visible);
 Mathscrollerposition (Event.gety ());
 Break Case motionevent.action_up://1 Alphabet_scrolLer.setpressed (FALSE);
 First_letter_overlay.setvisibility (View.gone);
 Break
 Case MotionEvent.ACTION_MOVE:mathScrollerPosition (Event.gety ());
 Break
 return false;

 }
 }; 
 /** * Display character * * @param y */private void mathscrollerposition (float y) {int height = alphabet_scroller.getheight ();
 float charheight = height/28.0f;
 char c = ' A ';
 if (Y < 0) y = 0;

 else if (y > Height) y = height;
 int index = (int) (y/charheight)-1;
 if (Index < 0) index = 0;

 else if (Index >) index = 25;
 String key = string.valueof ((char) (c + index));

 First_letter_overlay.settext (key);
 int position = 0;
 if (index = = 0) mlistview.setselection (0);
 else if (index = =) Mlistview.setselection (Madapter.getcount ()-1); else {for (PFile item:mAdapter.getAll ()) {if (Item.title_pinyin.startsWith (key)) {mlistview.setselection (position)
 ;
 Break
 } position++; }
 }
 }

Code Description:

The code is based on the last article, adding the playlist caching feature and the Quick Find feature.

a). Use the pinyin4j Open source project to extract the pinyin of the Chinese characters in the filename so that it can be.

B. A-Z This part of the code is also through the decompile reference meter chat, more practical value

c). Transactions are used in the warehousing section

Other code see project code.

Attention:

Because it is a sample code, consider not comprehensive, may be supplemented in subsequent chapters, please note that do not use the code directly! For example, you should check whether the SD card is available and so on.

iii. Vtamio and Vplayer

Vitamio: Http://vov.io
vplayer: http://vplayer.net (using Vitamio's most successful product, more than 5 million users)

The above is the Android Vitamio local playback function (fast search, data storage) data collation, have developed Android player friends can refer to.

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.