private void loadVideoData() { rlVideoContent = (RelativeLayout) findViewById(R.id.video_view); // rlVideoContent.setOnClickListener(this); if (PluginUtils.isPluginMounted()) { mEffects = new XEffects(); } userID = ActiveAccount.getInstance(ZApplication.getInstance()).getUID(); String diaryString = getIntent().getStringExtra("diarystring"); myDiary = new Gson().fromJson(diaryString, MyDiary.class); String diaryEditString = getIntent().getStringExtra(DiaryEditPreviewActivity.INTENT_ACTION_EDIT_NOTELIST); diaryEditNote = new Gson().fromJson(diaryEditString, DiaryEditNote.class); curOriginalVideoPath = diaryEditNote.mediaPath; // diaryUUID = getIntent().getStringExtra("diaryuuid"); // myDiary = DiaryManager.getInstance().findMyDiaryByUUID(diaryUUID); // String videoUrl = myDiary.getMainUrl(); // // MediaValue mediaValue = AccountInfo.getInstance(userID).mediamapping.getMedia(userID, // videoUrl); // if (mediaValue != null) { // videoPath = Environment.getExternalStorageDirectory() + mediaValue.path; // } videoPath = myDiary.getMainPath(); Log.d(TAG, "videoPath = " + videoPath); videoDuration = new Mp4InfoUtils(videoPath).totaltime; curVideoDuration = videoDuration; curVideoPath = videoPath; startMontageTime = 0; endMontageTime = videoDuration; montageView.setTotalTime(videoDuration); montageView.setVideoMontageChangeListener(this); // 播放时间 if (null == mMediaPlayer) { mMediaPlayer = new XMediaPlayer(this, mEffects, true); mMediaPlayer.setUpdateTimePeriod(0.1f); mMediaPlayer.setListener(new MyOnInfoListener()); rlVideoContent.addView((View) mMediaPlayer.getXSurfaceView()); if (videoPath != null) { mMediaPlayer.open(videoPath); } } generateThumbsCovers(); }
@Override public boolean handleMessage(Message msg) { switch (msg.what) { case STATE_WAITING: Log.d("debug", "I am waiting!"); break; case STATE_PREPARING: // 网络状态判断 if (ZNetworkStateDetector.isAvailable() && ZNetworkStateDetector.isConnected() && this.info != null && this.info.upRequest != null) { // 请求日记结构 Requester3.createStructure( handler, this.info.upRequest.diaryid, this.info.upRequest.diaryuuid, this.info.upRequest.operate_diarytype, this.info.upRequest.resourcediaryid, this.info.upRequest.resourcediaryuuid, this.info.upRequest.tags, String.valueOf(TimeHelper.getInstance().now()), this.info.upRequest.addresscode, this.info.upRequest.position_status, this.info.upRequest.isonlymic, this.info.upRequest.longitude_real, this.info.upRequest.latitude_real, this.info.upRequest.position_real, this.info.upRequest.longitude, this.info.upRequest.latitude, this.info.upRequest.position, this.info.upRequest.longitude_view, this.info.upRequest.latitude_view, this.info.upRequest.position_view, this.info.upRequest.shoottime, this.info.upRequest.attachs); } else { // Toast.makeText(ZApplication.getInstance().getApplicationContext(), "网络异常,无法启动该任务!", // Toast.LENGTH_LONG).show(); translateToState(STATE_ERROR); } break; case Requester3.RESPONSE_TYPE_CREATE_STRUCTURE: GsonResponse3.createStructureResponse response = (GsonResponse3.createStructureResponse) msg.obj; if (msg.obj != null && response != null && response.attachs != null && response.status.equals("0")) { this.info.diaryid = response.diaryid; // 取得diaryid DiaryManager diarymanager = DiaryManager.getInstance(); MyDiary myLocalDiary = diarymanager.findMyDiaryByUUID(response.diaryuuid); MyDiaryList diarylist = diarymanager.findDiaryGroupByUUID(response.diaryuuid); if (myLocalDiary != null && diarylist != null) { myLocalDiary.diaryid = response.diaryid; myLocalDiary.sync_status = 1; Log.d(TAG, "diaryid = " + myLocalDiary.diaryid); diarylist.diaryid = response.diaryid; } else if (this.info.source != 1) { Log.d(TAG, "Should Not Be Here!"); translateToState(STATE_REMOVED); return false; } if (this.info == null || this.info.caMedias == null /*|| this.info.caMedias.size() <= 0*/) { Log.e(TAG, "Do not click the control button rapidly!"); return false; } for (int i = 0; i < response.attachs.length; i++) { for (int j = 0; j < this.info.caMedias.size(); j++) { Log.d(TAG, "caMedias size = " + this.info.caMedias.size() + "i = " + i + ",j = " + j); upMedia tmpmedia = this.info.caMedias.get(j); if (tmpmedia == null) { Log.d(TAG, "tmpmedia is null"); } if (response.attachs[i] != null && tmpmedia.attachuuid.equals(response.attachs[i].attachuuid)) { this.info.caMedias.get(j).attachid = response.attachs[i].attachid; // 取得attachid // tmpmf.remotepath = response.attachs[i].path; for (int k = 0; k < this.info.caMedias.get(j).attachMedia.size(); k++) { String remoteUrl = this.info.caMedias.get(j).attachMedia.get(k).remotepath; this.info.caMedias.get(j).attachMedia.get(k).remotepath = response.attachs[i].path; // 取得服务器地址 // 写入mapping if (response.attachs[i].path != null) { MediaValue tmMV = new MediaValue(); tmMV = AccountInfo.getInstance(this.info.userid) .mediamapping .getMedia(this.info.userid, remoteUrl); if (tmMV != null) { Log.d(TAG, "get MediaValue.url=" + tmMV.url); tmMV.url = response.attachs[i].path; AccountInfo.getInstance(this.info.userid) .mediamapping .setMedia(this.info.userid, response.attachs[i].path, tmMV); AccountInfo.getInstance(this.info.userid) .mediamapping .delMedia(this.info.userid, remoteUrl); Log.d(TAG, "set MediaValue.url=" + tmMV.url); } } } } } if (this.info.source != 1) { // 修改日记结构 if (myLocalDiary != null && myLocalDiary.attachs != null) { DiaryAttach diaryattach = myLocalDiary.attachs; // 主 MainAttach mainattach = diaryattach.levelattach; if (mainattach != null) { if (mainattach.attachuuid.equals(response.attachs[i].attachuuid)) { mainattach.attachid = response.attachs[i].attachid; mainattach.attachurl = response.attachs[i].path; } } // 辅 AuxAttach[] auxattach = diaryattach.attach; if (auxattach != null) { for (int k = 0; k < auxattach.length; k++) { if (auxattach[k].attachuuid.equals(response.attachs[i].attachuuid)) { auxattach[k].attachid = response.attachs[i].attachid; auxattach[k].attachurl = response.attachs[i].path; } } } } } } if (this.info.source != 1) DiaryManager.getInstance().notifyMyDiaryChanged(); // 转变正常上传任务 translateToState(STATE_COMPELETED); } else { translateToState(ACTION_RETRY); return false; } break; // 转变正常上传任务 case STATE_RUNNING: retryTimes = 0; break; case STATE_PAUSED: retryTimes = 0; stopThread(); break; case STATE_REMOVED: retryTimes = 0; stopThread(); if (taskmanagerListener != null) { taskmanagerListener.OnTaskRemoved(this); } if (mitaskmanagerListener != null) { mitaskmanagerListener.OnTaskRemoved(this); } break; case ACTION_RETRY: if (retryTimes < 2) { retryTimes++; ZThread.sleep(500); // 500, 2000, 3500, 5000 if (getState() == STATE_PAUSED) { ZLog.e("Status changed to [" + getState() + "] when retrying!"); translateToState(STATE_PAUSED); break; } else if (getState() == STATE_WAITING) { ZLog.e("Status changed to [" + getState() + "] when retrying, ignore it!"); break; } translateToState(STATE_PREPARING); // return是为了不执行 notifyStateChange return false; } else { translateToState(STATE_ERROR); } break; // 转变正常上传任务 case STATE_COMPELETED: retryTimes = 0; stopThread(); Log.d(TAG, "离线任务成功转换成上传任务"); break; case STATE_ERROR: break; } return false; }
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_edit_video); videoLayout = (FrameLayout) findViewById(R.id.fl_edit_diary_video); dm = getResources().getDisplayMetrics(); Log.d(TAG, "width = " + dm.widthPixels + " height = " + dm.heightPixels); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(dm.widthPixels, dm.widthPixels); videoLayout.setLayoutParams(params); montageView = (VideoMontageView) findViewById(R.id.vv_edit_video_montageview); gridView = (GridView) findViewById(R.id.gv_edit_video_montage_imgs); adapter = new ImageAdapter(this); gridView.setAdapter(adapter); ivVideoCover = (ImageView) findViewById(R.id.iv_video_preview); loadVideoData(); videoCoverPath = myDiary.getVideoCoverPath(); ViewTreeObserver vto2 = ivVideoCover.getViewTreeObserver(); vto2.addOnGlobalLayoutListener( new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (videoCoverPath != null) { Log.d( TAG, "loadVideoData videoFrontCoverPath = " + videoCoverPath + " url = " + myDiary.getVideoCoverUrl()); ivVideoCover.setVisibility(View.VISIBLE); int height = ivVideoCover.getMeasuredHeight(); int width = ivVideoCover.getMeasuredWidth(); Log.d(TAG, "measuredwidth = " + width + " measuredheight = " + height); videoCoverBmp = BitmapUtils.readBitmapAutoSize(videoCoverPath, width, height); if (videoCoverBmp != null) { Log.d( TAG, "width = " + videoCoverBmp.getWidth() + " height = " + videoCoverBmp.getHeight()); } } else { ivVideoCover.setImageBitmap(null); } if (videoCoverBmp != null) { curAngle = mMediaPlayer.getCurrentOrientation(); ivVideoCover.setImageBitmap( BitmapUtils.rotate(videoCoverBmp, (360 - curAngle) % 360, true)); ivVideoCover.setVisibility(View.VISIBLE); } ivVideoCover.getViewTreeObserver().removeGlobalOnLayoutListener(this); } }); ivPlay = (ImageView) findViewById(R.id.iv_video_play); ivPlay.setOnClickListener(this); findViewById(R.id.fl_edit_diary_video).setOnClickListener(this); montageSave = (ImageView) findViewById(R.id.iv_edit_video_save); montageDelete = (ImageView) findViewById(R.id.iv_edit_video_delete); montageSave.setOnClickListener(this); montageDelete.setOnClickListener(this); ivBack = (ImageView) findViewById(R.id.iv_edit_diary_back); ivDone = (ImageView) findViewById(R.id.iv_edit_diary_save); ivUndo = (ImageView) findViewById(R.id.iv_edit_diary_undo); ivCover = (ImageView) findViewById(R.id.iv_edit_video_cover); flCoverSetted = (RelativeLayout) findViewById(R.id.fl_edit_video_cover_setted); ivCoverSetted = (ImageView) findViewById(R.id.iv_edit_video_cover_setted); findViewById(R.id.iv_edit_video_rotate).setOnClickListener(this); ivCover.setOnClickListener(this); flCoverSetted.setOnClickListener(this); flCoverSetted.setVisibility(View.GONE); ivBack.setOnClickListener(this); ivDone.setOnClickListener(this); ivUndo.setOnClickListener(this); ivUndo.setEnabled(false); ivDone.setEnabled(false); setMontageEnable(false); }