Search in sources :

Example 1 with ChatActivity

use of com.juns.wechat.chat.ChatActivity in project wechat by motianhuo.

the class VoicePlayClickListener method onClick.

@Override
public void onClick(View v) {
    String st = activity.getResources().getString(R.string.Is_download_voice_click_later);
    if (isPlaying) {
        if (((ChatActivity) activity).playMsgId != null && ((ChatActivity) activity).playMsgId.equals(message.getMsgId())) {
            currentPlayListener.stopPlayVoice();
            return;
        }
        currentPlayListener.stopPlayVoice();
    }
    if (message.direct == EMMessage.Direct.SEND) {
        // for sent msg, we will try to play the voice file directly
        playVoice(voiceBody.getLocalUrl());
    } else {
        if (message.status == EMMessage.Status.SUCCESS) {
            File file = new File(voiceBody.getLocalUrl());
            if (file.exists() && file.isFile())
                playVoice(voiceBody.getLocalUrl());
            else
                System.err.println("file not exist");
        } else if (message.status == EMMessage.Status.INPROGRESS) {
            String s = new String();
            Toast.makeText(activity, st, Toast.LENGTH_SHORT).show();
        } else if (message.status == EMMessage.Status.FAIL) {
            Toast.makeText(activity, st, Toast.LENGTH_SHORT).show();
            new AsyncTask<Void, Void, Void>() {

                @Override
                protected Void doInBackground(Void... params) {
                    EMChatManager.getInstance().asyncFetchMessage(message);
                    return null;
                }

                @Override
                protected void onPostExecute(Void result) {
                    super.onPostExecute(result);
                    adapter.notifyDataSetChanged();
                }
            }.execute();
        }
    }
}
Also used : ChatActivity(com.juns.wechat.chat.ChatActivity) File(java.io.File)

Aggregations

ChatActivity (com.juns.wechat.chat.ChatActivity)1 File (java.io.File)1