3131import io .agora .api .example .common .widget .VideoReportLayout ;
3232import io .agora .api .example .utils .CommonUtil ;
3333import io .agora .api .example .utils .TokenUtils ;
34+ import io .agora .mediaplayer .IMediaPlayer ;
35+ import io .agora .mediaplayer .data .MediaPlayerSource ;
3436import io .agora .rtc2 .ChannelMediaOptions ;
3537import io .agora .rtc2 .Constants ;
3638import io .agora .rtc2 .IRtcEngineEventHandler ;
@@ -63,6 +65,8 @@ public class LocalVideoTranscoding extends BaseFragment implements View.OnClickL
6365 private Switch switchTransparentBackground ;
6466 private EditText et_channel ;
6567 private RtcEngine engine ;
68+
69+ private IMediaPlayer mediaPlayer ;
6670 private int myUid ;
6771 private boolean joined = false ;
6872
@@ -135,13 +139,24 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
135139 // This api can only be used in the private media server scenario, otherwise some problems may occur.
136140 engine .setLocalAccessPoint (localAccessPointConfiguration );
137141 }
142+ createMediaPlayer ();
138143 }
139144 catch (Exception e ) {
140145 e .printStackTrace ();
141146 getActivity ().onBackPressed ();
142147 }
143148 }
144149
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+
145160 @ Override
146161 public void onDestroy () {
147162 super .onDestroy ();
@@ -152,6 +167,10 @@ public void onDestroy() {
152167 engine .stopCameraCapture (Constants .VideoSourceType .VIDEO_SOURCE_CAMERA_PRIMARY );
153168 engine .stopScreenCapture ();
154169 }
170+ if (mediaPlayer != null ) {
171+ mediaPlayer .stop ();
172+ mediaPlayer .destroy ();
173+ }
155174 handler .post (RtcEngine ::destroy );
156175 engine = null ;
157176 }
@@ -168,6 +187,7 @@ public void onClick(View v) {
168187 joinChannel (channelId );
169188 } else {
170189 joined = false ;
190+ mediaPlayer .pause ();
171191 /*After joining a channel, the user must call the leaveChannel method to end the
172192 * call before joining another channel. This method returns 0 if the user leaves the
173193 * channel and releases all resources related to the call. This method call is
@@ -188,7 +208,6 @@ public void onClick(View v) {
188208 engine .leaveChannel ();
189209 engine .stopPreview (Constants .VideoSourceType .VIDEO_SOURCE_TRANSCODED );
190210 engine .stopCameraCapture (Constants .VideoSourceType .VIDEO_SOURCE_CAMERA_PRIMARY );
191- engine .stopScreenCapture ();
192211 join .setText (getString (R .string .join ));
193212 videoReportLayout .removeAllViews ();
194213 }
@@ -223,11 +242,11 @@ private void joinChannel(String channelId) {
223242
224243
225244 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 );
245+ // ScreenCaptureParameters screenCaptureParameters = new ScreenCaptureParameters();
246+ // screenCaptureParameters.captureVideo = true;
247+ // screenCaptureParameters.videoCaptureParameters.width = width;
248+ // screenCaptureParameters.videoCaptureParameters.height = height;
249+ // engine.startScreenCapture(screenCaptureParameters);
231250
232251
233252 LocalTranscoderConfiguration config = new LocalTranscoderConfiguration ();
@@ -239,6 +258,15 @@ private void joinChannel(String channelId) {
239258 );
240259 config .transcodingVideoStreams = new ArrayList <>();
241260
261+ LocalTranscoderConfiguration .TranscodingVideoStream playerStream = new LocalTranscoderConfiguration .TranscodingVideoStream ();
262+ playerStream .sourceType = Constants .VideoSourceType .VIDEO_SOURCE_MEDIA_PLAYER ;
263+ playerStream .mediaPlayerId = mediaPlayer .getMediaPlayerId ();
264+ playerStream .width = width ;
265+ playerStream .height = height ;
266+ playerStream .zOrder = 1 ;
267+ config .transcodingVideoStreams .add (playerStream );
268+ mediaPlayer .play ();
269+
242270
243271 LocalTranscoderConfiguration .TranscodingVideoStream screenStream = new LocalTranscoderConfiguration .TranscodingVideoStream ();
244272 screenStream .sourceType = Constants .VideoSourceType .VIDEO_SOURCE_SCREEN_PRIMARY ;
0 commit comments