com.blankj.utilcode.util.FileUtils Java Examples

The following examples show how to use com.blankj.utilcode.util.FileUtils. 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 Project: FastWaiMai   Author: zion223   File: CameraHandler.java    License: MIT License 6 votes vote down vote up
private void takePhoto() {
	final String currentPhotoName = getPhotoName();
	final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
	final File tempFile = new File(FileUtil.CAMERA_PHOTO_DIR, currentPhotoName);
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
		final ContentValues contentValues = new ContentValues(1);
		contentValues.put(MediaStore.Images.Media.DATA, tempFile.getPath());
		final Uri uri = DELEGATE.getContext().getContentResolver().
				insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);
		//需要将Uri路径转化为实际路径
		final File realFile =
				FileUtils.getFileByPath(FileUtil.getRealFilePath(DELEGATE.getContext(), uri));
		final Uri realUri = Uri.fromFile(realFile);
		CameraImageBean.getInstance().setPath(realUri);
		intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
	} else {
		final Uri fileUri = Uri.fromFile(tempFile);
		CameraImageBean.getInstance().setPath(fileUri);
		intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
	}
	DELEGATE.startActivityForResult(intent, CameraRequestCodes.TAKE_PHOTO);

}
 
Example #2
Source Project: DoraemonKit   Author: didi   File: NetWorkMonitorFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    //保存白名单
    List<WhiteHostBean> hostBeans = mHostAdapter.getData();
    if (hostBeans.size() == 1 && TextUtils.isEmpty(hostBeans.get(0).getHost())) {
        DokitConstant.WHITE_HOSTS.clear();
        FileUtils.delete(whiteHostPath);
        return;
    }
    DokitConstant.WHITE_HOSTS.clear();
    DokitConstant.WHITE_HOSTS.addAll(hostBeans);
    String hostArray = GsonUtils.toJson(hostBeans);
    //保存到本地
    FileUtils.delete(whiteHostPath);
    FileIOUtils.writeFileFromString(whiteHostPath, hostArray);
    //ToastUtils.showShort("host白名单已保存");

}
 
Example #3
Source Project: DanDanPlayForAndroid   Author: xyoye   File: MD5Util.java    License: MIT License 6 votes vote down vote up
public static String getVideoFileHash(String filePath) {
    try {
        File file = FileUtils.getFileByPath(filePath);
        if (file != null) {
            if (file.length() < 16 * 1024 * 1024) {
                return getFileMD5String(file);
            } else {
                RandomAccessFile r = new RandomAccessFile(file, "r");
                r.seek(0);
                byte[] bs = new byte[16 * 1024 * 1024];
                r.read(bs);
                return getMD5String(bs);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "";
}
 
Example #4
Source Project: DanDanPlayForAndroid   Author: xyoye   File: SubtitleConverter.java    License: MIT License 6 votes vote down vote up
private static List<SubtitleBean> shooter2subtitle(List<SubtitleBean.Shooter> shooterList, String filePath){

        if (shooterList == null || shooterList.size() == 0){
            return new ArrayList<>();
        }

        List<SubtitleBean> subtitleList = new ArrayList<>();
        for (SubtitleBean.Shooter shooterBean : shooterList){
            for (SubtitleBean.Shooter.FilesBean shooterFile : shooterBean.getFiles()){
                if (StringUtils.isEmpty(shooterFile.getLink()))
                    continue;
                SubtitleBean subtitleBean = new SubtitleBean();
                subtitleBean.setOrigin(SubtitleBean.Shooter.SHOOTER);
                subtitleBean.setName(FileUtils.getFileNameNoExtension(filePath) + "." + shooterFile.getExt());
                subtitleBean.setRank(-1);
                subtitleBean.setUrl(shooterFile.getLink());
                subtitleList.add(subtitleBean);
            }
        }
        return subtitleList;
    }
 
Example #5
Source Project: DanDanPlayForAndroid   Author: xyoye   File: MainPresenterImpl.java    License: MIT License 6 votes vote down vote up
@Override
public void initTracker() {
    IApplication.getExecutor().execute(() -> {
        //trackers数据
        File configFolder = new File(FileUtils.getDirName(Constants.DefaultConfig.configPath));
        if (configFolder.isFile())
            configFolder.delete();
        if (!configFolder.exists())
            configFolder.mkdirs();

        File trackerFile = new File(Constants.DefaultConfig.configPath);

        //文件不存在,读取asset中默认的trackers,并写入文件
        if (!trackerFile.exists()) {
            TrackerManager.resetTracker();
        }
        //文件存在,直接读取
        else {
            TrackerManager.queryTracker();
        }
    });
}
 
Example #6
Source Project: DanDanPlayForAndroid   Author: xyoye   File: DownloadedFragment.java    License: MIT License 6 votes vote down vote up
@Override
public void onTaskDelete(int position, String taskHash, boolean withFile) {
    //删除系统中文件
    if (withFile) {
        FileUtils.deleteDir(taskList.get(position).getSaveDirPath());
    }

    //删除数据库中信息
    DataBaseManager.getInstance()
            .selectTable("downloaded_task")
            .delete()
            .where("torrent_hash", taskHash)
            .postExecute();
    DataBaseManager.getInstance()
            .selectTable("downloaded_file")
            .delete()
            .where("task_torrent_hash", taskHash)
            .postExecute();

    //刷新媒体库数据
    EventBus.getDefault().post(UpdateFragmentEvent.updatePlay(PlayFragment.UPDATE_SYSTEM_DATA));

    //更新界面数据
    if (position > -1 && position < taskList.size())
        taskRvAdapter.removeItem(position);
}
 
Example #7
Source Project: DanDanPlayForAndroid   Author: xyoye   File: TaskDownloadingFileItem.java    License: 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 #8
Source Project: DanDanPlayForAndroid   Author: xyoye   File: SmbFilePresenterImpl.java    License: MIT License 6 votes vote down vote up
private String checkZimuExist(List<SmbFileInfo> smbFileInfoList, String fullVideoName) {
    //获取smb视频文件名:test.mp4 -> test.
    String videoName = FileUtils.getFileNameNoExtension(fullVideoName) + ".";

    for (SmbFileInfo fileInfo : smbFileInfoList) {
        String fileName = fileInfo.getFileName();
        //是否以视频文件名开头:可test.ass,不可test1.ass
        if (fileName.startsWith(videoName)) {
            //是否为可解析字幕:可.ass,不可.1ass
            for (String ext : CommonPlayerUtils.subtitleExtension) {
                if (fileName.toUpperCase().endsWith("." + ext)) {
                    //是否只包含最多两个点:可test.ass、test.sc.ass,不可test.1.sc.ass
                    int pointCount = fileName.split(".").length - 1;
                    if (pointCount <= 2) {
                        return fileName;
                    }
                }
            }

        }
    }
    return null;
}
 
Example #9
Source Project: SuperNote   Author: ifadai   File: EditNotePresenter.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void copyFileInOtherThread(String imagePath) {
    final String imagePaths = imagePath;
    new AsyncTask<String, Integer, Boolean>() {

        @Override
        protected void onPreExecute() {
            mView.showLoading("加载中...");
        }

        @Override
        protected Boolean doInBackground(String... params) {
            return FileUtils.copyFile(new File(imagePaths), mImageFile);
        }

        @Override
        protected void onPostExecute(Boolean aBoolean) {
            mView.unShowLoading();
            if (aBoolean) {
                displayImage();
            } else {
                ToastUtils.showShort("图片读取失败");
            }
        }
    }.execute();
}
 
Example #10
Source Project: SuperNote   Author: ifadai   File: ImagePresenter.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void copyFile( final Activity activity){
    new AsyncTask<String,Integer,Boolean>(){

        @Override
        protected void onPreExecute() {
            mView.showLoading("保存中...");
        }

        @Override
        protected Boolean doInBackground(String... params) {
            return  FileUtils.copyFile(getImageFile(activity),
                    new File(Constans.imageSaveFolder+mImageName));
        }

        @Override
        protected void onPostExecute(Boolean aBoolean) {
            mView.unShowLoading();
            if(aBoolean){
                ToastUtils.showLong("已保存至/SuperNote/image/中");
            } else {
                ToastUtils.showLong("保存失败,请查看图片是否已存在");
            }
        }
    }.execute();
}
 
Example #11
Source Project: SuperNote   Author: ifadai   File: ImagePresenter.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void deleteFile(final Activity activity){
    new AsyncTask<String,Integer,Boolean>(){

        @Override
        protected void onPreExecute() {
            mView.showLoading("删除中...");
        }

        @Override
        protected Boolean doInBackground(String... params) {
            return FileUtils.deleteFile(getImageFile(activity));
        }

        @Override
        protected void onPostExecute(Boolean aBoolean) {
            mView.unShowLoading();
            if(aBoolean){
                mView.setResultAndFinish();
            } else {
                ToastUtils.showShort("删除失败");
            }
        }
    }.execute();
}
 
Example #12
Source Project: AndroidUtilCode   Author: Blankj   File: FileItem.java    License: Apache License 2.0 6 votes vote down vote up
public static List<FileItem> getFileItems(final FileItem parent) {
    if (parent == null) return getFileItems();
    List<File> files = FileUtils.listFilesInDir(parent.getFile(), new Comparator<File>() {
        @Override
        public int compare(File o1, File o2) {
            if (o1.isDirectory() && o2.isFile()) {
                return -1;
            } else if (o1.isFile() && o2.isDirectory()) {
                return 1;
            } else {
                return o1.getName().toLowerCase().compareTo(o2.getName().toLowerCase());
            }
        }
    });
    return (List<FileItem>) CollectionUtils.collect(files, new CollectionUtils.Transformer<File, FileItem>() {
        @Override
        public FileItem transform(File input) {
            return new FileItem(parent, input);
        }
    });
}
 
Example #13
Source Project: AndroidUtilCode   Author: Blankj   File: ImageLoader.java    License: Apache License 2.0 6 votes vote down vote up
public static void load(final File file, final ImageView imageView) {
    if (!FileUtils.isFileExists(file)) return;
    imageView.post(new Runnable() {
        @Override
        public void run() {
            ThreadUtils.executeByCached(new ThreadUtils.SimpleTask<Bitmap>() {
                @Override
                public Bitmap doInBackground() throws Throwable {
                    return ImageUtils.getBitmap(file, imageView.getWidth(), imageView.getHeight());
                }

                @Override
                public void onSuccess(final Bitmap result) {
                    imageView.setImageBitmap(result);
                }
            });
        }
    });
}
 
Example #14
Source Project: AndroidUtilCode   Author: Blankj   File: FileHelper.java    License: Apache License 2.0 6 votes vote down vote up
@FileType
public static int getFileType(File file) {
    if (!FileUtils.isFileExists(file)) return UNKNOWN;
    if (ImageUtils.isImage(file)) {
        return IMAGE;
    }
    if (FileUtils.getFileExtension(file).equals("xml")) {
        File parentFile = file.getParentFile();
        if (parentFile != null) {
            if (StringUtils.equals(parentFile.getName(), "shared_prefs")) {
                return SP;
            }
        }
    }
    if (FileUtils.isUtf8(file)) {
        return UTF8;
    }
    return UNKNOWN;
}
 
Example #15
Source Project: Pixiv-Shaft   Author: CeuiLiSA   File: FileOperator.java    License: MIT License 5 votes vote down vote up
@Override
public void clearAll() {
    if (FileUtils.delete(PathUtils.getInternalAppCachePath())) {
        ToastUtils.showShort("清除成功!");
    } else {
        ToastUtils.showShort("清除失败!");
    }
}
 
Example #16
Source Project: DanDanPlayForAndroid   Author: xyoye   File: SubtitleRequester.java    License: MIT License 5 votes vote down vote up
public static void querySubtitle(String videoPath, CommOtherDataObserver<List<SubtitleBean>> subtitleObserver) {
    //只查找本地视频字幕
    String localPath = Environment.getExternalStorageDirectory().getAbsolutePath();
    if (!videoPath.startsWith(localPath))
        return;
    String thunderHash = HashUtils.getFileSHA1(videoPath);
    String shooterHash = HashUtils.getFileHash(videoPath);
    if (!StringUtils.isEmpty(thunderHash) && !StringUtils.isEmpty(shooterHash)) {
        Map<String, String> shooterParams = new HashMap<>();
        shooterParams.put("filehash", shooterHash);
        shooterParams.put("pathinfo", FileUtils.getFileName(videoPath));
        shooterParams.put("format", "json");
        shooterParams.put("lang", "Chn");
        SubtitleRetrofitService service = RetroFactory.getSubtitleInstance();

        Observable<List<SubtitleBean.Shooter>> shooterObservable = service.queryShooter(shooterParams)
                .onErrorReturnItem(new ArrayList<>());

        service.queryThunder(thunderHash)
                .onErrorReturnItem(new SubtitleBean.Thunder())
                .zipWith(shooterObservable, (thunder, shooters) ->
                        SubtitleConverter.transform(thunder, shooters, videoPath))
                .doOnSubscribe(new NetworkConsumer())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subtitleObserver);
    }
}
 
Example #17
Source Project: DanDanPlayForAndroid   Author: xyoye   File: ScanManagerPresenterImpl.java    License: MIT License 5 votes vote down vote up
@Override
public void saveNewVideo(List<String> pathList) {
    newAddCount = 0;
    IApplication.getSqlThreadPool().execute(() -> {
        for (String videoPath : pathList) {
            String folderPath = FileUtils.getDirName(videoPath);
            DataBaseManager.getInstance()
                    .selectTable("file")
                    .query()
                    .where("folder_path", folderPath)
                    .where("file_path", videoPath)
                    .executeAsync(cursor -> {
                        if (!cursor.moveToNext()) {
                            VideoBean videoBean = queryFormSystem(videoPath);
                            DataBaseManager.getInstance()
                                    .selectTable("file")
                                    .insert()
                                    .param("folder_path", folderPath)
                                    .param("file_path", videoBean.getVideoPath())
                                    .param("duration", String.valueOf(videoBean.getVideoDuration()))
                                    .param("file_size", String.valueOf(videoBean.getVideoSize()))
                                    .param("file_id", videoBean.get_id())
                                    .executeAsync();
                            EventBus.getDefault().post(UpdateFragmentEvent.updatePlay(PlayFragment.UPDATE_DATABASE_DATA));
                            newAddCount++;
                        }
                    });
        }
        ToastUtils.showShort("扫描完成,新增:" + newAddCount);
    });
}
 
Example #18
Source Project: DanDanPlayForAndroid   Author: xyoye   File: FolderPresenterImpl.java    License: 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 #19
Source Project: DanDanPlayForAndroid   Author: xyoye   File: FolderPresenterImpl.java    License: 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 #20
Source Project: DanDanPlayForAndroid   Author: xyoye   File: PlayFragmentPresenterImpl.java    License: MIT License 5 votes vote down vote up
/**
 * 保存视频信息到数据库
 * 跳过已存在的视频信息
 */
private void saveVideoToDatabase(VideoBean videoBean) {
    String folderPath = FileUtils.getDirName(videoBean.getVideoPath());
    ContentValues values = new ContentValues();
    values.put(DataBaseInfo.getFieldNames()[2][1], folderPath);
    values.put(DataBaseInfo.getFieldNames()[2][2], videoBean.getVideoPath());
    values.put(DataBaseInfo.getFieldNames()[2][5], String.valueOf(videoBean.getVideoDuration()));
    values.put(DataBaseInfo.getFieldNames()[2][7], String.valueOf(videoBean.getVideoSize()));
    values.put(DataBaseInfo.getFieldNames()[2][8], videoBean.get_id());

    DataBaseManager.getInstance()
            .selectTable("file")
            .query()
            .where("folder_path", folderPath)
            .where("file_path", videoBean.getVideoPath())
            .executeAsync(cursor -> {
                if (!cursor.moveToNext()) {
                    DataBaseManager.getInstance()
                            .selectTable("file")
                            .insert()
                            .param("folder_path", folderPath)
                            .param("file_path", videoBean.getVideoPath())
                            .param("duration", String.valueOf(videoBean.getVideoDuration()))
                            .param("file_size", String.valueOf(videoBean.getVideoSize()))
                            .param("file_id", videoBean.get_id())
                            .executeAsync();
                }
            });
}
 
Example #21
Source Project: DanDanPlayForAndroid   Author: xyoye   File: BindDanmuPresenterImpl.java    License: 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 #22
Source Project: DanDanPlayForAndroid   Author: xyoye   File: ShooterSubDetailDialog.java    License: MIT License 5 votes vote down vote up
@SuppressLint("SetTextI18n")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dialog_shooter_subtitle_detail);
    ButterKnife.bind(this);

    String fileName = detailBean.getFilename() == null ? "" : detailBean.getFilename();
    String fileExtension = FileUtils.getFileExtension(fileName).toLowerCase();

    //不是可解压的文件
    if (SevenZipUtils.getArchiveFormat(fileExtension) == null){
        downloadUnzipTv.setVisibility(View.GONE);
        downloadTv.setBackground(CommonUtils.getResDrawable(R.drawable.background_dialog_button_positive));
    }

    subtitleFileNameEt.setText(fileName);
    subtitleFileNameEt.setSelection(fileName.length());
    subtitleFileSizeTv.setText(CommonUtils.convertFileSize(detailBean.getSize()));
    subtitleLanguageTv.setText(detailBean.getLang() == null ? "无" : detailBean.getLang().getDesc());

    if (detailBean.getProducer() == null || TextUtils.isEmpty(detailBean.getProducer().getSource())) {
        subtitleSourceTv.setVisibility(View.GONE);
    } else {
        subtitleSourceTv.setVisibility(View.VISIBLE);
        subtitleSourceTv.setText("制作: " + detailBean.getProducer().getProducer());
    }
}
 
Example #23
Source Project: DanDanPlayForAndroid   Author: xyoye   File: FolderItem.java    License: MIT License 5 votes vote down vote up
@Override
public void onUpdateViews(FolderBean model, int position) {
    String folder = model.getFolderPath();
    String title = CommonUtils.getFolderName(folder);

    folderTitle.setText(title);
    fileNumber.setText(String.format("%s 视频", model.getFileNumber()));

    //是否为上次播放的文件夹
    boolean isLastPlayFolder = false;
    String lastVideoPath = AppConfig.getInstance().getLastPlayVideo();
    if (!StringUtils.isEmpty(lastVideoPath)) {
        String folderPath = FileUtils.getDirName(lastVideoPath);
        isLastPlayFolder = folderPath.equals(model.getFolderPath());
    }

    folderTitle.setTextColor(isLastPlayFolder
            ? CommonUtils.getResColor(R.color.immutable_text_theme)
            : CommonUtils.getResColor(R.color.text_black));

    fileNumber.setTextColor(isLastPlayFolder
            ? CommonUtils.getResColor(R.color.immutable_text_theme)
            : CommonUtils.getResColor(R.color.text_gray));

    contentLayout.setOnClickListener(v -> listener.onClick(model.getFolderPath()));

    shieldFolderTv.setOnClickListener(v -> listener.onShield(model.getFolderPath(), title));
    deleteFolderTv.setOnClickListener(v -> listener.onDelete(model.getFolderPath(), title));
}
 
Example #24
Source Project: DanDanPlayForAndroid   Author: xyoye   File: SmbFileActivity.java    License: MIT License 5 votes vote down vote up
@Override
public void launchPlayerActivity(String videoUrl, String zimu) {
    PlayerManagerActivity.launchPlayerSmb(
            SmbFileActivity.this,
            FileUtils.getFileNameNoExtension(videoUrl),
            videoUrl,
            zimu
    );
}
 
Example #25
Source Project: DanDanPlayForAndroid   Author: xyoye   File: FolderActivity.java    License: MIT License 5 votes vote down vote up
@SuppressLint("CheckResult")
@Override
public void downloadDanmu(DanmuMatchBean.MatchesBean matchesBean) {
    new DanmuDownloadDialog(this, selectVideoBean.getVideoPath(), matchesBean, (danmuPath, episodeId) -> {
        selectVideoBean.setDanmuPath(danmuPath);
        selectVideoBean.setEpisodeId(episodeId);

        String folderPath = FileUtils.getDirName(selectVideoBean.getVideoPath());
        presenter.updateDanmu(danmuPath, episodeId, new String[]{folderPath, selectVideoBean.getVideoPath()});
        adapter.notifyItemChanged(selectPosition);

        openIntentVideo(selectVideoBean);
    }).show();
}
 
Example #26
Source Project: DanDanPlayForAndroid   Author: xyoye   File: FolderActivity.java    License: MIT License 5 votes vote down vote up
@Override
public void openIntentVideo(VideoBean videoBean) {
    boolean isExoPlayer = AppConfig.getInstance().getPlayerType() == com.xyoye.player.commom.utils.Constants.EXO_PLAYER;
    if (!isExoPlayer && FileUtils.getFileExtension(videoBean.getVideoPath()).toLowerCase().equals(".MKV") && AppConfig.getInstance().isShowMkvTips()) {
        new CommonDialog.Builder(this)
                .setAutoDismiss()
                .setOkListener(dialog -> launchPlay(videoBean))
                .setCancelListener(dialog -> launchActivity(PlayerSettingActivity.class))
                .setDismissListener(dialog -> AppConfig.getInstance().hideMkvTips())
                .build()
                .show(getResources().getString(R.string.mkv_tips), "关于MKV格式", "我知道了", "前往设置");
    } else {
        launchPlay(videoBean);
    }
}
 
Example #27
Source Project: DanDanPlayForAndroid   Author: xyoye   File: FolderActivity.java    License: MIT License 5 votes vote down vote up
/**
 * 启动播放器
 *
 * @param videoBean 数据
 */
private void launchPlay(VideoBean videoBean) {
    //记录此次播放
    AppConfig.getInstance().setLastPlayVideo(videoBean.getVideoPath());
    EventBus.getDefault().post(UpdateFragmentEvent.updatePlay(PlayFragment.UPDATE_ADAPTER_DATA));

    PlayerManagerActivity.launchPlayerLocal(
            this,
            FileUtils.getFileNameNoExtension(videoBean.getVideoPath()),
            videoBean.getVideoPath(),
            videoBean.getDanmuPath(),
            videoBean.getZimuPath(),
            videoBean.getCurrentPosition(),
            videoBean.getEpisodeId());
}
 
Example #28
Source Project: DanDanPlayForAndroid   Author: xyoye   File: IjkPlayerView.java    License: MIT License 5 votes vote down vote up
/**
 * 设置弹幕资源
 */
public IjkPlayerView setDanmakuSource(String danmuPath) {
    if (TextUtils.isEmpty(danmuPath) || !FileUtils.isFileExists(danmuPath)) {
        return this;
    }
    try {
        mDanmakuLoader.load(danmuPath);
        IDataSource<?> dataSource = mDanmakuLoader.getDataSource();
        mDanmakuParser.load(dataSource);
    } catch (IllegalDataException e) {
        e.printStackTrace();
        ToastUtils.showShort("弹幕加载失败");
    }
    return this;
}
 
Example #29
Source Project: DanDanPlayForAndroid   Author: xyoye   File: ExoPlayerView.java    License: MIT License 5 votes vote down vote up
/**
 * 设置弹幕资源
 */
public ExoPlayerView setDanmakuSource(String danmuPath) {
    if (TextUtils.isEmpty(danmuPath) || !FileUtils.isFileExists(danmuPath)) {
        return this;
    }
    try {
        mDanmakuLoader.load(danmuPath);
        IDataSource<?> dataSource = mDanmakuLoader.getDataSource();
        mDanmakuParser.load(dataSource);
    } catch (IllegalDataException e) {
        e.printStackTrace();
        ToastUtils.showShort("弹幕加载失败");
    }
    return this;
}
 
Example #30
Source Project: Android-UtilCode   Author: hoangkien0705   File: UtilsApp.java    License: Apache License 2.0 5 votes vote down vote up
private void initAssets() {
    if (!FileUtils.isFileExists(Config.getTestApkPath())) {
        try {
            FileIOUtils.writeFileFromIS(Config.getTestApkPath(), getAssets().open("test_install.apk"), false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}