Voice note is not playing at receiver end

we are able to record voice notes and play at senders end. But it is not playing at the receiver’s end. As our investigation, we are not getting the data from the URL. Can you check at your end?

I see it is not supported in latest android UIkit code

Audio code:-

Sir This code is working fine for audio file but not working with voice note

voice note url—>https://data-us.cometchat.io/153302013b049f5/media/1587454173_185036842_a3cce4cd81876b77c0f2faba85f03bec.mp3

audio url----> https://data-us.cometchat.io/153302013b049f5/media/1587469201_2124374995_7a39ed3039db79295c1883a7c679bd61.mp3

if (!player.isPlaying()) {
leftAudioViewHolder.playAudio.setImageResource(R.drawable.ic_play_arrow);
}

                        leftAudioViewHolder.audioSeekBar.setProgress(0);
                        final String finalMediaFile1 = mediaFile;


                        String audioPath = FileUtils.getPath(context, CometChatConstants.MESSAGE_TYPE_AUDIO)+
                                FileUtils.getFileName(mediaFile);

                        System.out.println("");

                        File audioFile = new File(audioPath);
                        audioFile.setReadable(true,false);

                        if (audioFile.exists()) {
                            leftAudioViewHolder.fileLoadingProgressBar.setVisibility(View.GONE);
                            leftAudioViewHolder.download.setVisibility(View.GONE);
                            leftAudioViewHolder.playAudio.setVisibility(View.VISIBLE);
                            try {

                                if (audioDurations.get(timeStampLong) == null) {
                                    player.reset();

                                    player.setDataSource(audioPath);
                                    player.prepare();


                                    int duration = player.getDuration();
                                    audioDurations.put(timeStampLong, duration);
                                    leftAudioViewHolder.audioLength.setText(DateUtils.convertTimeStampToDurationTime(duration));

                                } else {
                                    int duration = audioDurations.get(timeStampLong);
                                    leftAudioViewHolder.audioLength.setText(DateUtils.convertTimeStampToDurationTime(duration));

                                }

                            } catch (Exception e) {
                                e.printStackTrace();
                                player.reset();

                            }

                        } else {

                            leftAudioViewHolder.fileLoadingProgressBar.setVisibility(View.GONE);
                            leftAudioViewHolder.download.setVisibility(View.VISIBLE);
                            leftAudioViewHolder.playAudio.setVisibility(View.GONE);
                        }


                        String tempUrl = mediaFile;
                        leftAudioViewHolder.download.setOnClickListener(v -> {

                            if (downloadFile != null && downloadFile.getStatus() == AsyncTask.Status.RUNNING) {

                                downloadFile.cancel(true);
                                leftAudioViewHolder.fileLoadingProgressBar.setVisibility(View.GONE);
                                leftAudioViewHolder.playAudio.setVisibility(View.GONE);
                                leftAudioViewHolder.download.setImageResource(R.drawable.ic_file_download);
                                try {
                                    if (audioFile.exists()) {
                                        audioFile.delete();
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            } else {
                                if (CCPermissionHelper.hasPermissions(context, CCPermissionHelper.REQUEST_PERMISSION_WRITE_EXTERNAL_STORAGE)) {
                                    if (FileUtils.checkDirExistence(context, CometChatConstants.MESSAGE_TYPE_AUDIO)) {
                                        downloadFile = new DownloadFile(context, CometChatConstants.MESSAGE_TYPE_AUDIO, tempUrl, leftAudioViewHolder);
                                        downloadFile.execute();
                                    } else {
                                        FileUtils.makeDirectory(context, CometChatConstants.MESSAGE_TYPE_AUDIO);
                                    }
                                } else {
                                    CCPermissionHelper.requestPermissions((Activity) context, new String[]{CCPermissionHelper.REQUEST_PERMISSION_WRITE_EXTERNAL_STORAGE},
                                            StringContract.RequestCode.FILE_WRITE);

                                }
                            }
                        });


                        leftAudioViewHolder.playAudio.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {

                                System.out.println("media audio data..."+finalMediaFile1);
                                if (!TextUtils.isEmpty(finalMediaFile1)) {
                                    try {
                                        if (timeStampLong == currentlyPlayingId) {
                                            Logger.error(TAG, "onClick: currently playing");
                                            currentPlayingSong = "";

// currentlyPlayingId = 0l;
// setBtnColor(holder.viewType, playBtn, true);
try {
if (player.isPlaying()) {
player.pause();
Logger.error(TAG, “onClick: paused”);
leftAudioViewHolder.playAudio.setImageResource(R.drawable.ic_play_arrow);
} else {
// player.setDataSource(message);
// player.prepare();
player.seekTo(player.getCurrentPosition());
leftAudioViewHolder.audioSeekBar.setProgress(player.getCurrentPosition());
leftAudioViewHolder.audioLength.setText(DateUtils.convertTimeStampToDurationTime(player.getDuration()));
leftAudioViewHolder.audioSeekBar.setMax(player.getDuration());
leftAudioViewHolder.playAudio.setImageResource(R.drawable.ic_pause);
timerRunnable = new Runnable() {
@Override
public void run() {

                                                            int pos = player.getCurrentPosition();
                                                            leftAudioViewHolder.audioSeekBar.setProgress(pos);

                                                            if (player.isPlaying() && pos < player.getDuration()) {
                                                                leftAudioViewHolder.audioLength.setText(DateUtils.convertTimeStampToDurationTime(player.getCurrentPosition()));
                                                                seekHandler.postDelayed(this, 250);
                                                            } else {
                                                                seekHandler
                                                                        .removeCallbacks(timerRunnable);
                                                                timerRunnable = null;
                                                            }
                                                        }

                                                    };
                                                    seekHandler.postDelayed(timerRunnable, 100);
                                                    notifyDataSetChanged();
                                                    player.start();
                                                }
                                            } catch (Exception e) {
                                                e.printStackTrace();
                                            }

                                        } else {

                                            leftAudioViewHolder.playAudio.setImageResource(R.drawable.ic_pause);
                                            playAudio(audioFile.exists() ? audioPath : finalMediaFile1, timeStampLong, player, leftAudioViewHolder.playAudio,
                                                    leftAudioViewHolder.audioLength, leftAudioViewHolder.audioSeekBar, i);
                                        }
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }

                            }
                        });

Hi @VijayZ,

We checked at our end and it’s working fine. You can see the video in below link.
https://drive.google.com/a/sakec.ac.in/file/d/10dFoBYbkwUv36xuE0UnVA5wIbYZxVWzZ/view?usp=drivesdk

Hii
we are able to record voice notes and play at senders end. But it is not playing at the receiver’s end. As our investigation, again we are not getting the data from the URL.
if i send another audio from attachment its working fine on both end , please help me how can i resolve it in java app.

This is my code for voice note at receiver end.
LeftAudioViewHolder leftAudioViewHolder = (LeftAudioViewHolder) holder;
leftAudioViewHolder.fileLoadingProgressBar.setVisibility(View.GONE);
leftAudioViewHolder.messageTimeStamp.setText(timeStampString);
leftAudioViewHolder.senderName.setVisibility(View.GONE);
leftAudioViewHolder.avatar.setVisibility(View.GONE);
leftAudioViewHolder.audioSeekBar.getProgressDrawable().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP);
leftAudioViewHolder.audioSeekBar.getThumb().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP);

            if (!player.isPlaying()) {

                leftAudioViewHolder.playAudio.setImageResource(R.drawable.ic_play_arrow);
            }
            leftAudioViewHolder.audioSeekBar.setProgress(0);
            final String finalMediaFile1 = mediaFile;


            System.out.println(" media file..."+finalMediaFile1);


            String audioPath = FileUtils.getPath(context, CometChatConstants.MESSAGE_TYPE_AUDIO)+
                    FileUtils.getFileName(mediaFile);

            File audioFile = new File(audioPath);
            audioFile.setReadable(true,false);

            if (audioFile.exists()) {
                leftAudioViewHolder.fileLoadingProgressBar.setVisibility(View.GONE);
                leftAudioViewHolder.download.setVisibility(View.GONE);
                leftAudioViewHolder.playAudio.setVisibility(View.VISIBLE);
                try {

                    if (audioDurations.get(timeStampLong) == null) {
                        player.reset();

                        player.setDataSource(audioPath);
                        player.prepare();


                        int duration = player.getDuration();
                        audioDurations.put(timeStampLong, duration);
                        leftAudioViewHolder.audioLength.setText(DateUtils.convertTimeStampToDurationTime(duration));

                    } else {
                        int duration = audioDurations.get(timeStampLong);
                        leftAudioViewHolder.audioLength.setText(DateUtils.convertTimeStampToDurationTime(duration));

                    }

                } catch (Exception e) {
                    e.printStackTrace();
                    player.reset();

                }

            } else {
                leftAudioViewHolder.fileLoadingProgressBar.setVisibility(View.GONE);
                leftAudioViewHolder.download.setVisibility(View.VISIBLE);
                leftAudioViewHolder.playAudio.setVisibility(View.GONE);
            }


            String tempUrl = mediaFile;
            leftAudioViewHolder.download.setOnClickListener(v -> {

                if (downloadFile != null && downloadFile.getStatus() == AsyncTask.Status.RUNNING) {

                    downloadFile.cancel(true);
                    leftAudioViewHolder.fileLoadingProgressBar.setVisibility(View.GONE);
                    leftAudioViewHolder.playAudio.setVisibility(View.GONE);
                    leftAudioViewHolder.download.setImageResource(R.drawable.ic_file_download);
                    try {
                        if (audioFile.exists()) {
                            audioFile.delete();
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else {
                    if (CCPermissionHelper.hasPermissions(context, CCPermissionHelper.REQUEST_PERMISSION_WRITE_EXTERNAL_STORAGE)) {
                        if (FileUtils.checkDirExistence(context, CometChatConstants.MESSAGE_TYPE_AUDIO)) {
                            downloadFile = new DownloadFile(context, CometChatConstants.MESSAGE_TYPE_AUDIO, tempUrl, leftAudioViewHolder);
                            downloadFile.execute();
                        } else {
                            FileUtils.makeDirectory(context, CometChatConstants.MESSAGE_TYPE_AUDIO);
                        }
                    } else {
                        CCPermissionHelper.requestPermissions((Activity) context, new String[]{CCPermissionHelper.REQUEST_PERMISSION_WRITE_EXTERNAL_STORAGE},
                                StringContract.RequestCode.FILE_WRITE);

                    }
                }
            });

            leftAudioViewHolder.playAudio.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {


                    if (!TextUtils.isEmpty(finalMediaFile1)) {
                        try {

                            System.out.println(" data is.playing..."+timeStampLong+","+currentlyPlayingId);

                            if (timeStampLong == currentlyPlayingId) {
                                Logger.error(TAG, "onClick: currently playing");
                                currentPlayingSong = "";

// currentlyPlayingId = 0l;
// setBtnColor(holder.viewType, playBtn, true);
try {
if (player.isPlaying()) {
player.pause();
Logger.error(TAG, “onClick: paused”);
leftAudioViewHolder.playAudio.setImageResource(R.drawable.ic_play_arrow);
} else {
// player.setDataSource(message);
// player.prepare();
player.seekTo(player.getCurrentPosition());
leftAudioViewHolder.audioSeekBar.setProgress(player.getCurrentPosition());
leftAudioViewHolder.audioLength.setText(DateUtils.convertTimeStampToDurationTime(player.getDuration()));
leftAudioViewHolder.audioSeekBar.setMax(player.getDuration());
leftAudioViewHolder.playAudio.setImageResource(R.drawable.ic_pause);
timerRunnable = new Runnable() {
@Override
public void run() {

                                                int pos = player.getCurrentPosition();
                                                leftAudioViewHolder.audioSeekBar.setProgress(pos);

                                                if (player.isPlaying() && pos < player.getDuration()) {
                                                    leftAudioViewHolder.audioLength.setText(DateUtils.convertTimeStampToDurationTime(player.getCurrentPosition()));
                                                    seekHandler.postDelayed(this, 250);
                                                } else {
                                                    seekHandler
                                                            .removeCallbacks(timerRunnable);
                                                    timerRunnable = null;
                                                }
                                            }

                                        };
                                        seekHandler.postDelayed(timerRunnable, 100);
                                        notifyDataSetChanged();
                                        player.start();
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }

                            } else {

                                leftAudioViewHolder.playAudio.setImageResource(R.drawable.ic_pause);
                                playAudio(audioFile.exists() ? audioPath : finalMediaFile1, timeStampLong, player, leftAudioViewHolder.playAudio,
                                        leftAudioViewHolder.audioLength, leftAudioViewHolder.audioSeekBar, i);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                }
            });

Hi @avisharma.11,

We checked at our end and it’s working fine. The audio works fine at the sender because it plays a voice note from local storage if it’s available. In the case of a receiver, it streams the audio from url. Please share the log of voicenote file.

We suggest you to please refer uiKit as it includes voice note feature.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.