Exemplo n.º 1
0
  /** 插入影片下载数据 */
  public synchronized long insertMovieStore(DownLoadInfo downLoadInfo) {
    if (isStoreByUrl(downLoadInfo.getDownUrl())) return PipiPlayerConstant.ISEXIT_NORMOL;
    long sec = -1;
    try {
      ContentValues values = new ContentValues();
      values.put(TableName.MovieID, downLoadInfo.getDownID());
      values.put(TableName.MovieName, downLoadInfo.getDownName());
      values.put(TableName.MovieImgUrl, downLoadInfo.getDownImg());
      values.put(TableName.MovieUrl, downLoadInfo.getDownUrl());
      values.put(TableName.MoviePlaySourKey, downLoadInfo.getDownTag());

      ArrayList<String> list = downLoadInfo.getPlayList();
      JSONArray array = new JSONArray();
      for (String string : list) array.put(string);

      values.put(TableName.MoviePlayList, array.toString());
      values.put(TableName.MoviePlayPosition, downLoadInfo.getDownPosition());
      Log.i("TAG999", "insertMovieStore MoviePlayPosition===" + downLoadInfo.getDownPosition());
      database = pipiDBHelp.getWritableDatabase();
      sec = database.insert(PipiDBHelp.STORE_TABLENAME, null, values);
    } catch (Exception e) {
      // TODO: handle exception
    }
    return sec;
  }
Exemplo n.º 2
0
 public void addJob(DownLoadInfo downInfo) {
   for (DownTask downTask : mDownTaskList)
     if (downTask.getMovieUrl().equals(downInfo.getDownUrl())) return;
   DownTask downTask = new DownTask(downInfo);
   mDownTaskList.add(downTask);
   startDown(downTask);
 }
Exemplo n.º 3
0
  public synchronized void getDownInfo(DownLoadInfo downInfo) {
    try {
      String mediainfo = GetCurDownloadInfo(downInfo.getDownUrl());
      // int outspeed;
      // float outPercent;
      // long  outFileSize;
      String tmp[] = mediainfo.split("&");
      String speed = tmp[0];
      String percent = tmp[1];

      downInfo.setDownSpeed(Integer.parseInt(speed));
      downInfo.setDownProgress((int) Float.parseFloat(percent));

    } catch (Exception e) {
      // TODO: handle exception
      e.printStackTrace();
    }
  }
Exemplo n.º 4
0
 // 文件合并
 @SuppressWarnings("resource")
 public synchronized boolean GetFileMerge(final DownLoadInfo downInfo) {
   String parent = HtmlUtils.getFileDir(downInfo);
   final List<String> list = new ArrayList<String>();
   File file = new File(parent);
   if (!file.exists()) return true;
   // 检索要合并的文件名,不合格的剔除
   File[] childFiles =
       file.listFiles(
           new FileFilter() {
             public boolean accept(File pathname) {
               return pathname.getName().startsWith(downInfo.getDownName())
                   && !pathname.getName().endsWith(".ts");
             }
           });
   if (childFiles != null) {
     // 文件片段多于一个才需要合并
     String filePath = null;
     for (File file1 : childFiles) {
       filePath = file1.getAbsolutePath();
       list.add(filePath);
     }
     if (list.size() == 1) {
       DBHelperDao.getDBHelperDaoInstace().updataMovieStoreLocal(downInfo.getDownUrl(), filePath);
     } else {
       DBHelperDao.getDBHelperDaoInstace()
           .updataMovieStoreState(downInfo.getDownUrl(), DownTask.TASK_FileMerge);
       downInfo.setDownState(DownTask.TASK_FileMerge);
       String mp4filepath = null;
       if (filePath.endsWith(".flv")) {
         mp4filepath =
             parent
                 + "/"
                 + downInfo.getDownName()
                 + String.format("%03d", downInfo.getDownPosition())
                 + ".flv";
       } else {
         mp4filepath =
             parent
                 + "/"
                 + downInfo.getDownName()
                 + String.format("%03d", downInfo.getDownPosition())
                 + ".mp4";
       }
       final String[] filearray = list.toArray(new String[list.size()]);
       Arrays.sort(filearray); // 排序
       try {
         mlibvlc.nativeFileMerge(mp4filepath, filearray, false);
         // GetFileMergeStart(list, mp4filepath);
         // 合并完文件在更新数据库信息
         FileInputStream stream = new FileInputStream(mp4filepath);
         if (stream != null) {
           long size = stream.available();
           downInfo.setDownTotalSize(size);
           downInfo.setDownLocal(downInfo.getDownUrl());
           DBHelperDao.getDBHelperDaoInstace().updataMovieStoreSize(downInfo.getDownUrl(), size);
           DBHelperDao.getDBHelperDaoInstace()
               .updataMovieStoreLocal(downInfo.getDownUrl(), mp4filepath);
           downInfo.setDownState(DownTask.TASK_FINISHED);
           DBHelperDao.getDBHelperDaoInstace()
               .updataMovieStoreState(downInfo.getDownUrl(), DownTask.TASK_FINISHED);
           // 合并完成 删除源文件
           new Thread(
                   new Runnable() {
                     @Override
                     public void run() {
                       // TODO Auto-generated method stub
                       for (String fileName : list) {
                         FileUtils.deleteFile(fileName);
                       }
                     }
                   })
               .start();
         }
       } catch (Exception e) {
         // TODO: handle exception
         e.printStackTrace();
         return false;
       }
     }
   }
   return true;
 }