Android⼊门项⽬(⼆)仿今⽇头条VideoPlayer,史上超级详细android:layout_marginLeft=“12dp”
android:layout_marginBottom=“11dp”
android:layout_toRightOf="@id/img_video_icon"
android:text=“不舔瓶盖” />
<TextView
android:id="@+id/tv_video_comment"
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_alignParentTop=“true”
android:layout_alignParentEnd=“true”
android:layout_alignParentRight=“true”
android:layout_marginTop=“10dp”
android:layout_marginEnd=“15dp”
android:layout_marginRight=“14dp”
in other wordsandroid:drawableLeft="@drawable/image"
android:text=“36”
android:textSize=“12sp” />
<TextView
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_centerVertical=“true”
android:layout_marginRight=“27dp”
android:layout_toLeftOf="@id/tv_video_comment"
android:text=“3万次播放” />
这⾥添加了⼀个Video和⼀个相对布局,中间的图标和⼀些xml⽂件请参照GitHub地址
3,适配器代码
public class VideoAdapter extends CommonAdapter {
private Context mContext;
/**
构造函数
@param context
@param datas
@param layoutId
*/七夕英文
public VideoAdapter(Context context, List datas, int layoutId) {图片英文
super(context, layoutId, datas);
this.mContext = context;
}
@Override
protected void convert(ViewHolder viewHolder, String url, int position) {
JCVideoPlayerStandard player = View(R.id.player_list_video);
if (player != null) {
}
player.tUp(url, JCVideoPlayerStandard.SCREEN_LAYOUT_NORMAL, “爸爸去买⼏个橘⼦就回”);
}技术资料翻译
}
适配器很简单
4,主活动代码
/**
主活动
@author zhangyan
*/
public class MainActivity extends AppCompatActivity {
//在线视频
/
/本地视频
String localUrl = ExternalStorageDirectory().getAbsolutePath() + “/video/aaaa.mp4”; private ListView listView;
private ArrayList datas;
private JCVideoPlayerStandard currPlayer;
private VideoAdapter adapter;
private ImageView image;
/**
滑动监听
*/
private AbsListView.OnScrollListener onScrollListener; /**
当前第⼀个可见的item
*/honeycomb
private int firstVisible;
/**
当前可见的item个数
*/
private int visibleCount;
@Override
protected void onCreate(Bundle savedInstanceState) { Create(savedInstanceState);
tContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.listview); initDatas();
initListener();
}
/**
初始化
*/
private void initDatas() {
datas = new ArrayList<>();
datas.add(videoUrl);
// mediaPlayer(videoUrl);
datas.add(videoUrl1);
datas.add(videoUrl2);
datas.add(videoUrl3);
datas.add(videoUrl4);
datas.add(videoUrl5);
datas.add(localUrl);
adapter = new VideoAdapter(MainActivity.this, datas, R.layout.item_video);kj是什么意思
listView.tAdapter(adapter);
}
/**
加载视频第⼀帧
*/
private void mediaPlayer(String url) {
MediaMetadataRetriever media = new MediaMetadataRetriever();
/
/实例化File对象,⽂件路径为/storage/sdcard/Movies/music1.mp4
if(!url.isEmpty()){
media.tDataSource(url);
Bitmap bitmap = FrameAtTime();
image = (ImageView)this.findViewById(R.id.player_list_video);
if(bitmap!=null){
image.tImageBitmap(bitmap);//设置ImageView显⽰的图⽚
}el{
//获取视频缩略图失败,弹出消息提⽰框
Toast.makeText(MainActivity.this, “获取视频缩略图失败”, Toast.LENGTH_SHORT).show(); }
}
}
chuhao/**
滑动监听
*/
private void initListener() {
onScrollListener = new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
switch (scrollState) {
ca AbsListView.OnScrollListener.SCROLL_STATE_FLING:
break;
ca AbsListView.OnScrollListener.SCROLL_STATE_IDLE:
//滑动停⽌⾃动播放视频
autoPlayVideo(view);
break;
ca AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
blockuibreak;
default:
break;
}
}
@Override
bewitch
public void onScroll(AbsListView view, int firstVisibleItem, int vi
《Android学习笔记总结+最新移动架构视频+⼤⼚安卓⾯试真题+项⽬实战源码讲义》
【/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享
sibleItemCount, int totalItemCount) {
if (firstVisible == firstVisibleItem) {
难受的英文
return;
}
firstVisible = firstVisibleItem;
visibleCount = visibleItemCount;
//判断是否滚到最后⼀⾏
if (firstVisibleItem + visibleItemCount == totalItemCount && totalItemCount > 0) {
/
/ Toast.makeText(MainActivity.this, “⼩可爱,已经到了最后⼀个视频了”, Toast.LENGTH_SHORT).show(); }
}
};
listView.tOnScrollListener(onScrollListener);
}
/**
滑动停⽌⾃动播放视频
*/
private void autoPlayVideo(AbsListView view) {
for (int i = 0; i < visibleCount; i++) {