AdsVideoUtils.java 4.25 KB
package com.gimi.common.cinema.utils;

import android.text.TextUtils;
import android.util.Log;

import java.io.File;
import java.io.IOException;

/**
 * Created by wugian on 2016/7/22
 */
public class AdsVideoUtils {
    private static final String ADS_VIDEO_NAME = "qnyk.mp4";
    private static final String HASH_2D_DEMO = "c07f43798492d8c0cf58875e134e3793;0a00e1041ee59f4c12069f36c50acb9f;e763eb29a837b7609a0b4e8c8c0b3fb2;b241f1909e3fc8e36af7a1f28706bf07";
    //918
    private static final String Z4_PATH = "/sdcard/media/XgimiVideo/2D_DEMO.mp4";
    //928
    private static final String H1_PATH = "/sdcard/0/XgimiVideo/2D_DEMO.mp4";

    /**
     * 规则:服务器上的视频文件 -> 开机广告(目前只有z4x及z4xp上有path: /data/local/bootvideo.mp4) -> 2D_DEMO 视频
     *
     * @param sambaRootPath sambaRootPath
     * @return adsPath
     */
    public static String getAdsVideoPath(String sambaRootPath) {
        String videoPath = sambaRootPath + ADS_VIDEO_NAME;

        if (SambaFileCharge.fileExist(videoPath)) {
            String infoPath = sambaRootPath + ".video.inf";
            if (SambaFileCharge.fileExist(infoPath)) {
                String s = FileReadUtils.readDate(infoPath);
                String fileHash = FileHashUtils.getFileHash(videoPath);
                if (!TextUtils.isEmpty(s) && !TextUtils.isEmpty(fileHash)) {
                    if (s.equals(fileHash)) {
                        //charge the md5 right?
                        return videoPath;
                    }
                }
            }
        }
        if (new File("/data/local/bootvideo.mp4").exists()) {
            return "/data/local/bootvideo.mp4";
        }
        if (new File(Z4_PATH).exists()) {
            String fileHash = FileHashUtils.getFileHash(Z4_PATH);
            if (HASH_2D_DEMO.equals(fileHash)) {
                return Z4_PATH;
            }
        }
        if (new File(H1_PATH).exists()) {
            String fileHash = FileHashUtils.getFileHash(H1_PATH);
            if (HASH_2D_DEMO.equals(fileHash)) {
                return H1_PATH;
            }
        }
        return "file not exist or not legal";
    }

    public static String getAdsVideoHash(String sambaRootPath) {
        String videoPath = sambaRootPath + ADS_VIDEO_NAME;

        //存在合理就不再验证直接返回空
        if (SambaFileCharge.fileExist(videoPath)) {
            String infoPath = sambaRootPath + ".video.inf";
            if (SambaFileCharge.fileExist(infoPath)) {
                String s = FileReadUtils.readDate(infoPath);
                String fileHash = FileHashUtils.getFileHash(videoPath);
                if (!TextUtils.isEmpty(s) && !TextUtils.isEmpty(fileHash)) {
                    if (s.equals(fileHash)) {
                        Log.d("lovely", "╔════════════════════════════════════════════");
                        Log.d("lovely", "╟hash right return empty ");
                        Log.d("lovely", "╚════════════════════════════════════════════");
                        return "";
                    }
                }
            }
        }
        if (SambaFileCharge.fileExist(videoPath)) {
            return FileHashUtils.getFileHash(videoPath);
        }
        return "";
    }

    public static void writeAdsVideoInfo(String sambaRootPath, String videoInfo) {
        String infoPath = sambaRootPath + ".video.inf";
        if (!SambaFileCharge.fileExist(infoPath)) {
            try {
                new File(infoPath).createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (SambaFileCharge.fileExist(infoPath)) {
            FileReadUtils.writeDate(infoPath, videoInfo);
        } else {
            Log.d("lovely", "╔════════════════════════════════════════════");
            Log.d("lovely", "╟广告信息写入失败");
            Log.d("lovely", "╚════════════════════════════════════════════");
        }
    }
}