ijkPlayer视频播放

http://blog.csdn.net/qq_23477421/article/details/51822584



compile 'fm.jiecao:jiecaovideoplayer:5.5'

在清单文件中配置,哪个Activity用,就加到哪里
<activity android:name=".MainActivity"
    android:configChanges="orientation|screenSize|keyboardHidden"
    android:screenOrientation="portrait">

xml控件
<fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard
    android:id="@+id/jiecao_Player"
    android:layout_width="match_parent"
    android:layout_height="200dp">
fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard>
 
  
设置播放路径     //PATH为视频路径
 
  
jiecaoPlayer.setUp(PATH,jiecaoPlayer.SCREEN_LAYOUT_NORMAL,"视频");

给视频添加一个站位的图片
Glide.with(context).load(R.mipmap.login1).into((ImageView)holder.jiecao_Player.thumbImageView);

饺子 网址 : http://blog.csdn.net/zhaihaohao1/article/details/78029766
compile 'cn.jzvd:jiaozivideoplayer:6.0.0'

或直接下载jar包 不建议

2.添加布局

<cn.jzvd.JZVideoPlayerStandard
    android:id="@+id/videoplayer"
    android:layout_width="match_parent"
    android:layout_height="200dp"/>

3.设置视频地址、缩略图地址、标题

JZVideoPlayerStandard jzVideoPlayerStandard = (JZVideoPlayerStandard) findViewById(R.id.videoplayer);
jzVideoPlayerStandard.setUp("http://jzvd.nathen.cn/c6e3dc12a1154626b3476d9bf3bd7266/6b56c5f0dc31428083757a45764763b0-5287d2089db37e62345123a1be272f8b.mp4"
                            , JZVideoPlayerStandard.SCREEN_LAYOUT_NORMAL, "嫂子闭眼睛");
jzVideoPlayerStandard.thumbImageView.setImage("http://p.qpic.cn/videoyun/0/2449_43b6f696980311e59ed467f22794e792_1/640");

4.在Activity

@Override
public void onBackPressed() {
    if (JZVideoPlayer.backPress()) {
        return;
    }
    super.onBackPressed();
}
@Override
protected void onPause() {
    super.onPause();
    JZVideoPlayer.releaseAllVideos();
}

5.在AndroidManifest.xml

 

1. ListView普通列表,参考demo的VideoListAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder;
    if (null == convertView) {
        viewHolder = new ViewHolder();
        LayoutInflater mInflater = LayoutInflater.from(context);
        convertView = mInflater.inflate(R.layout.item_videoview, null);
        convertView.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }
    viewHolder.jcVideoPlayer = (JCVideoPlayerStandard) convertView.findViewById(R.id.videoplayer);
    viewHolder.jcVideoPlayer.setUp(
            VideoConstant.videoUrls[0][position], JCVideoPlayer.SCREEN_LAYOUT_LIST,
            VideoConstant.videoTitles[0][position]);
    Picasso.with(convertView.getContext())
            .load(VideoConstant.videoThumbs[0][position])
            .into(viewHolder.jcVideoPlayer.thumbImageView);
    return convertView;
}

和QuickStart的基本用法一样,5个步骤。

如果想让视频滑动出列表停止播放,那么列表必须是复用的,因为在列表复用的时候调用setUp函数,setUp里的onStateNormal函数会release视频。

2. Fragment + ViewPager + ListView的列表播放,参考demo的ListViewViewpagerActivity.java

@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

}

@Override
public void onPageSelected(int position) {
    JCVideoPlayer.releaseAllVideos();
}
@Override
public void onPageScrollStateChanged(int state) {

}

在ListView普通列表的基础上,滑动ViewPager时release视频。

不用在Fragment的onPause中releaseAllVideos(),如果有其他形式的Fragment的切换的话,在切换Fragment的时候releaseAllVideos(),总之在需要releaseAllVideos()的时候都可以调用。

3. MultiHolder + ListView的列表播放,参考demo的ListViewMultiHolderActivity.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    //This is the point
    if (convertView != null && convertView.getTag() != null && convertView.getTag() instanceof VideoHolder) {
        ((VideoHolder) convertView.getTag()).jcVideoPlayer.release();
    }
    ......
    return convertView;
}

重点在于判断列表复用的时候,在复用之前Item是否是视频的Item,如果是的话说明视频已经被移除列表不可见了,那么就应该releaseAllVideos()。




你可能感兴趣的:(andriod)