Skip to content

Commit fcb7a5a

Browse files
author
zhangwei
committed
[Android]LocalVideoTranscoding Code rollback.
1 parent 0ca71ff commit fcb7a5a

1 file changed

Lines changed: 18 additions & 31 deletions

File tree

Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/LocalVideoTranscoding.java

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
import io.agora.api.example.common.widget.VideoReportLayout;
3232
import io.agora.api.example.utils.CommonUtil;
3333
import io.agora.api.example.utils.TokenUtils;
34-
import io.agora.mediaplayer.IMediaPlayer;
35-
import io.agora.mediaplayer.data.MediaPlayerSource;
3634
import io.agora.rtc2.ChannelMediaOptions;
3735
import io.agora.rtc2.Constants;
3836
import io.agora.rtc2.IRtcEngineEventHandler;
@@ -65,8 +63,6 @@ public class LocalVideoTranscoding extends BaseFragment implements View.OnClickL
6563
private Switch switchTransparentBackground;
6664
private EditText et_channel;
6765
private RtcEngine engine;
68-
69-
private IMediaPlayer mediaPlayer;
7066
private int myUid;
7167
private boolean joined = false;
7268

@@ -139,24 +135,13 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
139135
// This api can only be used in the private media server scenario, otherwise some problems may occur.
140136
engine.setLocalAccessPoint(localAccessPointConfiguration);
141137
}
142-
createMediaPlayer();
143138
}
144139
catch (Exception e) {
145140
e.printStackTrace();
146141
getActivity().onBackPressed();
147142
}
148143
}
149144

150-
private void createMediaPlayer() {
151-
mediaPlayer = engine.createMediaPlayer();
152-
MediaPlayerSource source = new MediaPlayerSource();
153-
source.setUrl("https://agora-adc-artifacts.s3.cn-north-1.amazonaws.com.cn/resources/sample.mp4");
154-
source.setAutoPlay(false);
155-
mediaPlayer.setLoopCount(-1);
156-
mediaPlayer.openWithMediaSource(source);
157-
mediaPlayer.adjustPlayoutVolume(0);
158-
}
159-
160145
@Override
161146
public void onDestroy() {
162147
super.onDestroy();
@@ -167,10 +152,6 @@ public void onDestroy() {
167152
engine.stopCameraCapture(Constants.VideoSourceType.VIDEO_SOURCE_CAMERA_PRIMARY);
168153
engine.stopScreenCapture();
169154
}
170-
if (mediaPlayer != null) {
171-
mediaPlayer.stop();
172-
mediaPlayer.destroy();
173-
}
174155
handler.post(RtcEngine::destroy);
175156
engine = null;
176157
}
@@ -187,7 +168,6 @@ public void onClick(View v) {
187168
joinChannel(channelId);
188169
} else {
189170
joined = false;
190-
mediaPlayer.pause();
191171
/*After joining a channel, the user must call the leaveChannel method to end the
192172
* call before joining another channel. This method returns 0 if the user leaves the
193173
* channel and releases all resources related to the call. This method call is
@@ -208,6 +188,7 @@ public void onClick(View v) {
208188
engine.leaveChannel();
209189
engine.stopPreview(Constants.VideoSourceType.VIDEO_SOURCE_TRANSCODED);
210190
engine.stopCameraCapture(Constants.VideoSourceType.VIDEO_SOURCE_CAMERA_PRIMARY);
191+
engine.stopScreenCapture();
211192
join.setText(getString(R.string.join));
212193
videoReportLayout.removeAllViews();
213194
}
@@ -240,23 +221,31 @@ private void joinChannel(String channelId) {
240221
// Set audio route to microPhone
241222
engine.setDefaultAudioRoutetoSpeakerphone(true);
242223

224+
225+
engine.startCameraCapture(Constants.VideoSourceType.VIDEO_SOURCE_CAMERA_PRIMARY, new CameraCapturerConfiguration(CameraCapturerConfiguration.CAMERA_DIRECTION.CAMERA_FRONT));
226+
ScreenCaptureParameters screenCaptureParameters = new ScreenCaptureParameters();
227+
screenCaptureParameters.captureVideo = true;
228+
screenCaptureParameters.videoCaptureParameters.width = width;
229+
screenCaptureParameters.videoCaptureParameters.height = height;
230+
engine.startScreenCapture(screenCaptureParameters);
231+
232+
243233
LocalTranscoderConfiguration config = new LocalTranscoderConfiguration();
244234
config.videoOutputConfiguration = new VideoEncoderConfiguration(
245235
new VideoEncoderConfiguration.VideoDimensions(width, height),
246-
VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15,
236+
VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_24,
247237
STANDARD_BITRATE,
248238
VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE
249239
);
250240
config.transcodingVideoStreams = new ArrayList<>();
251241

252-
LocalTranscoderConfiguration.TranscodingVideoStream playerStream = new LocalTranscoderConfiguration.TranscodingVideoStream();
253-
playerStream.sourceType = Constants.VideoSourceType.VIDEO_SOURCE_MEDIA_PLAYER;
254-
playerStream.mediaPlayerId = mediaPlayer.getMediaPlayerId();
255-
playerStream.width = width;
256-
playerStream.height = height;
257-
playerStream.zOrder = 1;
258-
config.transcodingVideoStreams.add(playerStream);
259-
mediaPlayer.play();
242+
243+
LocalTranscoderConfiguration.TranscodingVideoStream screenStream = new LocalTranscoderConfiguration.TranscodingVideoStream();
244+
screenStream.sourceType = Constants.VideoSourceType.VIDEO_SOURCE_SCREEN_PRIMARY;
245+
screenStream.width = width;
246+
screenStream.height = height;
247+
screenStream.zOrder = 1;
248+
config.transcodingVideoStreams.add(screenStream);
260249

261250
LocalTranscoderConfiguration.TranscodingVideoStream cameraStream = new LocalTranscoderConfiguration.TranscodingVideoStream();
262251
cameraStream.sourceType = Constants.VideoSourceType.VIDEO_SOURCE_CAMERA_PRIMARY;
@@ -268,8 +257,6 @@ private void joinChannel(String channelId) {
268257
cameraStream.mirror = true;
269258
config.transcodingVideoStreams.add(cameraStream);
270259

271-
engine.startCameraCapture(Constants.VideoSourceType.VIDEO_SOURCE_CAMERA_PRIMARY, new CameraCapturerConfiguration(CameraCapturerConfiguration.CAMERA_DIRECTION.CAMERA_FRONT));
272-
273260
engine.startLocalVideoTranscoder(config);
274261

275262
// Create render view by RtcEngine

0 commit comments

Comments
 (0)