Jump to content
  • 0

How to switch video track from Camera to Screen share and vice versa


Vijay EH
 Share

Question

Hello everyone! We have been stuck here from a week at least trying to solve this. I'm using the webrtc-framework for android provided from official website of antmedia. I'm able to switch from front camera to back camera/vice versa. However I want to switch video track dynamically. I'm trying to create screen sharing video track and add it to peer connection like below.

 

public void SwitchVideoTrack() {

final EglBase.Context eglBaseContext = eglBase.getEglBaseContext();

PeerConnectionFactory peerConnectionFactory = peerConnectionClient.factory;

 

// create AudioSource

AudioSource audioSource = peerConnectionFactory.createAudioSource(new MediaConstraints());

this.audioTrack = peerConnectionFactory.createAudioTrack("AUDIO_TRACK_ID", audioSource);

 

surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", eglBaseContext);

// create VideoCapturer

videoCapturer = createScreenCapturer();

 

VideoSource videoSource = peerConnectionFactory.createVideoSource(videoCapturer.isScreencast());

localVideoTrack = peerConnectionFactory.createVideoTrack("VIDEO_TRACK_ID  ", videoSource);

videoCapturer.initialize(surfaceTextureHelper, context, videoSource.getCapturerObserver()); 

videoCapturer.startCapture(720, 1280, 30);

 

peerConnectionClient.setLocalVideoTrack(localVideoTrack);

peerConnectionClient.localVideoSender.setTrack(localVideoTrack, true);

}

 Here localVideoSender is RtpSender.

public RtpSender localVideoSender;

 

As soon as I switch using this method, the stream stops and I get "Source error" in player where I'm streaming this video.

Please guide me to the right path if I'm missing anything else here. 

 

Thanks!

Link to comment
Share on other sites

  • Answers 2
  • Created
  • Last Reply

Top Posters For This Question

Top Posters For This Question

2 answers to this question

Recommended Posts

  • 0

Hi

Have a good day. 

The SDK has a switchCamera() function that switches front and rear cameras on the fly. We are doing our best, but it can sometimes take time to find resources for this kind of implementation. You can develop this feature according to switchCamera() codebase. If you still cannot figure it out, I can organize a meeting with our developer team.  How does it sound?

Best Regards,
Selim

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share


×
×
  • Create New...