Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.text.TextUtils;

import java.io.File;

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<String> getSubtitlePath(String videoPath) {
        List<String> sbPathList = new ArrayList<String>();
        if (TextUtils.isEmpty(videoPath))
            return sbPathList;
        if (videoPath.contains("file")) {
            videoPath = videoPath.substring(7);
        }

        int end = videoPath.lastIndexOf("/", videoPath.length());
        String path = videoPath.substring(0, end + 1);
        end = videoPath.lastIndexOf(".", videoPath.length());
        if (-1 == end || null == path)
            return sbPathList;

        String subffix = videoPath.substring(0, end);
        File files = new File(path);
        if ((files != null) && (files.exists()) && (files.isDirectory())) {
            File[] filesInDir = files.listFiles();
            long count = filesInDir.length;
            for (int num = 0; num < count; num++) {
                String filePath = filesInDir[num].getPath();
                File subTitleFile = new File(filePath);
                if ((subTitleFile != null) && (subTitleFile.isFile()) && (subTitleFile.canRead())) {
                    int pos = filePath.lastIndexOf(".", filePath.length());
                    String sub = filePath.substring(pos + 1, filePath.length());
                    if ((filePath.startsWith(subffix)) && (sub != null)
                            && ((sub.equalsIgnoreCase("srt")) || (sub.equalsIgnoreCase("ass"))
                                    || (sub.equalsIgnoreCase("smi")) || (sub.equalsIgnoreCase("ssa"))
                                    || (sub.equalsIgnoreCase("sub")))) {
                        sbPathList.add(filePath);
                    }
                }
            }
            if (sbPathList.size() != 0) {
                return sbPathList;
            }
        }
        return sbPathList;
    }
}