Search in sources :

Example 1 with VideoMessageBody

use of com.easemob.chat.VideoMessageBody in project wechat by motianhuo.

the class ChatActivity method sendVideo.

/**
	 * 发送视频消息
	 */
private void sendVideo(final String filePath, final String thumbPath, final int length) {
    final File videoFile = new File(filePath);
    if (!videoFile.exists()) {
        return;
    }
    try {
        EMMessage message = EMMessage.createSendMessage(EMMessage.Type.VIDEO);
        // 如果是群聊,设置chattype,默认是单聊
        if (chatType == CHATTYPE_GROUP)
            message.setChatType(ChatType.GroupChat);
        String to = toChatUsername;
        message.setReceipt(to);
        VideoMessageBody body = new VideoMessageBody(videoFile, thumbPath, length, videoFile.length());
        message.addBody(body);
        conversation.addMessage(message);
        listView.setAdapter(adapter);
        adapter.refresh();
        listView.setSelection(listView.getCount() - 1);
        setResult(RESULT_OK);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : File(java.io.File) EaseMobException(com.easemob.exceptions.EaseMobException) IOException(java.io.IOException) EMMessage(com.easemob.chat.EMMessage) VideoMessageBody(com.easemob.chat.VideoMessageBody)

Example 2 with VideoMessageBody

use of com.easemob.chat.VideoMessageBody in project wechat by motianhuo.

the class MessageAdapter method handleVideoMessage.

/**
	 * 视频消息
	 * 
	 * @param message
	 * @param holder
	 * @param position
	 * @param convertView
	 */
private void handleVideoMessage(final EMMessage message, final ViewHolder holder, final int position, View convertView) {
    VideoMessageBody videoBody = (VideoMessageBody) message.getBody();
    // final File image=new File(PathUtil.getInstance().getVideoPath(),
    // videoBody.getFileName());
    String localThumb = videoBody.getLocalThumb();
    holder.iv.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            activity.startActivityForResult(new Intent(activity, ContextMenu.class).putExtra("position", position).putExtra("type", EMMessage.Type.VIDEO.ordinal()), ChatActivity.REQUEST_CODE_CONTEXT_MENU);
            return true;
        }
    });
    if (localThumb != null) {
        showVideoThumbView(localThumb, holder.iv, videoBody.getThumbnailUrl(), message);
    }
    if (videoBody.getLength() > 0) {
        String time = DateUtils.toTimeBySecond(videoBody.getLength());
        holder.timeLength.setText(time);
    }
    holder.playBtn.setImageResource(R.drawable.video_download_btn_nor);
    if (message.direct == EMMessage.Direct.RECEIVE) {
        if (videoBody.getVideoFileLength() > 0) {
            String size = TextFormater.getDataSize(videoBody.getVideoFileLength());
            holder.size.setText(size);
        }
    } else {
        if (videoBody.getLocalUrl() != null && new File(videoBody.getLocalUrl()).exists()) {
            String size = TextFormater.getDataSize(new File(videoBody.getLocalUrl()).length());
            holder.size.setText(size);
        }
    }
    if (message.direct == EMMessage.Direct.RECEIVE) {
        // System.err.println("it is receive msg");
        if (message.status == EMMessage.Status.INPROGRESS) {
            // System.err.println("!!!! back receive");
            holder.iv.setImageResource(R.drawable.default_image);
            showDownloadImageProgress(message, holder);
        } else {
            // System.err.println("!!!! not back receive, show image directly");
            holder.iv.setImageResource(R.drawable.default_image);
            if (localThumb != null) {
                showVideoThumbView(localThumb, holder.iv, videoBody.getThumbnailUrl(), message);
            }
        }
        return;
    }
    holder.pb.setTag(position);
    // until here ,deal with send video msg
    switch(message.status) {
        case SUCCESS:
            holder.pb.setVisibility(View.GONE);
            holder.staus_iv.setVisibility(View.GONE);
            holder.tv.setVisibility(View.GONE);
            break;
        case FAIL:
            holder.pb.setVisibility(View.GONE);
            holder.tv.setVisibility(View.GONE);
            holder.staus_iv.setVisibility(View.VISIBLE);
            break;
        case INPROGRESS:
            if (timers.containsKey(message.getMsgId()))
                return;
            // set a timer
            final Timer timer = new Timer();
            timers.put(message.getMsgId(), timer);
            timer.schedule(new TimerTask() {

                @Override
                public void run() {
                    activity.runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            holder.pb.setVisibility(View.VISIBLE);
                            holder.tv.setVisibility(View.VISIBLE);
                            holder.tv.setText(message.progress + "%");
                            if (message.status == EMMessage.Status.SUCCESS) {
                                holder.pb.setVisibility(View.GONE);
                                holder.tv.setVisibility(View.GONE);
                                // message.setSendingStatus(Message.SENDING_STATUS_SUCCESS);
                                timer.cancel();
                            } else if (message.status == EMMessage.Status.FAIL) {
                                holder.pb.setVisibility(View.GONE);
                                holder.tv.setVisibility(View.GONE);
                                // message.setSendingStatus(Message.SENDING_STATUS_FAIL);
                                // message.setProgress(0);
                                holder.staus_iv.setVisibility(View.VISIBLE);
                                Toast.makeText(activity, activity.getString(R.string.send_fail) + activity.getString(R.string.connect_failuer_toast), 0).show();
                                timer.cancel();
                            }
                        }
                    });
                }
            }, 0, 500);
            break;
        default:
            // sendMsgInBackground(message, holder);
            sendPictureMessage(message, holder);
    }
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) OnLongClickListener(android.view.View.OnLongClickListener) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) File(java.io.File) VideoMessageBody(com.easemob.chat.VideoMessageBody)

Example 3 with VideoMessageBody

use of com.easemob.chat.VideoMessageBody in project wechat by motianhuo.

the class MessageAdapter method showVideoThumbView.

/**
	 * 展示视频缩略图
	 * 
	 * @param localThumb
	 *            本地缩略图路径
	 * @param iv
	 * @param thumbnailUrl
	 *            远程缩略图路径
	 * @param message
	 */
private void showVideoThumbView(String localThumb, ImageView iv, String thumbnailUrl, final EMMessage message) {
    // first check if the thumbnail image already loaded into cache
    Bitmap bitmap = ImageCache.getInstance().get(localThumb);
    if (bitmap != null) {
        // thumbnail image is already loaded, reuse the drawable
        iv.setImageBitmap(bitmap);
        iv.setClickable(true);
        iv.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                VideoMessageBody videoBody = (VideoMessageBody) message.getBody();
                // TODO 打开视频页面
                System.err.println("video view is on click");
            // Intent intent = new Intent(activity,
            // ShowVideoActivity.class);
            // intent.putExtra("localpath", videoBody.getLocalUrl());
            // intent.putExtra("secret", videoBody.getSecret());
            // intent.putExtra("remotepath", videoBody.getRemoteUrl());
            // if (message != null
            // && message.direct == EMMessage.Direct.RECEIVE
            // && !message.isAcked
            // && message.getChatType() != ChatType.GroupChat) {
            // message.isAcked = true;
            // try {
            // EMChatManager.getInstance().ackMessageRead(
            // message.getFrom(), message.getMsgId());
            // } catch (Exception e) {
            // e.printStackTrace();
            // }
            // }
            // activity.startActivity(intent);
            }
        });
    } else {
        new LoadVideoImageTask().execute(localThumb, thumbnailUrl, iv, activity, message, this);
    }
}
Also used : Bitmap(android.graphics.Bitmap) OnClickListener(android.view.View.OnClickListener) LoadVideoImageTask(com.juns.wechat.chat.task.LoadVideoImageTask) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) VideoMessageBody(com.easemob.chat.VideoMessageBody)

Aggregations

VideoMessageBody (com.easemob.chat.VideoMessageBody)3 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 File (java.io.File)2 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 OnClickListener (android.view.View.OnClickListener)1 OnLongClickListener (android.view.View.OnLongClickListener)1 EMMessage (com.easemob.chat.EMMessage)1 EaseMobException (com.easemob.exceptions.EaseMobException)1 LoadVideoImageTask (com.juns.wechat.chat.task.LoadVideoImageTask)1 IOException (java.io.IOException)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1