소스 검색

geo视频

zhaofuxin 4 년 전
부모
커밋
f22828e46d

+ 27 - 12
app/src/main/java/com/jld/vod/service/LatLongService.kt

@@ -31,6 +31,7 @@ import com.jld.vod.utils.LogUtils
 import com.jld.vod.utils.http.OkHttpUtils
 import com.jld.vod.utils.SharedPrefUtils
 import com.jld.vod.view.widget.CustomGEOAdDialog
+import com.jld.vod.view.widget.CustomVideoGEOAdDialog
 import com.jld.vod.viewmodel.MainViewModel
 import okhttp3.Call
 import okhttp3.Response
@@ -57,6 +58,7 @@ class LatLongService :Service() {
     private var carinfo:CarSiteAllBean?=null
 
     private lateinit var mCustom : CustomGEOAdDialog
+    private lateinit var mVideoCustom : CustomVideoGEOAdDialog
     private var mContext: Context ?= null
 
     private val mHandler: Handler = @SuppressLint("HandlerLeak")
@@ -139,15 +141,25 @@ class LatLongService :Service() {
                 2->{
                     //开启通知
                     val result = msg.obj as GEOAdvertBean
-                    LogUtils.logD("result"+result)
                     if (result.data != null)
                     {
-                        mCustom = CustomGEOAdDialog(mContext)
-                        mCustom.getWindow()!!.setType((WindowManager.LayoutParams.TYPE_SYSTEM_ALERT));
-                        mCustom.setDataList(result.data)
-                        mCustom!!.setCancelable(false)
-                        mCustom!!.setCanceledOnTouchOutside(false)
-                        mCustom.show()
+                        if (result.data[0].fileType == 0)
+                        {
+                            mCustom = CustomGEOAdDialog(mContext)
+                            mCustom.getWindow()!!.setType((WindowManager.LayoutParams.TYPE_SYSTEM_ALERT));
+                            mCustom.setDataList(result.data)
+                            mCustom!!.setCancelable(false)
+                            mCustom!!.setCanceledOnTouchOutside(false)
+                            mCustom.show()
+                        }else if (result.data[0].fileType == 1)
+                        {
+                            mVideoCustom = CustomVideoGEOAdDialog(mContext)
+                            mVideoCustom.getWindow()!!.setType((WindowManager.LayoutParams.TYPE_SYSTEM_ALERT));
+                            mVideoCustom.setDataList(result.data)
+                            mVideoCustom!!.setCancelable(false)
+                            mVideoCustom!!.setCanceledOnTouchOutside(false)
+                            mVideoCustom.show()
+                        }
                     }
 
                  //   addNotification(result.pat,result.info,result.bitmap)
@@ -187,11 +199,14 @@ class LatLongService :Service() {
             override fun success(call: Call?, response: Response?) {
                 val json = response!!.body!!.string()
 
-                val mGEOAdvertBean= gson!!.fromJson(json, GEOAdvertBean::class.java)
-                val msg = Message()
-                msg.what = 2
-                msg.obj = mGEOAdvertBean
-                mHandler.sendMessage(msg)
+                if(json != null)
+                {
+                    val mGEOAdvertBean= gson!!.fromJson(json, GEOAdvertBean::class.java)
+                    val msg = Message()
+                    msg.what = 2
+                    msg.obj = mGEOAdvertBean
+                    mHandler.sendMessage(msg)
+                }
 
             }
         })

+ 1 - 1
app/src/main/java/com/jld/vod/view/widget/CustomGEOAdDialog.java

@@ -100,7 +100,7 @@ public class CustomGEOAdDialog
         list.clear();
         for (int i = 0;i<positionAdvert.size();i++)
         {
-            list.add(Config.ApiBaseUrl + "/synchronization/previewImg?imgUrl=" + positionAdvert.get(i).getFilePath());
+            list.add(Config.ApiBaseUrl +"/"+ positionAdvert.get(i).getFilePath());
         }
     }
 

+ 186 - 0
app/src/main/java/com/jld/vod/view/widget/CustomVideoGEOAdDialog.java

@@ -0,0 +1,186 @@
+package com.jld.vod.view.widget;
+
+import android.annotation.SuppressLint;
+import android.app.Dialog;
+import android.content.Context;
+import android.media.MediaPlayer;
+import android.os.Bundle;
+import android.os.CountDownTimer;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.Window;
+import android.view.WindowManager;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+import android.widget.VideoView;
+
+import com.jld.vod.R;
+import com.jld.vod.config.Config;
+import com.jld.vod.model.bean.Datas;
+import com.youth.banner.Banner;
+import com.youth.banner.BannerConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CustomVideoGEOAdDialog
+        extends Dialog
+{
+
+    //private ImageView mCloseImg;
+    private TextView auto_ms_text;
+    private VideoView vd_geo_ad;
+    private List<String> list = new ArrayList<>();
+    private Context mContext;
+    public OnClickBottomListener onClickBottomListener;
+
+
+    public CustomVideoGEOAdDialog(Context paramContext)
+    {
+        super(paramContext, R.style.MyDialog);
+        this.mContext = paramContext;
+
+
+    }
+
+    @Override
+    public void dismiss() {
+        super.dismiss();
+    }
+
+    private void initEvent()
+    {
+
+    }
+
+    private void initView()
+    {
+
+        this.auto_ms_text = findViewById(R.id.auto_ms_text);
+
+        //轮播
+        this.vd_geo_ad = (VideoView)findViewById(R.id.vd_geo_ad);
+        vd_geo_ad.setOnTouchListener(new View.OnTouchListener() {
+            @Override
+            public boolean onTouch(View v, MotionEvent event) {
+                return true;
+            }
+        });
+
+        //videoview全屏拉伸
+        RelativeLayout.LayoutParams layoutParams = new  RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
+        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
+        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
+        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
+        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
+        vd_geo_ad.setLayoutParams(layoutParams);
+
+        if (list != null)
+        {
+            vd_geo_ad.setVideoPath(list.get(0));
+            vd_geo_ad.start();
+            //循环播放
+            vd_geo_ad.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
+                @Override
+                public void onPrepared(MediaPlayer mp) {
+                    mp.start();
+                    mp.setLooping(true);
+                }
+            });
+        }
+    }
+
+    @Override
+    public void show() {
+
+        /** 倒计时30秒,一次1秒 */
+        CountDownTimer timer = new CountDownTimer(30*1000, 1000) {
+            @Override
+            public void onTick(long millisUntilFinished) {
+                // TODO Auto-generated method stub
+                auto_ms_text.setText(millisUntilFinished/1000+"");
+            }
+
+            @Override
+            public void onFinish() {
+                vd_geo_ad.stopPlayback();
+                auto_ms_text.setText("0");
+                dismiss();
+            }
+        }.start();
+        super.show();
+    }
+
+    /**
+     * 设置数据
+     * @param positionAdvert
+     */
+    public void setDataList(List<Datas> positionAdvert)
+    {
+        list.clear();
+        for (int i = 0;i<positionAdvert.size();i++)
+        {
+            list.add(Config.ApiBaseUrl + "/synchronization/previewImg?imgUrl=" + positionAdvert.get(i).getFilePath());
+        }
+    }
+
+    @SuppressLint("WrongConstant")
+    private void refreshView()
+    {
+
+//        if (!TextUtils.isEmpty(this.tv_ok)) {
+//            this.mBtnOk.setText(this.tv_ok);
+//        }
+//        if (!TextUtils.isEmpty(this.tv_no)) {
+//            this.mBtnNo.setText(this.tv_no);
+//        }
+//        Button localButton = this.mBtnNo;
+//        if (this.visiable) {}
+//        for (int i = 0;; i = 8)
+//        {
+//            localButton.setVisibility(i);
+//            if (!TextUtils.isEmpty(this.tv_cus))
+//            {
+//                this.mBtnCus.setText(this.tv_cus);
+//                this.mBtnCus.setVisibility(View.VISIBLE);
+//            }
+//            return;
+//        }
+    }
+
+    protected void onCreate(Bundle paramBundle)
+    {
+        super.onCreate(paramBundle);
+        setContentView(R.layout.custom_video_geo_ad_dialog);
+        setCanceledOnTouchOutside(false);
+        Window w = getWindow();
+//        int width = 850;
+//        int height = 600;
+//        w.setLayout(width,height);
+        w.setGravity(17);
+        WindowManager.LayoutParams localLayoutParams = w.getAttributes();
+
+        localLayoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
+        localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
+
+        w.setWindowAnimations(R.style.AnimationDialog);
+        w.setAttributes(localLayoutParams);
+
+        initView();
+        refreshView();
+        initEvent();
+    }
+
+
+    public CustomVideoGEOAdDialog setOnClickBottomListener(OnClickBottomListener paramOnClickBottomListener)
+    {
+        this.onClickBottomListener = paramOnClickBottomListener;
+        return this;
+    }
+
+
+    public static abstract interface OnClickBottomListener
+    {
+        public abstract void onBtnCloseClick();
+    }
+}

+ 29 - 0
app/src/main/res/layout/custom_video_geo_ad_dialog.xml

@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:background="@color/white"
+    android:orientation="vertical">
+    <VideoView
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:id="@+id/vd_geo_ad"
+        />
+
+    <TextView
+        android:layout_alignParentTop="true"
+        android:layout_alignParentRight="true"
+        android:id="@+id/auto_ms_text"
+        android:textColor="@color/black"
+        android:textSize="16sp"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_margin="20dp"
+        android:paddingTop="5dp"
+        android:paddingBottom="5dp"
+        android:paddingLeft="10dp"
+        android:paddingRight="10dp"
+        android:background="@color/white"
+        />
+
+</RelativeLayout>