1. 程式人生 > >視訊和圖片輪播廣告欄,商品詳情輪播

視訊和圖片輪播廣告欄,商品詳情輪播

網上弄了個輪播視訊的基礎demo滑動可能有點小問題請自行修改

視訊+圖片輪播

1.Banner中的init方法中替換:

LayoutInflater inflater = LayoutInflater.from(getContext()); View view=inflater.inflate(R.layout.item_goodsinfofragment_viewpager,null); viewPager=(ViewPager)view.findViewById(R.id.main_viewpager) ; mLinearLayout = (LinearLayout) view.findViewById(R.id.main_linear); this.addView(view);//替換之前viewPager佈局的,初始化小圓點,onPageSelected中判斷指示器狀態等網上有

2.指示器弄完可以除錯下視訊:

滑動暫停時 滑動停止播放onPageScrollStateChanged新增:

if (state==ViewPager.SCROLL_STATE_IDLE){//滑動結束                             if(autoCurrIndex<list.size()){                                 if (MimeTypeMap.getFileExtensionFromUrl(list.get(autoCurrIndex)).equals("mp4")){                                     isAutoPlay = false;//視訊播放中不自動輪播                                     System.out.println("播放"+autoCurrIndex+isAutoPlay); //                                    JZVideoPlayer.goOnPlayOnResume();

                                }                             } //                         }else if (state==ViewPager.SCROLL_STATE_DRAGGING){//正在滑動                             if(autoCurrIndex<list.size()){                                 if (MimeTypeMap.getFileExtensionFromUrl(list.get(autoCurrIndex)).equals("mp4")){                                     System.out.println("暫停"+autoCurrIndex+isAutoPlay);                                   JZVideoPlayer.clearSavedProgress(context, null);                                     JZVideoPlayer.goOnPlayOnPause();                                 }                             }                         }

我的是放在Fragment中的所以全屏播放按手機返回直接整個acrivity退出了而不是僅僅退出視訊全屏,修改:

@Override public boolean onKeyDown(int keyCode, KeyEvent event) {     if (keyCode == KeyEvent.KEYCODE_BACK) {         JZVideoPlayerStandard jz=new JZVideoPlayerStandard(context);         boolean aaa=jz.backPress();         if (aaa) {             JZVideoPlayer.backPress();             Log.i("TAG",""+"關閉全屏");             return true;         }             finish();

    }     return false; }

3.最後是視訊縮圖

loadVideoScreenshot(context,url,jzVideoPlayerStandard.thumbImageView,1000);//在views.add(root);之前新增即可

public static void loadVideoScreenshot(final Context context, String uri, ImageView imageView, long frameTimeMicros) {     RequestOptions requestOptions = RequestOptions.frameOf(frameTimeMicros);     requestOptions.set(FRAME_OPTION, MediaMetadataRetriever.OPTION_CLOSEST);     requestOptions.transform(new BitmapTransformation() {         @Override         protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {             return toTransform;         }

        @Override         public void updateDiskCacheKey(MessageDigest messageDigest) {             try {                 messageDigest.update((context.getPackageName() + "RotateTransform").getBytes("utf-8"));             } catch (Exception e) {                 e.printStackTrace();             }         }     });     Glide.with(context).load(uri).apply(requestOptions).into(imageView); }

記得新增類庫:

compile 'cn.jzvd:jiaozivideoplayer:6.2.12' compile 'com.github.bumptech.glide:glide:4.0.0'

完成後的效果