示例#1
0
  /** 得到影片收藏列表 */
  public synchronized List<DownLoadInfo> getSmovieSave() {

    List<DownLoadInfo> resultsInfos = new ArrayList<DownLoadInfo>();
    String sql =
        "select  *  from "
            + PipiDBHelp.SAVE_TABLENAME
            + " order by "
            + TableName.Movie_ID
            + " desc";
    try {
      database = pipiDBHelp.getWritableDatabase();
      cursor = database.rawQuery(sql, null);
      if (cursor != null && cursor.getCount() != 0) {
        while (cursor.moveToNext()) {
          DownLoadInfo info = new DownLoadInfo();
          info.setDownID(cursor.getString(cursor.getColumnIndex(TableName.MovieID)));
          info.setDownName(cursor.getString(cursor.getColumnIndex(TableName.MovieName)));
          info.setDownImg(cursor.getString(cursor.getColumnIndex(TableName.MovieImgUrl)));

          resultsInfos.add(info);
        }
      } else {

      }

    } catch (Exception e) {
      // TODO: handle exception
    } finally {
      closeCursor();
    }
    return resultsInfos;
  }
 public int getSeleteCount() { // 被选中即将删除的个数
   if (list == null || list.size() == 0) return 0;
   int num = 0;
   for (DownLoadInfo movieInfo : list) {
     if (movieInfo.isDelete()) num++;
   }
   return num;
 }
 public boolean changeDeleteVisible() {
   this.deleteVisible = !deleteVisible;
   if (!deleteVisible) { //// 重置多选框状态
     for (DownLoadInfo downInfo : list) {
       if (downInfo.isDelete()) downInfo.setDelete(false);
     }
   }
   notifyDataSetChanged();
   return deleteVisible;
 }
示例#4
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;
  }
 public boolean getNotSelete() { // 是否含有未被选中的
   boolean delete = false;
   if (list == null || list.size() == 0) return delete;
   for (DownLoadInfo downInfo : list) {
     if (!downInfo.isDelete()) {
       delete = true;
       break;
     }
   }
   return delete;
 }
 public void setDeleteAllList(Button deleteall) { // 将所有数据标记为可删除
   boolean delete = getNotSelete(); // 含有未被选中的则全选  如果已经被全选则全部取消
   if (delete) deleteall.setText(mContext.getString(R.string.notselectall));
   else deleteall.setText(mContext.getString(R.string.selectall));
   for (DownLoadInfo downInfo : list) downInfo.setDelete(delete);
   notifyDataSetChanged();
   Message message = new Message();
   message.what = DELETElAYOUT;
   message.obj = getSeleteCount();
   handler.sendMessage(message);
 }
 public void DeleteList() { // 删除数据
   if (list == null || list.size() == 0) return;
   for (int i = list.size() - 1; i > -1; i--) { // 倒序删除,避免循环错误
     DownLoadInfo movie = list.get(i);
     if (movie.isDelete()) {
       list.remove(movie);
       dao.delSingleSmovieSave(movie.getDownID());
     }
   }
   notifyDataSetChanged();
   setDeleteInVisible();
 }
示例#8
0
 /** 影片收藏 */
 public synchronized long insertMovieSave(DownLoadInfo info) {
   if (isMovieSaveByID(info.getDownID())) return PipiPlayerConstant.ISEXIT_NORMOL;
   long sec = -1;
   try {
     ContentValues values = new ContentValues();
     values.put(TableName.MovieID, info.getDownID());
     values.put(TableName.MovieName, info.getDownName());
     values.put(TableName.MovieImgUrl, info.getDownImg());
     database = pipiDBHelp.getWritableDatabase();
     sec = database.insert(PipiDBHelp.SAVE_TABLENAME, null, values);
   } catch (Exception e) {
     // TODO: handle exception
   }
   return sec;
 }
示例#9
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);
 }
示例#10
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();
    }
  }
示例#11
0
  public View getView(final int position, View convertView, ViewGroup vg) {
    // TODO Auto-generated method stub
    ViewHolder holder;

    if (convertView != null) {
      holder = (ViewHolder) convertView.getTag();
      holder.moive_img.setImageResource(R.drawable.item_moive_list); // 设置默认图片,避免�?成图片看起来混乱
    } else {
      holder = new ViewHolder();
      convertView = inflate.inflate(R.layout.item_play_history, null);
      holder.title = (TextView) convertView.findViewById(R.id.moive_title);
      holder.moive_img = (ImageView) convertView.findViewById(R.id.moive_img);
      holder.delete = (CheckBox) convertView.findViewById(R.id.delete);
      convertView.setTag(holder);
    }
    holder.moive_img.setImageResource(R.drawable.item_moive_list); // 设置默认图片,避免造成图片看起来混乱
    if (list == null || list.size() == 0 || position < 0 || position >= list.size())
      return convertView;
    final DownLoadInfo downInfo = list.get(position);
    holder.title.setText(downInfo.getDownName());

    bmpManager.loadBitmap(downInfo.getDownImg(), holder.moive_img);

    // 删除按钮
    if (!deleteVisible) holder.delete.setVisibility(8);
    else {
      holder.delete.setVisibility(0);
      holder.delete.setChecked(downInfo.isDelete()); //
      holder.delete.setOnClickListener(
          new OnClickListener() {
            public void onClick(View v) {
              // TODO Auto-generated method stub
              downInfo.setDelete(!downInfo.isDelete());

              Message message = new Message();
              message.what = DELETElAYOUT;
              message.obj = getSeleteCount();
              handler.sendMessage(message);
            }
          });
    }

    return convertView;
  }
示例#12
0
  /** 得到影片历史列表 */
  public synchronized List<DownLoadInfo> getSmovieHistroy() {

    List<DownLoadInfo> resultsInfos = new ArrayList<DownLoadInfo>();
    String sql =
        "select  *  from "
            + PipiDBHelp.HISTROY_TABLENAME
            + " order by "
            + TableName.Movie_ID
            + " desc";
    try {
      database = pipiDBHelp.getWritableDatabase();
      cursor = database.rawQuery(sql, null);
      if (cursor != null && cursor.getCount() != 0) {
        while (cursor.moveToNext()) {
          DownLoadInfo downInfo = new DownLoadInfo();
          downInfo.setDownID(cursor.getString(cursor.getColumnIndex("sMovieID")));
          downInfo.setDownName(cursor.getString(cursor.getColumnIndex("sMovieName")));
          downInfo.setDownImg(cursor.getString(cursor.getColumnIndex("sMovieImgUrl")));
          downInfo.setDownUrl(cursor.getString(cursor.getColumnIndex("sMovieUrl")));
          downInfo.setDownTotalSize(cursor.getInt(cursor.getColumnIndex("sMovieSize")));
          downInfo.setDownProgress(cursor.getInt(cursor.getColumnIndex("sMoviePlayProgress")));
          downInfo.setDownState(cursor.getInt(cursor.getColumnIndex("sMovieLoadState")));
          downInfo.setDownTag(cursor.getString(cursor.getColumnIndex(TableName.MoviePlaySourKey)));
          downInfo.setDownPath(cursor.getString(cursor.getColumnIndex("sMovieLocalUrl")));
          downInfo.setDownPosition(
              cursor.getInt(cursor.getColumnIndex(TableName.MoviePlayPosition)));
          resultsInfos.add(downInfo);
        }
      }

    } catch (Exception e) {
      // TODO: handle exception
    } finally {
      closeCursor();
    }
    return resultsInfos;
  }
示例#13
0
 /** sMovieUrl 插入影片历史数据 */
 public synchronized long insertMovieHistroy(DownLoadInfo downInfo) {
   long sec = -1;
   try {
     ContentValues values = new ContentValues();
     values.put(TableName.MovieID, downInfo.getDownID());
     values.put(TableName.MovieName, downInfo.getDownName());
     values.put(TableName.MovieImgUrl, downInfo.getDownImg());
     values.put(TableName.MovieUrl, StringUtils.getDate()); // MovieUrl 在此处替代插入时间
     values.put(TableName.MoviePlaySourKey, downInfo.getDownTag());
     values.put(TableName.MoviePlayProgress, downInfo.getDownProgress());
     values.put(TableName.MovieSize, downInfo.getDownTotalSize());
     values.put(TableName.MoviePlayPosition, downInfo.getDownPosition());
     values.put(TableName.MovieLocalUrl, downInfo.getDownPath());
     database = pipiDBHelp.getWritableDatabase();
     Log.i(
         "TAG999",
         "insertMovieHistroy  = "
             + downInfo.getDownPosition()
             + "*******"
             + downInfo.getDownProgress());
     if (isMovieHistroyByID(downInfo.getDownID())) { // 存在记录,删除记录
       //	sec = database.update(PipiDBHelp.HISTROY_TABLENAME, values, "sMovieID=?",
       //			new String[]{downInfo.getDownID()});
       sec =
           database.delete(
               PipiDBHelp.HISTROY_TABLENAME, "sMovieID=?", new String[] {downInfo.getDownID()});
     }
     sec = database.insert(PipiDBHelp.HISTROY_TABLENAME, null, values);
   } catch (Exception e) {
     // TODO: handle exception
   }
   return sec;
 }
示例#14
0
  /** 得到影片下载列表 */
  public synchronized List<DownLoadInfo> getSmovieStores() {

    List<DownLoadInfo> resultsInfos = new ArrayList<DownLoadInfo>();
    String sql =
        "select  *  from "
            + PipiDBHelp.STORE_TABLENAME
            + " order by "
            + TableName.Movie_ID
            + " desc ";
    try {
      database = pipiDBHelp.getWritableDatabase();
      cursor = database.rawQuery(sql, null);
      if (cursor != null && cursor.getCount() != 0) {
        while (cursor.moveToNext()) {
          DownLoadInfo downInfo = new DownLoadInfo();
          downInfo.setDownID(cursor.getString(cursor.getColumnIndex("sMovieID")));
          downInfo.setDownName(cursor.getString(cursor.getColumnIndex("sMovieName")));
          downInfo.setDownImg(cursor.getString(cursor.getColumnIndex("sMovieImgUrl")));
          downInfo.setDownUrl(cursor.getString(cursor.getColumnIndex("sMovieUrl")));
          downInfo.setDownTotalSize(cursor.getLong(cursor.getColumnIndex("sMovieSize")));
          downInfo.setDownProgress(cursor.getLong(cursor.getColumnIndex("sMoviePlayProgress")));
          downInfo.setDownState(cursor.getInt(cursor.getColumnIndex("sMovieLoadState")));
          downInfo.setDownPosition(
              cursor.getInt(cursor.getColumnIndex(TableName.MoviePlayPosition)));
          downInfo.setDownTag(cursor.getString(cursor.getColumnIndex(TableName.MoviePlaySourKey)));
          String path = cursor.getString(cursor.getColumnIndex("sMovieLocalUrl"));
          downInfo.setDownPath(path);
          JSONArray array;
          try {
            array = new JSONArray(cursor.getString(cursor.getColumnIndex("sMoviePlayList")));
            ArrayList<String> list = new ArrayList<String>();
            for (int i = 0; i < array.length(); i++) list.add(array.getString(i));

            downInfo.setPlayList(list);
          } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
          // 下载片段索引
          if (!TextUtils.isEmpty(path)) {
            try {
              File file = new File(path);
              if (file != null && file.isDirectory()) {
                downInfo.setDownIndex(
                    file.listFiles().length - 1 > 0 ? file.listFiles().length - 1 : 0);
              }
            } catch (Exception e) {
              // TODO: handle exception
            }
          }

          resultsInfos.add(downInfo);
        }
      }
    } catch (Exception e) {
      // TODO: handle exception
    } finally {
      closeCursor();
    }
    return resultsInfos;
  }
示例#15
0
  public synchronized List<DownTask> getActiveDownLoad() {
    List<DownTask> mDownLoadTaskList = new ArrayList<DownTask>();
    SQLiteDatabase database = null;
    Cursor cursor = null;
    String sql = "select  *  from " + PipiDBHelp.STORE_TABLENAME;

    try {
      database = pipiDBHelp.getReadableDatabase();
      cursor = database.rawQuery(sql, null);
      while (cursor.moveToNext()) {

        DownLoadInfo downInfo = new DownLoadInfo();
        downInfo.setDownID(cursor.getString(cursor.getColumnIndex("sMovieID")));
        downInfo.setDownName(cursor.getString(cursor.getColumnIndex("sMovieName")));
        downInfo.setDownImg(cursor.getString(cursor.getColumnIndex("sMovieImgUrl")));
        downInfo.setDownUrl(cursor.getString(cursor.getColumnIndex("sMovieUrl")));
        downInfo.setDownTotalSize(cursor.getLong(cursor.getColumnIndex("sMovieSize")));
        downInfo.setDownProgress(cursor.getLong(cursor.getColumnIndex("sMoviePlayProgress")));
        downInfo.setDownState(cursor.getInt(cursor.getColumnIndex("sMovieLoadState")));
        downInfo.setDownPosition(cursor.getInt(cursor.getColumnIndex(TableName.MoviePlayPosition)));
        downInfo.setDownTag(cursor.getString(cursor.getColumnIndex(TableName.MoviePlaySourKey)));
        String path = cursor.getString(cursor.getColumnIndex("sMovieLocalUrl"));
        downInfo.setDownPath(path);
        JSONArray array;
        try {
          array = new JSONArray(cursor.getString(cursor.getColumnIndex("sMoviePlayList")));
          ArrayList<String> list = new ArrayList<String>();
          for (int i = 0; i < array.length(); i++) list.add(array.getString(i));

          downInfo.setPlayList(list);
          // 下载片段索引
          if (!TextUtils.isEmpty(path)) {
            try {
              File file = new File(path);
              if (file != null && file.isDirectory()) {
                downInfo.setDownIndex(
                    file.listFiles().length - 1 > 0 ? file.listFiles().length - 1 : 0);
              }
            } catch (Exception e) {
              // TODO: handle exception
            }
          }
        } catch (JSONException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }

        DownTask task = new DownTask(downInfo);
        if (downInfo.getDownState() == DownTask.TASK_FileMerge) {
          // task.finish();//上次未合并完的再次进行合并
        } else if (downInfo.getDownState() != DownTask.TASK_FINISHED) // 已经下载完的
        downInfo.setDownState(DownTask.TASK_PAUSE_DOWNLOAD); // 未下载完的标示为暂停,让用户主动去下�?
        mDownLoadTaskList.add(task);
      }
    } finally {
      if (cursor != null) {
        cursor.close();
      }
      database.close();
    }
    return mDownLoadTaskList;
  }
示例#16
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;
 }