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

Android仿搜狐視頻、微視等列表播放視頻功能

 更新時(shí)間:2020年05月29日 09:41:34   作者:mayi203  
這篇文章主要為大家詳細(xì)介紹了Android仿搜狐視頻、微視等列表播放視頻功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

最近項(xiàng)目中需要是實(shí)現(xiàn)在列表中自動(dòng)播放視頻,中間遇到了些問題,終于解決,特來(lái)跟大家分享一下:

列表使用的RecyclerView 播放視頻使用MediaPlayer+TextureView。

主要思路:

1、監(jiān)聽RecyclerView的滑動(dòng),開始滑動(dòng)時(shí)停止正在播放的item。

2、通過(guò)LinearLayoutManager 獲取當(dāng)前顯示的第一個(gè)item及最后一個(gè)item

3、RecyclerView停止滑動(dòng)后,選擇item進(jìn)行播放。如果當(dāng)前界面只有一個(gè)item,播放當(dāng)前。如果item數(shù)量大于2個(gè),播放第二個(gè)。如當(dāng)前界面有兩個(gè)item則判定哪一個(gè)顯示的區(qū)域比較大。播放item并記錄當(dāng)前position。

附上主要實(shí)現(xiàn)邏輯:

try { 
  int fristPos = layoutManager.findFirstVisibleItemPosition(); 
  int lastPos = layoutManager.findLastVisibleItemPosition(); 
  ViewHolder holder = null; 
  if (recyclerView.getChildCount() == 2) { 
  View fristView = recyclerView.getChildAt(0); 
  if (fristView != null) { 
   int[] location = new int[2]; 
   fristView.getLocationInWindow(location); 
   if (location[1] > 0) { 
   holder = (ViewHolder) recyclerView.findViewHolderForPosition(fristPos); 
   lastPlayPosition = fristPos; 
   } 
  } 
  if (holder == null) { 
   View lastView = recyclerView.getChildAt(1); 
   if (lastView != null) { 
   int[] lastViewLocation = new int[2]; 
   lastView.getLocationInWindow(lastViewLocation); 
   if ((lastViewLocation[1] + videoHeight) < screenHeight) { 
    holder = (ViewHolder) recyclerView.findViewHolderForPosition(lastPos); 
    lastPlayPosition = lastPos; 
   } 
   } 
 
 
  } 
  } else if (recyclerView.getChildCount() == 1) { 
  holder = (ViewHolder) recyclerView.findViewHolderForPosition(fristPos); 
  lastPlayPosition = fristPos; 
  } else { 
  holder = (ViewHolder) recyclerView.findViewHolderForPosition(fristPos + 1); 
  lastPlayPosition = fristPos + 1; 
  } 
 
 
  if (holder != null) { 
  holder.play(); 
  } 
  
 } catch (Exception e) { 
  e.printStackTrace(); 
} 

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論