Skip to content

Commit e9fb0f0

Browse files
author
zhangwei
committed
[Android]Fixs NMS-27370.
1 parent 0eddfa4 commit e9fb0f0

2 files changed

Lines changed: 35 additions & 6 deletions

File tree

Android/APIExample-Compose/app/src/main/java/io/agora/api/example/compose/samples/LocalVideoTranscoding.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ fun LocalVideoTranscoding() {
164164
val source = MediaPlayerSource()
165165
source.url = "https://agora-adc-artifacts.s3.cn-north-1.amazonaws.com.cn/resources/sample.mp4"
166166
source.isAutoPlay = false
167+
setLoopCount(-1)
167168
openWithMediaSource(source)
168169
adjustPlayoutVolume(0)
169170
}

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

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
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;
3436
import io.agora.rtc2.ChannelMediaOptions;
3537
import io.agora.rtc2.Constants;
3638
import 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

Comments
 (0)