欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android 使用Vitamio打造自己的萬能播放器(4)——本地播放(快捷搜索、數(shù)據(jù)存儲)

 更新時(shí)間:2016年07月25日 11:54:23   投稿:lqh  
本文主要介紹android Vitamio 本地播放功能(快捷搜索,數(shù)據(jù)存儲),這里提供實(shí)例代碼和效果圖,有需要的小伙伴可以參考下

前言

  關(guān)鍵字:Vitamio、VPlayer、Android播放器、Android影音、Android開源播放器

  本章節(jié)把Android萬能播放器本地播放的主要功能(緩存播放列表和A-Z快速查詢功能)完成,和播放組件關(guān)系不大,但用到一些實(shí)用的技術(shù),歡迎交流!

系列

  1、Android 使用Vitamio打造自己的萬能播放器(1)——準(zhǔn)備

  2、Android 使用Vitamio打造自己的萬能播放器(2)—— 手勢控制亮度、音量、縮放

  3、Android 使用Vitamio打造自己的萬能播放器(3)——本地播放(主界面、播放列表)

正文

  一、目標(biāo)

    1.1  A-Z快速切換查找影片

  把手機(jī)上的聯(lián)系人上的A-Z快速查找運(yùn)用到了這里,查找文件更便捷。這也是"學(xué)"的米聊的 :)

    1.2  緩存掃描視頻列表

  首次使用掃描SD卡一遍,以后就從數(shù)據(jù)庫讀取了,下篇文章再加一個(gè)監(jiān)聽即可。

    1.3      截圖

          二、實(shí)現(xiàn)

 核心代碼:

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 = super.onCreateView(inflater, container, savedInstanceState);
 // ~~~~~~~~~ 綁定控件
 first_letter_overlay = (TextView) v.findViewById(R.id.first_letter_overlay);
 alphabet_scroller = (ImageView) v.findViewById(R.id.alphabet_scroller);

 // ~~~~~~~~~ 綁定事件
 alphabet_scroller.setClickable(true);
 alphabet_scroller.setOnTouchListener(asOnTouch);
 mListView.setOnItemClickListener(this);

 // ~~~~~~~~~ 加載數(shù)據(jù)
 if (new SQLiteHelper(getActivity()).isEmpty())
 new ScanVideoTask().execute();
 else
 new DataTask().execute();

 return v;
 }

 /** 單擊啟動播放 */
 @Override
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
 final 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 onPreExecute() {
 super.onPreExecute();
 mLoadingLayout.setVisibility(View.VISIBLE);
 mListView.setVisibility(View.GONE);
 }

 @Override
 protected ArrayList<PFile> doInBackground(Void... params) {
 return FileBusiness.getAllSortFiles(getActivity());
 }

 @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);
 }
 }

 /** 掃描SD卡 */
 private class ScanVideoTask extends AsyncTask<Void, File, ArrayList<PFile>> {
 private ProgressDialog pd;
 private ArrayList<File> files = new ArrayList<File>();

 @Override
 protected void onPreExecute() {
 super.onPreExecute();
 pd = new ProgressDialog(getActivity());
 pd.setMessage("正在掃描視頻文件...");
 pd.show();
 }

 @Override
 protected ArrayList<PFile> doInBackground(Void... params) {
 // ~~~ 遍歷文件夾
 eachAllMedias(Environment.getExternalStorageDirectory());

 // ~~~ 入庫
 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_PINYIN + "," + 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();
 }

 // ~~~ 查詢數(shù)據(jù)
 return FileBusiness.getAllSortFiles(getActivity());
 }

 @Override
 protected void onProgressUpdate(final File... values) {
 File f = values[0];
 files.add(f);
 pd.setMessage(f.getName());
 }

 /** 遍歷所有文件夾,查找出視頻文件 */
 public void eachAllMedias(File f) {
 if (f != null && f.exists() && f.isDirectory()) {
 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> 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(View 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;
 }
 };

 /**
 * 顯示字符
 * 
 * @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 > 25)
 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 == 25)
 mListView.setSelection(mAdapter.getCount() - 1);
 else {
 for (PFile item : mAdapter.getAll()) {
 if (item.title_pinyin.startsWith(key)) {
 mListView.setSelection(position);
 break;
 }
 position++;
 }
 }
 }

 代碼說明:

         代碼是基于上篇文章,新增了播放列表緩存功能以及快速查找功能。

  a).  使用了pinyin4j開源項(xiàng)目,用于提取文件名中的漢字的拼音,以便能夠。

  b).  A-Z這部分的代碼也是通過反編譯參考米聊的,比較有實(shí)用價(jià)值

  c).  入庫部分使用了事務(wù)

  其他代碼請參見項(xiàng)目代碼。

 注意:

由于是示例代碼,考慮不盡周全,可能在后續(xù)章節(jié)中補(bǔ)充,請大家注意不要直接使用代碼!例如應(yīng)該檢查一下SD卡是否可用等問題。

      三、Vtamio與VPlayer

 Vitamio:http://vov.io 
 VPlayerhttp://vplayer.net (使用Vitamio最成功的產(chǎn)品,用戶超過500萬)

以上就是對Android Vitamio 本地播放功能(快捷搜索,數(shù)據(jù)存儲)資料整理,有開發(fā)Android播放器的朋友可以參考下。

相關(guān)文章

  • Android ListView詳解

    Android ListView詳解

    listview控件在項(xiàng)目開發(fā)過程中經(jīng)常會用到,本文給大家分享android listview相關(guān)知識,感興趣的朋友一起學(xué)習(xí)吧
    2015-12-12
  • Flutter進(jìn)階之實(shí)現(xiàn)動畫效果(四)

    Flutter進(jìn)階之實(shí)現(xiàn)動畫效果(四)

    這篇文章主要為大家詳細(xì)介紹了Flutter進(jìn)階之實(shí)現(xiàn)動畫效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-08-08
  • Android中判斷是否有前置攝像頭、后置攝像頭的方法

    Android中判斷是否有前置攝像頭、后置攝像頭的方法

    這篇文章主要介紹了Android中判斷是否有前置攝像頭、后置攝像頭的方法,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下
    2015-01-01
  • Android RecyclerView添加頭部和底部的方法

    Android RecyclerView添加頭部和底部的方法

    這篇文章主要為大家詳細(xì)介紹了Android RecyclerView添加頭部和底部的方法,感興趣的小伙伴們可以參考一下
    2016-05-05
  • android之SeekBar控件用法詳解

    android之SeekBar控件用法詳解

    下面小編就為大家?guī)硪黄猘ndroid之SeekBar控件用法詳解。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2016-09-09
  • Android簡易圖片瀏覽器的實(shí)現(xiàn)

    Android簡易圖片瀏覽器的實(shí)現(xiàn)

    最近做了一個(gè)圖片瀏覽小程序,本文主要介紹了Android簡易圖片瀏覽器的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-03-03
  • Android進(jìn)階Handler應(yīng)用線上卡頓監(jiān)控詳解

    Android進(jìn)階Handler應(yīng)用線上卡頓監(jiān)控詳解

    這篇文章主要為大家介紹了Android進(jìn)階Handler應(yīng)用線上卡頓監(jiān)控詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-01-01
  • Android實(shí)現(xiàn)京東上滑效果

    Android實(shí)現(xiàn)京東上滑效果

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)京東上滑效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-06-06
  • Android UI設(shè)計(jì)系列之自定義Dialog實(shí)現(xiàn)各種風(fēng)格的對話框效果(7)

    Android UI設(shè)計(jì)系列之自定義Dialog實(shí)現(xiàn)各種風(fēng)格的對話框效果(7)

    這篇文章主要介紹了Android UI設(shè)計(jì)系列之自定義Dialog實(shí)現(xiàn)各種風(fēng)格的對話框效果,具有一定的實(shí)用性和參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-06-06
  • Android之Gallery使用例子

    Android之Gallery使用例子

    本篇文章主要介紹了Android之Gallery使用例子,Gallery用來顯示圖片列表,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。
    2017-01-01

最新評論