完善直播demo
This commit is contained in:
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@@ -26,7 +26,6 @@
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
<option name="useQualifiedModuleNames" value="true" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
|
||||
@@ -11,6 +11,7 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.mogo.cloud.live.listener.ILiveProgressListener;
|
||||
import com.mogo.cloud.live.manager.MoGoLiveManager;
|
||||
import com.mogo.cloud.util.Devices;
|
||||
|
||||
|
||||
public class LivePlayActivity extends AppCompatActivity {
|
||||
@@ -34,12 +35,11 @@ public class LivePlayActivity extends AppCompatActivity {
|
||||
Toast.makeText(getApplicationContext(), buttonView.getText(), Toast.LENGTH_SHORT).show();
|
||||
if (isChecked) {
|
||||
String roomId = etLookRoomId.getText().toString().trim();
|
||||
mStreamId = MoGoLiveManager.STREAM_ID_PREFIX + roomId;
|
||||
MoGoLiveManager.getInstance().init(this.getApplication(), null);
|
||||
MoGoLiveManager.getInstance().loginRoom("F803EB2046PZD00140", roomId);
|
||||
MoGoLiveManager.getInstance().loginRoom(Devices.getSn(), roomId);
|
||||
MoGoLiveManager.getInstance().setLiveProgressListener(listener);
|
||||
} else {
|
||||
MoGoLiveManager.getInstance().stopLive(mStreamId);
|
||||
MoGoLiveManager.getInstance().stopLive();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -83,12 +83,12 @@ public class LivePlayActivity extends AppCompatActivity {
|
||||
};
|
||||
|
||||
private void toggleLive(boolean isChecked) {
|
||||
Log.i(TAG, "toggleLive status : " + isChecked + " , mStreamId : " + mStreamId);
|
||||
if (isChecked) {
|
||||
MoGoLiveManager.getInstance().startLive(mStreamId, surfaceView);
|
||||
mStreamId = MoGoLiveManager.getInstance().startLive(surfaceView);
|
||||
} else {
|
||||
MoGoLiveManager.getInstance().stopLive(mStreamId);
|
||||
MoGoLiveManager.getInstance().stopLive();
|
||||
}
|
||||
Log.i(TAG, "toggleLive status : " + isChecked + " , mStreamId : " + mStreamId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,11 +40,11 @@ public class LivePushActivity extends BaseLiveActivity {
|
||||
public void toggleLive(boolean isLive) {
|
||||
Log.i(TAG, "toggleLive : " + isLive);
|
||||
this.isLive = isLive;
|
||||
// if (isLive) {
|
||||
// PushService.startService(this, PushService.ACTION_START_RTMP_PUSH, Devices.getSn());
|
||||
// } else {
|
||||
// PushService.startService(this, PushService.ACTION_STOP_RTMP_PUSH, null);
|
||||
// }
|
||||
if (isLive) {
|
||||
PushService.startService(this, PushService.ACTION_START_RTMP_PUSH, Devices.getSn());
|
||||
} else {
|
||||
PushService.startService(this, PushService.ACTION_STOP_RTMP_PUSH, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,10 +2,12 @@ package com.mogo.cloud.live.manager;
|
||||
|
||||
import android.app.Application;
|
||||
import android.os.Environment;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.SurfaceView;
|
||||
|
||||
import com.mogo.cloud.live.listener.ILiveProgressListener;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
@@ -88,6 +90,10 @@ public class MoGoLiveManager {
|
||||
* 当前的房间ID
|
||||
*/
|
||||
private String currentRoomId = "";
|
||||
/**
|
||||
* 当前直播流ID
|
||||
*/
|
||||
private String currentStreamId = "";
|
||||
/**
|
||||
* 自定义采集状态,true-初始化完成,false-没有初始化
|
||||
*/
|
||||
@@ -288,8 +294,11 @@ public class MoGoLiveManager {
|
||||
public void loginRoom(String userId, String roomId) {
|
||||
initCustomVideoCapture();
|
||||
currentRoomId = ROOM_ID_PREFIX + roomId;
|
||||
currentStreamId = STREAM_ID_PREFIX + roomId;
|
||||
ZegoUser zegoUser = new ZegoUser(userId, NAME_PREFIX + userId);
|
||||
mExpressEngine.loginRoom(currentRoomId, zegoUser);
|
||||
Log.i(TAG, "loginRoom userId:" + userId + " currentRoomId : " + currentRoomId
|
||||
+ " currentStreamId:" + currentStreamId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -373,22 +382,26 @@ public class MoGoLiveManager {
|
||||
/**
|
||||
* 开始直播
|
||||
*
|
||||
* @param streamId 直播流ID
|
||||
* @param surfaceView 渲染直播的视图
|
||||
*/
|
||||
public void startLive(String streamId, SurfaceView surfaceView) {
|
||||
ZegoCanvas zegoCanvas = new ZegoCanvas(surfaceView);
|
||||
zegoCanvas.viewMode = ZegoViewMode.SCALE_TO_FILL;
|
||||
mExpressEngine.startPlayingStream(streamId, zegoCanvas);
|
||||
public String startLive(SurfaceView surfaceView) {
|
||||
if (!TextUtils.isEmpty(currentStreamId) &&
|
||||
!currentStreamId.equals(STREAM_ID_PREFIX)) {
|
||||
ZegoCanvas zegoCanvas = new ZegoCanvas(surfaceView);
|
||||
zegoCanvas.viewMode = ZegoViewMode.SCALE_TO_FILL;
|
||||
mExpressEngine.startPlayingStream(currentStreamId, zegoCanvas);
|
||||
} else {
|
||||
Logger.e(TAG, "直播ID有误,请重试");
|
||||
}
|
||||
|
||||
return currentStreamId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止直播
|
||||
*
|
||||
* @param streamId 数据流ID
|
||||
*/
|
||||
public void stopLive(String streamId) {
|
||||
mExpressEngine.stopPlayingStream(streamId);
|
||||
public void stopLive() {
|
||||
mExpressEngine.stopPlayingStream(currentStreamId);
|
||||
stopPreview();
|
||||
logOutRoom();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user