完成了直播播放的拉流demo
This commit is contained in:
@@ -33,8 +33,11 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".PushActivity"
|
||||
android:label="推送直播" />
|
||||
android:name=".LivePushActivity"
|
||||
android:label="直播播放" />
|
||||
<activity
|
||||
android:name=".LivePlayActivity"
|
||||
android:label="直播推送" />
|
||||
<activity
|
||||
android:name="com.mogo.cloud.network.NetworkActivity"
|
||||
android:label="网络测试" />
|
||||
|
||||
@@ -38,7 +38,7 @@ public abstract class BaseLiveActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_push_video);
|
||||
setContentView(R.layout.activity_live_push);
|
||||
|
||||
surfaceView = findViewById(R.id.surfaceView);
|
||||
btnLive = findViewById(R.id.btnLive);
|
||||
|
||||
101
app/src/main/java/com/mogo/cloud/LivePlayActivity.java
Normal file
101
app/src/main/java/com/mogo/cloud/LivePlayActivity.java
Normal file
@@ -0,0 +1,101 @@
|
||||
package com.mogo.cloud;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
import android.widget.ToggleButton;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.mogo.cloud.live.listener.ILiveProgressListener;
|
||||
import com.mogo.cloud.live.manager.ZeGoLiveManager;
|
||||
import com.mogo.cloud.util.Devices;
|
||||
|
||||
|
||||
public class LivePlayActivity extends AppCompatActivity {
|
||||
private String TAG = "LiveActivity";
|
||||
|
||||
private SurfaceView surfaceView;
|
||||
private ToggleButton liveToggleBtn;
|
||||
private EditText etLookRoomId;
|
||||
|
||||
private boolean isLoginSuccess = false;
|
||||
private String mStreamId = "STREAM_ID_";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_live_play);
|
||||
surfaceView = findViewById(R.id.surfaceView);
|
||||
etLookRoomId = findViewById(R.id.etLookRoomId);
|
||||
liveToggleBtn = findViewById(R.id.liveToggleBtn);
|
||||
liveToggleBtn.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
Toast.makeText(getApplicationContext(), buttonView.getText(), Toast.LENGTH_SHORT).show();
|
||||
if (isChecked) {
|
||||
String roomId = etLookRoomId.getText().toString().trim();
|
||||
mStreamId = ZeGoLiveManager.STREAM_ID_PREFIX + roomId;
|
||||
ZeGoLiveManager.getInstance().init(this.getApplication(), null);
|
||||
ZeGoLiveManager.getInstance().loginRoom("F803EB2046PZD00140", roomId);
|
||||
ZeGoLiveManager.getInstance().setLiveProgressListener(listener);
|
||||
} else {
|
||||
ZeGoLiveManager.getInstance().stopLive(mStreamId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private ILiveProgressListener listener = new ILiveProgressListener() {
|
||||
|
||||
@Override
|
||||
public void onConnecting() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected(String roomId) {
|
||||
Log.i(TAG, "onConnected:" + roomId);
|
||||
isLoginSuccess = true;
|
||||
toggleLive(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisConnect() {
|
||||
Log.i(TAG, "onDisConnect:");
|
||||
isLoginSuccess = false;
|
||||
toggleLive(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDebugError(int errorCode, String funcName, String errorInfo) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRoomStreamUpdate(String streamId, boolean isLive) {
|
||||
Log.i(TAG, "onRoomStreamUpdate:" + streamId);
|
||||
if (streamId != null && isLive) {
|
||||
Toast.makeText(LivePlayActivity.this, "主播开始直播了", Toast.LENGTH_SHORT).show();
|
||||
mStreamId = streamId;
|
||||
} else {
|
||||
Toast.makeText(LivePlayActivity.this, "主播已离线", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private void toggleLive(boolean isChecked) {
|
||||
Log.i(TAG, "toggleLive status : " + isChecked + " , mStreamId : " + mStreamId);
|
||||
if (isChecked) {
|
||||
ZeGoLiveManager.getInstance().startLive(mStreamId, surfaceView);
|
||||
} else {
|
||||
ZeGoLiveManager.getInstance().stopLive(mStreamId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
ZeGoLiveManager.getInstance().onDestroyLive();
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import com.mogo.cloud.util.Devices;
|
||||
/**
|
||||
* 推流页面
|
||||
*/
|
||||
public class PushActivity extends BaseLiveActivity {
|
||||
public class LivePushActivity extends BaseLiveActivity {
|
||||
public static final String TAG = "PushActivity";
|
||||
|
||||
private boolean isLive = false;
|
||||
@@ -18,7 +18,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
private Button btnJumpNetWorkPort;
|
||||
private Button btnJumpRealTime;
|
||||
private Button btnJumpRoadCondition;
|
||||
private Button btnJumpPushLive;
|
||||
private Button btnJumpLivePush;
|
||||
private Button btnJumpLivePlay;
|
||||
|
||||
private TextView tvSn;
|
||||
private TextView tvToken;
|
||||
@@ -58,9 +59,15 @@ public class MainActivity extends AppCompatActivity {
|
||||
startActivity(intent);
|
||||
});
|
||||
|
||||
btnJumpPushLive = findViewById(R.id.btnJumpPushLive);
|
||||
btnJumpPushLive.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(MainActivity.this, PushActivity.class);
|
||||
btnJumpLivePush = findViewById(R.id.btnJumpLivePush);
|
||||
btnJumpLivePush.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(MainActivity.this, LivePushActivity.class);
|
||||
startActivity(intent);
|
||||
});
|
||||
|
||||
btnJumpLivePlay = findViewById(R.id.btnJumpLivePlay);
|
||||
btnJumpLivePlay.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(MainActivity.this, LivePlayActivity.class);
|
||||
startActivity(intent);
|
||||
});
|
||||
|
||||
|
||||
35
app/src/main/res/layout/activity_live_play.xml
Normal file
35
app/src/main/res/layout/activity_live_play.xml
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".LivePlayActivity">
|
||||
|
||||
<SurfaceView
|
||||
android:id="@+id/surfaceView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etLookRoomId"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="请输入要查看的车机SN"
|
||||
android:text="F803EB2046PZD00149"
|
||||
android:textColor="#FFFF"
|
||||
app:layout_constraintBottom_toTopOf="@+id/liveToggleBtn"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<ToggleButton
|
||||
android:id="@+id/liveToggleBtn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textOff="开始拉流"
|
||||
android:textOn="停止拉流"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -67,10 +67,15 @@
|
||||
android:text="路况服务测试" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnJumpPushLive"
|
||||
android:id="@+id/btnJumpLivePush"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="直播SDK推流测试" />
|
||||
<Button
|
||||
android:id="@+id/btnJumpLivePlay"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="直播SDK观看测试" />
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
Reference in New Issue
Block a user