Skip to content

Conversation

@Florian14
Copy link
Contributor

@Florian14 Florian14 commented Oct 13, 2022

Type of change

  • WIP Feature
  • Bugfix
  • Technical
  • Other :

Content

Handle the recording side of the voice broadcast with play/pause/resume/stop actions
Voice messages are recorded in mp4 for technical reasons (the Android MediaRecorder does not allow to record in multiple files in other formats).
For the moment, voice messages are sent to the room as separate events in relation to the voice broadcast state event.
The aggregation of the events and the conversion to ogg will be done in dedicated PRs.

Note: common voice messages are still recorded in ogg

Motivation and context

Continue #7127

Screenshots / GIFs

(there is transparency because of gif compression)

voice_broadcast_recording

Tests

  • Enable the voice broadcast feature flag
  • Start a voice broadcast in a room
  • Verify that voice messages are sent to the room
  • Verify that the VB is correctly paused & resumed when playing with the buttons
  • Stop the VB and observe that a final voice message has been sent

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

@Florian14 Florian14 force-pushed the feature/fre/voice_broadcast_start_record branch 5 times, most recently from 0154ead to 82bd02c Compare October 14, 2022 14:41
@Florian14 Florian14 requested review from a team and bmarty and removed request for a team October 14, 2022 14:42
@Florian14 Florian14 marked this pull request as ready for review October 14, 2022 14:42
roomId: String,
attachment: ContentAttachmentData,
rootThreadEventId: String?
rootThreadEventId: String?,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking but I am wondering if we should remove the rootThreadEventId param and build the relatesTo param in case of threads at an upper level?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started considering this point but I am not sure it would make sense to build the relatesTo related to a thread in an upper level, IMO it makes sense to do it in the factory 😕

return createMessageEvent(roomId, content)
}

private fun generateThreadRelationContent(rootThreadEventId: String) =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for mutualizing this code!

@Florian14 Florian14 added the Z-NextRelease For issues and PRs which should be included in the NextRelease. label Oct 17, 2022
@Florian14 Florian14 force-pushed the feature/fre/voice_broadcast_start_record branch from 82bd02c to 3a951f2 Compare October 17, 2022 22:41
Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, a few remarks. Did not try to run the code.

voiceRecorder.stopRecord()
stopRecordingAmplitudes()
voiceRecorder.pauseRecord()
pauseRecordingAmplitudes()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am OK with this change, but can it have a side effect on the voice message feature?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not observe any problem during my few tests with voice messages but I miss some bg about it, I revert the change for the moment and added a comment about it def9fc0

fun setNextOutputFile(roomId: String) {
val mediaRecorder = mediaRecorder ?: return
nextOutputFile = createOutputFile(roomId)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are always >= Q here, no? So this test will be always true. Do you agree?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private fun setOutputFile(roomId: String) {
val mediaRecorder = mediaRecorder ?: return
outputFile = outputFile ?: createOutputFile(roomId)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same remark

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


override fun resumeRecord() {
Toast.makeText(context, "Not implemented for this Android version", Toast.LENGTH_SHORT).show()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could add a fun canPauseAndResume(): Boolean in the interface to adapt the UI pro-actively. Or a more extensive fun getRecorderCapability(): RecorderCapability.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try to consider this point in another PR

"Voice message.${voiceMessageFile.extension}"
)
val audioType = outputFileUri.toMultiPickerAudioType(context) ?: return
if (audioType.duration > 1000) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to keep this check on the duration? It was for voice message IIRC.

If we keep it, the else block should delete the file, maybe?

Copy link
Contributor Author

@Florian14 Florian14 Oct 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was hesitating on that point, I think it makes sense to remove it, let's see what happens 🤞🏻 92bd8cd

}

private fun stopRecording() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this check could be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const val STATE_ROOM_VOICE_BROADCAST_INFO = "io.element.voice_broadcast_info"

/** Default voice broadcast chunk duration, in seconds. */
const val DEFAULT_CHUNK_LENGTH = 30
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be nice for clarity where it's used to have the unit in the name

Suggested change
const val DEFAULT_CHUNK_LENGTH = 30
const val DEFAULT_CHUNK_LENGTH_IN_SECONDS = 30

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 5 Code Smells

16.2% 16.2% Coverage
0.7% 0.7% Duplication

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's all good to me, thanks for the update!

@Florian14 Florian14 merged commit b675005 into develop Oct 18, 2022
@Florian14 Florian14 deleted the feature/fre/voice_broadcast_start_record branch October 18, 2022 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Z-NextRelease For issues and PRs which should be included in the NextRelease.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants