Пример #1
0
        protected override void onSuccess(DownloadVideoRequest request, DownloadVideoResponse response)
        {
            DownloadVideoContext mContext = base.mContext as DownloadVideoContext;

            if ((mContext == null) || !mContext.isRunning())
            {
                Log.e("NetSceneDwVideoEx", "scene is finished, ignored response. ");
            }
            else
            {
                RetConst ret = (RetConst)response.BaseResponse.Ret;
                if (ret != RetConst.MM_OK)
                {
                    Log.e("NetSceneDwVideoEx", "download video failed, ret = " + ret);
                    mContext.mStatus = 4;
                    mContext.onFinishedEx();
                }
                else
                {
                    Log.d("NetSceneDwVideoEx", string.Concat(new object[] { "download response success(rtt=", base.mMiniRTT, ") , startpos = ", response.StartPos, ", total = ", response.TotalLen, ", datalen = ", response.Data.Buffer.Length, ", tranLen=", mContext.mVideoInfo.nTransDataLen }));
                    if ((response.StartPos < 0) || ((response.StartPos + response.Data.Buffer.Length) > response.TotalLen))
                    {
                        Log.e("NetSceneDwVideoEx", "download failed ");
                        mContext.mStatus = 4;
                        mContext.onFinishedEx();
                    }
                    else
                    {
                        mContext.mVideoInfo.nTotalDataLen = (int)response.TotalLen;
                        mContext.appendDownData(response.Data.Buffer.ToByteArray(), response.StartPos, (uint)response.Data.Buffer.Length);
                        mContext.mVideoInfo.nTransDataLen += response.Data.Buffer.Length;
                        base.mOffsetPos += response.Data.Buffer.Length;
                        if (base.mOffsetPos >= base.mEndPos)
                        {
                            Log.d("NetSceneDwVideoEx", string.Concat(new object[] { "download video block complete... [", base.mStartPos, "---", base.mEndPos, "]" }));
                            mContext.onBlockCompleted(base.mSceneID);
                            if (mContext.isDownloadCompleted())
                            {
                                Log.d("NetSceneDwVideoEx", "all videos downlaod completed.");
                                mContext.mStatus = 5;
                                mContext.onFinishedEx();
                            }
                        }
                        else
                        {
                            mContext.updateProgressInfo(0);
                            this.doDownScene();
                        }
                    }
                }
            }
        }
Пример #2
0
        private bool doSceneEx(int msgSvrId, string talker, bool isThumb, ChatMsg msg)
        {
            MsgTrans trans;

            if (msgSvrId == 0)
            {
                Log.e("DownloadVideoService", "Not found the chatmsg , invalid msgid =  " + msgSvrId);
                return(false);
            }
            DownloadVideoContext context = DownloadVideoContextMgr.getInstance().findBySrvMsgID(msgSvrId, isThumb);

            if ((context != null) && !context.needToClean())
            {
                Log.e("DownloadVideoService", "already downloading video  by msgid =  " + msgSvrId);
                return(false);
            }
            // ChatMsg msg = StorageMgr.chatMsg.getBySvrID(talker, msgSvrId);
            if (msg == null)
            {
                Log.e("DownloadVideoService", "Not found the chatmsg by msgid =  " + msgSvrId);
                return(false);
            }

            Log.d("DownloadVideoService", "begin downLoad video thumb...msgid = " + msgSvrId);
            trans                 = new MsgTrans();
            trans.nTransType      = 6;
            trans.nMsgSvrID       = msgSvrId;
            trans.nMsgLocalID     = msg.nMsgLocalID;
            trans.strThumbnail    = msg.strThumbnail;
            trans.strFromUserName = talker;
            trans.strToUserName   = AccountMgr.getCurAccount().strUsrName;
            DownloadVideoContext contextInfo = new DownloadVideoContext {
                mVideoInfo   = trans,
                mChatMsg     = msg,
                mIsThumbMode = isThumb
            };

            if (!parseVideoMsgXML(msg.strMsg, trans, contextInfo))
            {
                Log.e("DownloadVideoService", "parseVideoMsgXML failed!  ");
                return(false);
            }

            if (Directory.Exists(System.IO.Directory.GetCurrentDirectory() + "\\ReplyRes\\Video\\") == false)//如果不存在就创建file文件夹
            {
                Directory.CreateDirectory(System.IO.Directory.GetCurrentDirectory() + "\\ReplyRes\\Video");
            }
            //using (FileStream sw = new FileStream(System.IO.Directory.GetCurrentDirectory() + "\\ReplyRes\\Video\\" + msgSvrId.ToString() + ".xml", FileMode.CreateNew))
            //{
            //    byte[] myByte = System.Text.Encoding.UTF8.GetBytes(msg.strMsg);
            //    sw.Write(myByte, 0, myByte.Length);
            //    sw.Close();
            //}

            new NetSceneUploadCdnVideo().doSceneToCGI(talker, trans, contextInfo, msg.nMsgType);
            return(true);

            contextInfo.updateProgressInfo(0);
            contextInfo.updateChatMsg();
            DownloadVideoContextMgr.getInstance().putToHead(contextInfo);
            this.checkReadyContextDispatcher();
            return(true);
        }