public void doScene(UploadVoiceContext voiceContext)
        {
            if ((voiceContext.mStatus != 0) && (voiceContext.mStatus != 4))
            {
                Log.e("NetSceneUploadVoice", "doScene status error, status = " + voiceContext.mStatus);
            }
            else
            {
                voiceContext.mStatus      = 1;
                this.mVoiceContext        = voiceContext;
                this.mVoiceContext.mScene = this;

                if (mTimerObject == null)
                {
                    //this.mTimerObject = new System.Timers.Timer();

                    //this.mTimerObject.Elapsed += new ElapsedEventHandler((o,e) => NetSceneUploadVoice.onTimerHandler(this,new TimerEventArgs(this)));
                    //this.mTimerObject.Interval = 1000;
                    //new System.Timers.ElapsedEventHandler(NetSceneUploadVoice.onTimerHandler);
                    //mTimerObject.Start();
                    this.mTimerObject = TimerService.addTimer(1, new EventHandler(NetSceneUploadVoice.onTimerHandler), 0, -1, new TimerEventArgs(this));
                    this.mTimerObject.start();
                }
            }
        }
        public void dispatchVoiceHandler()
        {
            UploadVoiceContext mVoiceContext = this.mVoiceContext;

            if (mVoiceContext != null)
            {
                if (mVoiceContext.isFinished())
                {
                    Log.e("NetSceneUploadVoice", "completed already, close netscene.. ");
                    this.doSceneFinished(0);
                }
                else if (mVoiceContext.isInvalidShortVoice())// && mVoiceContext.isRecordEnd()
                {
                    mVoiceContext.mStatus = 4;
                    Log.e("NetSceneUploadVoice", "complete with short voice , ignored.. ");
                    this.doSceneFinished(3);
                }
                else if (mVoiceContext.isSaveCompleted() && mVoiceContext.isSendCompleted())
                {
                    mVoiceContext.mStatus = 5;
                    this.doSceneFinished(1);
                }
                else if (mVoiceContext.isSaveCompleted() && (mVoiceContext.mStatus == 4))
                {
                    Log.e("NetSceneUploadVoice", "save completed, but send error. ");
                    this.doSceneFinished(2);
                }
                else
                {
                    this.checkRecorderSaver();
                    this.checkNetScene();
                }
            }
        }
Esempio n. 3
0
 private static void onSceneFinished(UploadVoiceContext context)
 {
     if (context.mStatus == 5)
     {
         //UploadVoiceContextLoader.resetIntervalLimit();
         Log.i("UploadVoiceService", "ALL completed, clientmsgid = " + context.mClientMsgId);
     }
     else if (context.mStatus == 4)
     {
         Log.e("UploadVoiceService", "on error, clientmsgid = " + context.mClientMsgId);
     }
     else
     {
         Log.e("UploadVoiceService", "status error, clientmsgid = " + context.mClientMsgId);
     }
 }
 public void doSceneFinished(int finishType)
 {
     this.mTimerObject.stop();
     //mTimerObject.Close();
     //mTimerObject.Dispose();
     this.mTimerObject = null;
     if (finishType != 0)
     {
         this.mVoiceContext.onFinished(finishType);
         if (this.mOnSceneFinished != null)
         {
             this.mOnSceneFinished(this.mVoiceContext);
         }
     }
     this.mVoiceContext.mScene = null;
     this.mVoiceContext        = null;
 }
Esempio n. 5
0
//        public bool doSceneBegin(string toUserName)
//        {
//            if (UploadVoiceRecorder.isRunning())
//            {
//                Log.e("UploadVoiceService", "scene cannot begin in recording. ");
//                return false;
//            }
//            string hashString = MD5Core.GetHashString(toUserName + Util.getNowMilliseconds());
//            UploadVoiceContext context = UploadVoiceContext.createByClientMsgID(hashString);
//            if (context == null)
//            {
//                Log.e("UploadVoiceService", "create upload voice context failed. ");
//                return false;
//            }
//            Log.i("UploadVoiceService", "cmd to scene begin, toUserName = "******" , clientMsgId = " + hashString);
//            context.mUserName = toUserName;
//            context.mStatus = 0;
//            UploadVoiceContextMgr.getInstance().putToHead(context);
//            this.checkReadyContextDispatcher();
//            UploadVoiceRecorder.start(context);
//            return true;
//        }

        public bool doSceneDirectWithoutRecord(string toUserName, int voiceTimeLength, byte[] buffer, int EncodeType)
        {
            if (voiceTimeLength > 60)
            {
                voiceTimeLength = 60;
            }
            if (voiceTimeLength < 2)
            {
                voiceTimeLength = 2;
            }
            //voiceTimeLength = buffer.Length;
            voiceTimeLength *= 0x3e8;
            string             hashString = MD5Core.GetHashString(toUserName + Util.getNowMilliseconds());
            UploadVoiceContext context    = UploadVoiceContext.createByClientMsgID(hashString);

            if (context == null)
            {
                Log.e("UploadVoiceService", "create upload voice context failed. ");
                return(false);
            }
            Log.i("UploadVoiceService", "cmd to scene begin, toUserName = "******" , clientMsgId = " + hashString);
            //int count = (voiceTimeLength * 7) / 10;
            //byte[] buffer = new byte[count];
            //for (int i = 0; i < count; i++)
            //{
            //    buffer[i] = (byte) (i | 1);
            //}
            context.mCreateTime = (int)(Util.getNowMilliseconds() / 1000.0);
            context.mUserName   = toUserName;
            context.EncodeType  = EncodeType;//sikl
            context.appendOutputData(buffer, 0, buffer.Length);
            context.mVoiceTimeLength = voiceTimeLength;
            //context.
            context.mEndFlag = 1;
            context.mStatus  = 0;
            UploadVoiceContextMgr.getInstance().putToTail(context);
            this.checkReadyContextDispatcher();
            return(true);
        }
Esempio n. 6
0
 public static void onVoiceContextDispatcher(object sender, EventArgs e)
 {
     UploadVoiceContextMgr.getInstance().clearnFinishedContext();
     if (UploadVoiceContextMgr.getInstance().getCount() <= 0)
     {
         //UploadVoiceContextLoader.checkCleanMsgTrans();
         if (UploadVoiceContextMgr.getInstance().getCount() <= 0)
         {
             closeDispatcherTimer();
             return;
         }
     }
     if (UploadVoiceContextMgr.getInstance().countRunningContext() < MAX_RUNNING)
     {
         UploadVoiceContext voiceContext = UploadVoiceContextMgr.getInstance().getFirstContextNeedHandle();
         if (voiceContext != null)
         {
             Log.i("UploadVoiceService", "new task startup, clientmsgid = " + voiceContext.mClientMsgId);
             NetSceneUploadVoice voice = new NetSceneUploadVoice();
             voice.mOnSceneFinished += new onSceneFinishedDelegate(UploadVoiceService.onSceneFinished);
             voice.doScene(voiceContext);
         }
     }
 }