Java Code Examples for com.blankj.utilcode.util.FileUtils#getFileName()

The following examples show how to use com.blankj.utilcode.util.FileUtils#getFileName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskDownloadingFileItem.java    From DanDanPlayForAndroid with MIT License 6 votes vote down vote up
@SuppressLint("SetTextI18n")
@Override
public void onUpdateViews(TorrentChildFile model, int position) {

    String fileName = FileUtils.getFileName(model.getFileName());

    fileNameTv.setText(fileName);

    //文件是否忽略下载
    if (model.isChecked()) {
        fileNameTv.setTextColor(CommonUtils.getResColor(R.color.text_black));
        int progress = model.getFileSize() == 0
                ? 0
                : (int) (model.getFileReceived() * 100 / model.getFileSize());
        downloadDurationPb.setProgress(progress);

        String duration = CommonUtils.convertFileSize(model.getFileReceived()) + "/" + CommonUtils.convertFileSize(model.getFileSize());
        duration += "  (" + progress + "%)";
        durationTv.setText(duration);
    } else {
        fileNameTv.setTextColor(CommonUtils.getResColor(R.color.text_gray));
        downloadDurationPb.setProgress(0);
        durationTv.setText("已忽略");
    }
}
 
Example 2
Source File: FolderPresenterImpl.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@Override
public void getDanmu(String videoPath) {
    getView().showLoading();
    String title = FileUtils.getFileName(videoPath);
    DanmuMatchParam param = new DanmuMatchParam();
    String hash = MD5Util.getVideoFileHash(videoPath);
    long length = new File(videoPath).length();
    long duration = MD5Util.getVideoDuration(videoPath);
    param.setFileName(title);
    param.setFileHash(hash);
    param.setFileSize(length);
    param.setVideoDuration(duration);
    param.setMatchMode("hashAndFileName");
    DanmuMatchBean.matchDanmu(param, new CommJsonObserver<DanmuMatchBean>(getLifecycle()) {
        @Override
        public void onSuccess(DanmuMatchBean danmuMatchBean) {
            getView().hideLoading();
            if (danmuMatchBean.getMatches().size() > 0)
                getView().downloadDanmu(danmuMatchBean.getMatches().get(0));
            else
                getView().noMatchDanmu(videoPath);
        }

        @Override
        public void onError(int errorCode, String message) {
            getView().hideLoading();
            getView().noMatchDanmu(videoPath);
        }
    }, new NetworkConsumer());
}
 
Example 3
Source File: FolderPresenterImpl.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
/**
 * 获取匹配弹幕的参数
 */
private Map<String, String> getDanmuMatchParam(String videoPath) {
    String title = FileUtils.getFileName(videoPath);
    DanmuMatchParam param = new DanmuMatchParam();
    String hash = MD5Util.getVideoFileHash(videoPath);
    long length = new File(videoPath).length();
    long duration = MD5Util.getVideoDuration(videoPath);
    param.setFileName(title);
    param.setFileHash(hash);
    param.setFileSize(length);
    param.setVideoDuration(duration);
    param.setMatchMode("hashAndFileName");
    return param.getMap();
}
 
Example 4
Source File: BindDanmuPresenterImpl.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@Override
public void matchDanmu(String videoPath) {

    if (StringUtils.isEmpty(videoPath)) {
        ToastUtils.showShort("无匹配弹幕");
        return;
    }

    String title = FileUtils.getFileName(videoPath);
    String hash = MD5Util.getVideoFileHash(videoPath);
    long length = new File(videoPath).length();
    long duration = MD5Util.getVideoDuration(videoPath);
    DanmuMatchParam param = new DanmuMatchParam();
    param.setFileName(title);
    param.setFileHash(hash);
    param.setFileSize(length);
    param.setVideoDuration(duration);
    param.setMatchMode("hashAndFileName");

    getView().showLoading();
    DanmuMatchBean.matchDanmu(param, new CommJsonObserver<DanmuMatchBean>(getLifecycle()) {
        @Override
        public void onSuccess(DanmuMatchBean danmuMatchBean) {
            getView().hideLoading();
            if (danmuMatchBean.getMatches().size() > 0)
                getView().refreshDanmuAdapter(danmuMatchBean.getMatches());
            else
                ToastUtils.showShort("无匹配弹幕");
        }

        @Override
        public void onError(int errorCode, String message) {
            getView().hideLoading();
            ToastUtils.showShort(message);
        }
    }, new NetworkConsumer());
}
 
Example 5
Source File: TaskDownloadedFileItem.java    From DanDanPlayForAndroid with MIT License 4 votes vote down vote up
@SuppressLint("SetTextI18n")
@Override
public void onUpdateViews(DownloadedTaskBean.DownloadedTaskFileBean model, int position) {

    danmuBindIv.setImageResource(StringUtils.isEmpty(model.getDanmuPath())
            ? R.mipmap.ic_danmu_unexists
            : R.mipmap.ic_danmu_exists);

    String fileName = FileUtils.getFileName(model.getFilePath());
    fileNameTv.setText(fileName);

    fileSizeTv.setText(CommonUtils.convertFileSize(model.getFileLength()));

    if (!TextUtils.isEmpty(model.getDanmuPath())){
        File file = new File(model.getDanmuPath());
        if (file.exists() && file.isFile()){
            danmuBindIv.setImageResource(R.mipmap.ic_danmu_exists);
        }
    }

    danmuBindIv.setOnClickListener(v -> {
        if (CommonUtils.isMediaFile(model.getFilePath())) {
            BindResourceParam param = new BindResourceParam(model.getFilePath(), taskPosition, position);
            Intent intent = new Intent(mActivity, BindDanmuActivity.class);
            intent.putExtra("bind_param", param);
            mActivity.startActivityForResult(intent, DownloadManagerActivity.TASK_DOWNLOADED_DANMU_BIND);
        } else {
            ToastUtils.showShort("不支持绑定弹幕的文件格式");
        }
    });

    mView.setOnClickListener(v -> {
        if (CommonUtils.isMediaFile(model.getFilePath())){
            PlayerManagerActivity.launchPlayerLocal(
                    mView.getContext(),
                    fileName,
                    model.getFilePath(),
                    model.getDanmuPath(),
                    "",
                    0,
                    model.getEpisode_id()
            );
        }else {
            ToastUtils.showShort("不支持播放的文件格式");
        }
    });
}
 
Example 6
Source File: PlayerManagerActivity.java    From DanDanPlayForAndroid with MIT License 4 votes vote down vote up
private void initIntent() {
    Intent openIntent = getIntent();
    videoTitle = openIntent.getStringExtra("video_title");
    videoPath = openIntent.getStringExtra("video_path");
    danmuPath = openIntent.getStringExtra("danmu_path");
    zimuPath = openIntent.getStringExtra("zimu_path");
    currentPosition = openIntent.getLongExtra("current_position", 0L);
    episodeId = openIntent.getIntExtra("episode_id", 0);
    thunderTaskId = openIntent.getLongExtra("thunder_task_id", -1L);
    searchWord = openIntent.getStringExtra("search_word");

    sourceOrigin = openIntent.getIntExtra("source_origin", SOURCE_ORIGIN_LOCAL);

    //本地文件播放可预先绑定弹幕,其它播放来源都应弹窗询问是否选择弹幕
    boolean showSelectDanmuDialog = AppConfig.getInstance().isShowOuterChainDanmuDialog();
    boolean autoLaunchDanmuPage = AppConfig.getInstance().isOuterChainDanmuSelect();

    //外部打开
    if (Intent.ACTION_VIEW.equals(openIntent.getAction())) {
        sourceOrigin = SOURCE_ORIGIN_OUTSIDE;
        //获取视频地址
        Uri data = getIntent().getData();
        if (data != null) {
            videoPath = CommonUtils.getRealFilePath(PlayerManagerActivity.this, data);
        }
    }

    //检查视频地址
    if (TextUtils.isEmpty(videoPath)) {
        ToastUtils.showShort("解析视频地址失败");
        errorTv.setVisibility(View.VISIBLE);
        return;
    }

    //检查弹幕地址
    if (!TextUtils.isEmpty(danmuPath) && danmuPath.toLowerCase().endsWith(".xml")) {
        File danmuFile = new File(danmuPath);
        if (!danmuFile.exists() || !danmuFile.isFile()) {
            danmuPath = "";
        }
    }

    //检查字幕地址
    if (!TextUtils.isEmpty(zimuPath)) {
        File zimuFile = new File(zimuPath);
        if (!zimuFile.exists() || !zimuFile.isFile()) {
            zimuPath = "";
        }
    }

    //检查视频标题
    videoTitle = TextUtils.isEmpty(videoTitle) ? FileUtils.getFileName(videoPath) : videoTitle;
    searchWord = TextUtils.isEmpty(searchWord) ? FileUtils.getFileNameNoExtension(videoPath) : searchWord;

    //选择弹幕弹窗及跳转
    if (sourceOrigin != SOURCE_ORIGIN_LOCAL) {
        if (showSelectDanmuDialog) {
            new DanmuSelectDialog(this, isSelectDanmu -> {
                if (isSelectDanmu) {
                    launchDanmuSelect(searchWord);
                } else {
                    launchPlayerActivity();
                }
            }).show();
            return;
        }
        if (autoLaunchDanmuPage) {
            launchDanmuSelect(searchWord);
            return;
        }
    }
    launchPlayerActivity();
}