com.xunlei.downloadlib.XLTaskHelper Java Examples

The following examples show how to use com.xunlei.downloadlib.XLTaskHelper. 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: DownloadTask.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
public void setUrl(String url) {
    //删除旧任务及文件
    this.stopTask();

    this.url = url;
    this.playList.clear();
    this.mIsLiveMedia = FileUtils.isLiveMedia(this.url);
    this.isNetworkDownloadTask = !this.mIsLiveMedia && FileUtils.isNetworkDownloadTask(this.url);
    this.name = this.mIsLiveMedia ? FileUtils.getWebMediaFileName(this.url) :
                 this.isNetworkDownloadTask ? XLTaskHelper.instance().getFileName(this.url) : FileUtils.getFileName(this.url);
    this.localSavePath = (new File(getBaseDir(), FileUtils.getFileNameWithoutExt(this.name)).toString()) + "/";
    this.isLocalMedia = !this.mIsLiveMedia && !this.isNetworkDownloadTask && FileUtils.isMediaFile(this.name);
    this.torrentInfo = null;
    this.torrentMediaIndexs = null;
    this.torrentUnmediaIndexs = null;
    this.currentPlayMediaIndex = 0;
    if(this.isLocalMedia){
        playList.add(new PlayListItem(this.name, 0, new File(this.getUrl()).length()));
    }else if(this.mIsLiveMedia || this.isNetworkDownloadTask){
        playList.add(new PlayListItem(this.name, 0, 0L));
    } else if (".torrent".equals(FileUtils.getFileExt(this.name))) {
        this.torrentInfo = XLTaskHelper.instance().getTorrentInfo(this.url);
        this.initTorrentIndexs();
    }
}
 
Example #2
Source File: MainActivity.java    From MiniThunder with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    XLTaskHelper.init(getApplicationContext());
    inputUrl = (EditText) findViewById(R.id.input_url);
    btnDownload = (Button) findViewById(R.id.btn_down);
    tvStatus = (TextView) findViewById(R.id.tv_status);
    btnDownload.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(!TextUtils.isEmpty(inputUrl.getText())) {
                long taskId = XLTaskHelper.instance().addThunderTask(inputUrl.getText().toString(),"/sdcard/",null);
                handler.sendMessage(handler.obtainMessage(0,taskId));
            }
        }
    });
}
 
Example #3
Source File: MainActivity.java    From MiniThunder with Apache License 2.0 6 votes vote down vote up
@Override
public void handleMessage(Message msg) {
    super.handleMessage(msg);
    if(msg.what == 0) {
        long taskId = (long) msg.obj;
        XLTaskInfo taskInfo = XLTaskHelper.instance().getTaskInfo(taskId);
        tvStatus.setText(
                "fileSize:" + taskInfo.mFileSize
                        + " downSize:" + taskInfo.mDownloadSize
                        + " speed:" + convertFileSize(taskInfo.mDownloadSpeed)
                        + "/s dcdnSoeed:" + convertFileSize(taskInfo.mAdditionalResDCDNSpeed)
                        + "/s filePath:" + "/sdcard/" + XLTaskHelper.instance().getFileName(inputUrl.getText().toString())
        );
        handler.sendMessageDelayed(handler.obtainMessage(0,taskId),1000);
    }
}
 
Example #4
Source File: DownLoadModelImp.java    From AndroidDownload with Apache License 2.0 6 votes vote down vote up
@Override
public List<TorrentInfoEntity> getTorrentInfo(String btpath) {
    TorrentInfo torrentInfo= XLTaskHelper.instance(x.app().getApplicationContext()).getTorrentInfo(btpath);
    List<TorrentInfoEntity> list=new ArrayList<>();
    for(TorrentFileInfo torrent:torrentInfo.mSubFileInfo){
        TorrentInfoEntity tie=new TorrentInfoEntity();
        tie.setHash(torrent.hash);
        tie.setmFileIndex(torrent.mFileIndex);
        tie.setmFileName(torrent.mFileName);
        tie.setmFileSize(torrent.mFileSize);
        tie.setmSubPath(torrent.mSubPath);
        tie.setmRealIndex(torrent.mRealIndex);
        tie.setPath(AppSettingUtil.getInstance().getFileSavePath()+
                File.separator+torrentInfo.mMultiFileBaseFolder+
                File.separator+torrent.mSubPath+File.separator+torrent.mFileName);
        list.add(tie);
    }
    return list;
}
 
Example #5
Source File: DownLoadModelImp.java    From AndroidDownload with Apache License 2.0 6 votes vote down vote up
@Override
public Boolean startUrlTask(String url) {
    DownloadTaskEntity task=new DownloadTaskEntity();
    task.setTaskType(Const.URL_DOWNLOAD);
    task.setUrl(url);
    task.setLocalPath(AppSettingUtil.getInstance().getFileSavePath());
    try {
        long taskId = XLTaskHelper.instance(x.app().getApplicationContext()).addThunderTask(url,AppSettingUtil.getInstance().getFileSavePath(),null);
        XLTaskInfo taskInfo = XLTaskHelper.instance(x.app().getApplicationContext()).getTaskInfo(taskId);
        task.setmFileName(XLTaskHelper.instance(x.app().getApplicationContext()).getFileName(url));
        task.setmFileSize(taskInfo.mFileSize);
        task.setmTaskStatus(taskInfo.mTaskStatus);
        task.setTaskId(taskId);
        task.setmDCDNSpeed(taskInfo.mAdditionalResDCDNSpeed);
        task.setmDownloadSize(taskInfo.mDownloadSize);
        task.setmDownloadSpeed(taskInfo.mDownloadSpeed);
        task.setFile(true);
        task.setCreateDate(new Date());
        DBTools.getInstance().db().saveBindingId(task);
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
 
Example #6
Source File: TorrentInfoPresenterImp.java    From AndroidDownload with Apache License 2.0 6 votes vote down vote up
@Override
public void startTask(List<TorrentInfoEntity> checkList) {
    //String path=task.getLocalPath()+ File.separator+task.getmFileName();
    TorrentInfo torrentInfo= XLTaskHelper.instance(x.app().getApplicationContext()).getTorrentInfo(torrentPath);
    List<DownloadTaskEntity> tasks=taskModel.findTaskByHash(torrentInfo.mInfoHash);
    if(tasks!=null && tasks.size()>0){
        DownloadTaskEntity task=tasks.get(0);
        if(!FileTools.exists(task.getLocalPath()+ File.separator+task.getmFileName())) {
            downLoadModel.startTorrentTask(task);
            torrentInfoView.startTaskSuccess();
        }else if(task.getmTaskStatus()== Const.DOWNLOAD_CONNECTION
                || task.getmTaskStatus()== Const.DOWNLOAD_LOADING
                || task.getmTaskStatus()== Const.DOWNLOAD_FAIL
                || task.getmTaskStatus()== Const.DOWNLOAD_STOP
                || task.getmTaskStatus()== Const.DOWNLOAD_WAIT){
            torrentInfoView.startTaskFail(x.app().getString(R.string.task_earlier_has));
        }else if(task.getmTaskStatus()== Const.DOWNLOAD_SUCCESS){
            torrentInfoView.startTaskFail(x.app().getString(R.string.task_earlier_success));
        }
    }else{
        downLoadModel.startTorrentTask(torrentPath);
        torrentInfoView.startTaskSuccess();
    }
}
 
Example #7
Source File: DownloadTask.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
public String getPlayUrl(){
    if(this.isLocalMedia || this.mIsLiveMedia){
        return this.getUrl();
    }else if(this.taskId != 0L){
        if(this.isNetworkDownloadTask){
            return XLTaskHelper.instance().getLoclUrl(this.localSavePath + this.name);
        }else if(this.torrentInfo != null && this.currentPlayMediaIndex != -1){
            for(PlayListItem item : getPlayList()){
                if(item.getIndex() == this.currentPlayMediaIndex){
                    return XLTaskHelper.instance().getLoclUrl(this.localSavePath + item.getName());
                }
            }
        }
    }
    return null;
}
 
Example #8
Source File: DownLoadUtil.java    From BtPlayer with Apache License 2.0 5 votes vote down vote up
public void startDownLoad(String url) throws Exception {
    savePath = StorageUtils.getDefaultSavePath(globalContext);
    String fileName = null;
    if (UrlType.isTorrentUrl(url)) {
        TorrentInfo info = getTorrentInfo(url);
        savePath += "/" + info.mMultiFileBaseFolder;
        File f = new File(savePath);
        f.mkdirs();
        fileName = null;
    } else {
        fileName = getFileName(url);
    }

    preFile = savePath + (fileName == null ? "" : "/" + fileName);
    LogPrinter.i(TAG, "start download url : " + url + ", save path : " + savePath);

    if (UrlType.isThunderUrl(url) || UrlType.isHttpOrHttpsUrl(url) || UrlType.isFTPUrl(url)) {
        taskID = XLTaskHelper.instance(globalContext)
                .addThunderTask(url, savePath, fileName);
    } else if (UrlType.isMagnetUrl(url)) {
        taskID = XLTaskHelper.instance(globalContext)
                .addMagentTask(url, savePath, fileName);
    } else if (StorageUtils.isTorrentFile(url)) {
        taskID = XLTaskHelper.instance(globalContext)
                .addTorrentTask(url, savePath, null);
    }

    LogPrinter.i(TAG, "download url taskID : " + taskID);
    updateProgress();
}
 
Example #9
Source File: DownLoadUtil.java    From BtPlayer with Apache License 2.0 5 votes vote down vote up
public void getTaskInfo(String url) {
    XLTaskHelper xlTaskHelper = XLTaskHelper.instance(globalContext);

    if (UrlType.isTorrentUrl(url)) {
        TorrentInfo torrentInfo = xlTaskHelper.getTorrentInfo(url);
        LogPrinter.i(TAG, torrentInfo.toString());
    } else {
        String fileName = xlTaskHelper.getFileName(url);
        if (fileName.endsWith(".torrent"))
            dstFileIsTorrentFileTask = true;
        LogPrinter.i(TAG, fileName);
    }
}
 
Example #10
Source File: App.java    From AndroidDownload with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    x.Ext.init(this);
    //x.Ext.setDebug(BuildConfig.DEBUG);
    XLTaskHelper.init(getApplicationContext());
    instance = this;
}
 
Example #11
Source File: UrlDownLoadActivity.java    From AndroidDownload with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.setTopBarTitle(R.string.new_download);
    XLTaskHelper.init(getApplicationContext());
    urlDownLoadPresenter=new UrlDownLoadPresenterImp(this);
}
 
Example #12
Source File: DownLoadUtil.java    From BtPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMessage(Message msg) {
    switch (msg.what) {

        case TASK_UPDATE_PROGRESS: {
            if (progressListener != null) {
                XLTaskInfo taskInfo = XLTaskHelper.instance(globalContext).getTaskInfo(taskID);
                if (taskInfo.mFileSize == taskInfo.mDownloadSize) {
                    if (TextUtils.isEmpty(taskInfo.mFileName)) {
                        progressListener.onDonwloadEnd(preFile);
                    } else {
                        progressListener.onDonwloadEnd(savePath + "/" + taskInfo.mFileName);
                    }
                    return;
                }

                progressListener.onProgressChangeRealSize(taskInfo.mFileSize,
                        taskInfo.mDownloadSize, taskInfo.mDownloadSpeed);

                progressListener.onProgressChange(StorageUtils.convertFileSize(taskInfo.mFileSize)
                        , StorageUtils.convertFileSize(taskInfo.mDownloadSize)
                        , StorageUtils.convertFileSize(taskInfo.mDownloadSpeed));
                progressHandler.sendEmptyMessageDelayed(TASK_UPDATE_PROGRESS, 1000);
            }
            break;
        }


    }
}
 
Example #13
Source File: DownloadTask.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public void stopTask(){
    if(this.taskId != 0L){
        if(!this.isLocalMedia && !this.mIsLiveMedia) {
            XLTaskHelper.instance().deleteTask(this.taskId, this.localSavePath);
        }
        Log.d(TAG, "stopTask(" + this.url + "), taskId = " + taskId);
        this.taskId = 0L;
    }
}
 
Example #14
Source File: DownLoadModelImp.java    From AndroidDownload with Apache License 2.0 5 votes vote down vote up
@Override
public Boolean deleTask(DownloadTaskEntity task, Boolean stopTask, Boolean deleFile) {
    if(stopTask){
        XLTaskHelper.instance(x.app().getApplicationContext()).stopTask(task.getTaskId());
    }
    return deleTask(task,deleFile);
}
 
Example #15
Source File: DownLoadModelImp.java    From AndroidDownload with Apache License 2.0 5 votes vote down vote up
@Override
public Boolean startTask(DownloadTaskEntity task) {
    try {
        long taskId=0;
        if(task.getTaskType()==Const.BT_DOWNLOAD){
            TorrentInfo torrentInfo= XLTaskHelper.instance(x.app().getApplicationContext()).getTorrentInfo(task.getUrl());
            int i=0;
            int[] indexs=new int[torrentInfo.mSubFileInfo.length];
            for(TorrentFileInfo torrent:torrentInfo.mSubFileInfo) {
                indexs[i++]=torrent.mFileIndex;
            }
            taskId = XLTaskHelper.instance(x.app().getApplicationContext()).addTorrentTask(task.getUrl(), task.getLocalPath(),indexs);
        }else if(task.getTaskType()==Const.URL_DOWNLOAD){
            taskId = XLTaskHelper.instance(x.app().getApplicationContext()).addThunderTask(task.getUrl(), task.getLocalPath(), null);
        }
        XLTaskInfo taskInfo = XLTaskHelper.instance(x.app().getApplicationContext()).getTaskInfo(taskId);
        task.setmFileSize(taskInfo.mFileSize);
        task.setTaskId(taskId);
        task.setmTaskStatus(taskInfo.mTaskStatus);
        DBTools.getInstance().db().saveOrUpdate(task);
        if(taskInfo.mTaskId==0)
            return false;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
 
Example #16
Source File: DownLoadModelImp.java    From AndroidDownload with Apache License 2.0 5 votes vote down vote up
@Override
public Boolean stopTask(DownloadTaskEntity task) {
    try {
        XLTaskHelper.instance(x.app().getApplicationContext()).stopTask(task.getTaskId());
        task.setmTaskStatus(Const.DOWNLOAD_STOP);
        task.setmDownloadSpeed(0);
        task.setmDCDNSpeed(0);
        DBTools.getInstance().db().saveOrUpdate(task);
    } catch (DbException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
 
Example #17
Source File: DownloadManager.java    From TVRemoteIME with GNU General Public License v2.0 4 votes vote down vote up
public void init(Context context){
    if(this.context == null) {
        XLTaskHelper.init(context);
    }
    this.context = context;
}
 
Example #18
Source File: DownLoadUtil.java    From BtPlayer with Apache License 2.0 4 votes vote down vote up
private void init() {
    LogPrinter.i(TAG, "init");
    XLTaskHelper.init(globalContext);
}
 
Example #19
Source File: DownLoadModelImp.java    From AndroidDownload with Apache License 2.0 4 votes vote down vote up
@Override
public Boolean startTorrentTask(String btpath, int[] indexs) {
    DownloadTaskEntity task=new DownloadTaskEntity();
    TorrentInfo torrentInfo= XLTaskHelper.instance(x.app().getApplicationContext()).getTorrentInfo(btpath);
    if(indexs==null || indexs.length<=0) {
        int i = 0;
        indexs = new int[torrentInfo.mSubFileInfo.length];
        for (TorrentFileInfo torrent : torrentInfo.mSubFileInfo) {
            indexs[i++] = torrent.mFileIndex;
        }
    }
    String savePath= AppSettingUtil.getInstance().getFileSavePath();
    if(torrentInfo.mIsMultiFiles) {
        savePath += File.separator + torrentInfo.mMultiFileBaseFolder;
        task.setmFileName(torrentInfo.mMultiFileBaseFolder);
    }else{
        if(torrentInfo.mSubFileInfo.length>1) {
            savePath += File.separator + FileTools.getFileNameWithoutSuffix(btpath);
            task.setmFileName(FileTools.getFileNameWithoutSuffix(btpath));
        }else{
            task.setmFileName(torrentInfo.mSubFileInfo[0].mFileName);
        }
    }
    long taskId= 0;
    try {
        taskId = XLTaskHelper.instance(x.app().getApplicationContext()).addTorrentTask(btpath, savePath,indexs);
        XLTaskInfo taskInfo = XLTaskHelper.instance(x.app().getApplicationContext()).getTaskInfo(taskId);
        task.setLocalPath(savePath);
        task.setFile(!torrentInfo.mIsMultiFiles);
        task.setHash(torrentInfo.mInfoHash);
        task.setUrl(btpath);
        task.setmFileSize(taskInfo.mFileSize);
        task.setmTaskStatus(taskInfo.mTaskStatus);
        task.setTaskId(taskId);
        task.setmDCDNSpeed(taskInfo.mAdditionalResDCDNSpeed);
        task.setmDownloadSize(taskInfo.mDownloadSize);
        task.setmDownloadSpeed(taskInfo.mDownloadSpeed);
        task.setTaskType(Const.BT_DOWNLOAD);
        task.setCreateDate(new Date());
        DBTools.getInstance().db().saveBindingId(task);
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
 
Example #20
Source File: DownloadTask.java    From TVRemoteIME with GNU General Public License v2.0 4 votes vote down vote up
public XLTaskInfo getTaskInfo(){
    return this.taskId == 0L || this.isLocalMedia || this.mIsLiveMedia ? null : XLTaskHelper.instance().getTaskInfo(this.taskId);
}
 
Example #21
Source File: IApplication.java    From DanDanPlayForAndroid with MIT License 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@Override
public void onCreate() {
    super.onCreate();
    _context = this.getApplicationContext();
    _asset = _context.getAssets();

    //AndroidUtilsCode
    Utils.init(this);

    //skins
    SkinCompatManager.withoutActivity(this)                         // 基础控件换肤初始化
            .addInflater(new SkinMaterialViewInflater())            // material design 控件换肤初始化[可选]
            .addInflater(new SkinConstraintViewInflater())          // ConstraintLayout 控件换肤初始化[可选]
            .addInflater(new SkinCardViewInflater())                // CardView v7 控件换肤初始化[可选]
            .addInflater(new SkinFlycoTabLayoutInflater())
            .setSkinStatusBarColorEnable(true)                      // 关闭状态栏换肤,默认打开[可选]
            .setSkinWindowBackgroundEnable(true)                    // 关闭windowBackground换肤,默认打开[可选]
            .setSkinAllActivityEnable(true)
            .loadSkin();

    //Crash
    CaocConfig.Builder.create()
            .backgroundMode(CaocConfig.BACKGROUND_MODE_SHOW_CUSTOM)
            .enabled(true)
            .trackActivities(true)
            .minTimeBetweenCrashesMs(2000)
            .restartActivity(SplashActivity.class)
            .errorActivity(CrashActivity.class)
            .apply();

    //Bugly
    Bugly.init(getApplicationContext(), SoUtils.getInstance().getBuglyAppId(), false);

    //Sophix
    SophixManager.getInstance().setPatchLoadStatusStub(CommonUtils.getPatchLoadListener());

    //thunder
    XLTaskHelper.init(this);

    //数据库
    DataBaseManager.init(this);

    //播放器配置
    PlayerConfigShare.initPlayerConfigShare(this);

    //检查补丁
    if (AppConfig.getInstance().isAutoQueryPatch()){
        SophixManager.getInstance().queryAndLoadNewPatch();
    }

    startCorrectlyFlag = true;

    //严格模式
    //strictMode();
}
 
Example #22
Source File: DownLoadUtil.java    From BtPlayer with Apache License 2.0 4 votes vote down vote up
private String getFileName(String url) {
    XLTaskHelper xlTaskHelper = XLTaskHelper.instance(globalContext);
    return xlTaskHelper.getFileName(url);
}
 
Example #23
Source File: DownLoadUtil.java    From BtPlayer with Apache License 2.0 4 votes vote down vote up
private TorrentInfo getTorrentInfo(String url) {
    XLTaskHelper xlTaskHelper = XLTaskHelper.instance(globalContext);
    TorrentInfo torrentInfo = xlTaskHelper.getTorrentInfo(url);
    return torrentInfo;
}
 
Example #24
Source File: DownLoadUtil.java    From BtPlayer with Apache License 2.0 4 votes vote down vote up
public void stopTask() {
    XLTaskInfo taskInfo = XLTaskHelper.instance(globalContext).getTaskInfo(taskID);
    int status = taskInfo.mTaskStatus;
    LogPrinter.i(TAG, "stopTask -- > taskStatus : " + status);
    XLTaskHelper.instance(globalContext).stopTask(taskID);
}