10000 Media Recorder implementation Android and iOS by daniel-g-favoreto-opl · Pull Request #1810 · flutter-webrtc/flutter-webrtc · GitHub
[go: up one dir, main page]

Skip to content

Media Recorder implementation Android and iOS #1810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 25, 2025

Conversation

daniel-g-favoreto-opl
Copy link
Contributor
@daniel-g-favoreto-opl daniel-g-favoreto-opl commented Apr 4, 2025

This PR adds media recorder support for iOS and fix Android implementation. The core implementation was originally submitted in this PR, but it had become outdated and had merge conflicts. I resolved the conflicts and fixed additional issues that appeared during testing.

Issues that were fixed:

  • On Android versions above 10, an exception was being thrown when attempting to save the recording.
  • On iOS, the generated video wasn’t being saved to the Photos album. To fix this, I used the gallery_saver package. I also updated the media recorder example to reflect this change.

The implementation has been tested across a variety of devices and appears to be working well.

Current behavior:

  • On Android, if the stream is muted, the recorded video will have no audio. (This could be improved in a future PR.)
  • On iOS, the recorded video will always include audio.

This PR depends on two other open PRs that must be merged first:
flutter-webrtc/webrtc-interface#31
flutter-webrtc/dart-webrtc#62

Feel free to request any changes — I’ll respond quickly, as the team needs this merged as soon as possible.

Edit: The pubspec.yaml is currently pointing to a different fork to ensure the build passes. Once the interface and dart-webRTC PR's are merged, the pubspec.yaml should be updated to point to the correct version.

@daniel-g-favoreto-opl daniel-g-favoreto-opl changed the title Media Recorder implementation Media Recorder implementation Android and IoS Apr 4, 2025
@daniel-g-favoreto-opl daniel-g-favoreto-opl changed the title Media Recorder implementation Android and IoS Media Recorder implementation Android and IOs Apr 4, 2025
@daniel-g-favoreto-opl daniel-g-favoreto-opl changed the title Media Recorder implementation Android and IOs Media Recorder implementation Android and iOS Apr 4, 2025
@bantunes22
Copy link

@cloudwebrtc Can you have a look at this? Tested on latest version of flutter and everything seems ok.

This was referenced Apr 7, 2025
@cloudwebrtc
Copy link
Member

hey, thanks for the PR, I will review this PR and its related later this week.

NSNumber* recorderId = argsMap[@"recorderId"];
NSString* path = argsMap[@"path"];
NSString* trackId = argsMap[@"videoTrackId"];
NSString* audioTrackId = argsMap[@"audioTrackId"];
Copy link
@kjawadDeveloper kjawadDeveloper Apr 15, 2025

Choose a reason for hiding this comment

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

I noticed that you had to use a dependency override just to provide audioTrackId. I used this workaround instead to avoid making additional changes.


- (NSString *)audioTrackIdForVideoTrackId:(NSString *)videoTrackId {
    NSString *audioTrackId = nil;

    // Iterate through all peerConnections
    for (NSString *peerConnectionId in self.peerConnections) {
        RTCPeerConnection *peerConnection = self.peerConnections[peerConnectionId];

        // Iterate through the receivers to find the video track
        for (RTCRtpReceiver *receiver in peerConnection.receivers) {
            RTCMediaStreamTrack *track = [receiver valueForKey:@"track"];
            if ([track.kind isEqualToString:@"video"] && [track.trackId isEqualToString:videoTrackId]) {
                // Found the video track, now look for the audio track in the same peerConnection
                for (RTCRtpReceiver *audioReceiver in peerConnection.receivers) {
                    RTCMediaStreamTrack *audioTrack = [audioReceiver valueForKey:@"track"];
                    if ([audioTrack.kind isEqualToString:@"audio"]) {
                        audioTrackId = audioTrack.trackId;
                        break;
                    }
                }
                break;
            }
        }

        // If the audioTrackId is found, break out of the loop
        if (audioTrackId != nil) {
            break;
        }
    }

    return audioTrackId;
}

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 followed your suggestion and created the audioTrackIdForVideoTrackId method. I also refactored the code and removed audioTrack from the methodChannel, since the videoTrack alone is sufficient. Please let me know if everything looks good.

Choose a reason for hiding this comment

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

LGTM

Choose a reason for hiding this comment

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

@cloudwebrtc can you check this?

@bantunes22
Copy link

LGTM

@cloudwebrtc cloudwebrtc merged commit 04ccd08 into flutter-webrtc:main Apr 25, 2025
8 checks passed
cloudwebrtc added a commit that referenced this pull request Apr 29, 2025
cloudwebrtc added a commit that referenced this pull request Apr 29, 2025
cloudwebrtc added a commit that referenced this pull request Apr 29, 2025
cloudwebrtc added a commit that referenced this pull request Apr 29, 2025
* Revert "Revert "Media Recorder implementation Android and iOS (#1810)" (#1822)"

This reverts commit 42eac74.

* bump version for dart-webrtc and interface.

* update.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0