1、升级ZeGo直播SDK
2、修复直播拉流播放状态,
/**
* 连接失败,播放失败,都走这里,可以展示播失败信息
*
* @param errorMsg
*/
void onError(String errorMsg);
/**
* 拉流成功且处于播放中
*/
void onPlaying();
/**
* 拉流重试中,还没成功,可以做Loading
*/
void onPlaRequesting();
106 lines
3.3 KiB
Java
106 lines
3.3 KiB
Java
package com.mogo.cloud;
|
|
|
|
import android.net.wifi.WifiInfo;
|
|
import android.os.Bundle;
|
|
import android.util.Log;
|
|
import android.view.SurfaceView;
|
|
import android.view.View;
|
|
import android.widget.EditText;
|
|
import android.widget.TextView;
|
|
import android.widget.Toast;
|
|
import android.widget.ToggleButton;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import com.mogo.cloud.live.manager.LiveStreamManagerImpl;
|
|
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
|
|
import com.mogo.cloud.trafficlive.api.ITrafficCarLiveCallBack;
|
|
import com.mogo.cloud.trafficlive.api.MoGoAiCloudTrafficLive;
|
|
import com.mogo.cloud.wifi.IWifiStateListener;
|
|
import com.mogo.cloud.wifi.WifiStateManager;
|
|
|
|
|
|
/**
|
|
* @author mogoauto
|
|
*/
|
|
public class LivePlayOneActivity extends AppCompatActivity implements ITrafficCarLiveCallBack, IWifiStateListener {
|
|
private String TAG = "LivePlayOneActivity";
|
|
private TextView tvWifiState;
|
|
|
|
private SurfaceView surfaceView;
|
|
private ToggleButton liveToggleBtn;
|
|
private EditText etLookRoomId;
|
|
private String liveSn;
|
|
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.activity_live_play_on);
|
|
|
|
LiveStreamManagerImpl.getInstance(this.getApplication(),
|
|
MoGoAiCloudClientConfig.getInstance().getSn(), false);
|
|
tvWifiState = findViewById(R.id.tvWifiState);
|
|
|
|
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) {
|
|
liveSn = etLookRoomId.getText().toString().trim();
|
|
MoGoAiCloudTrafficLive.viewDesignativeVehicleLive(liveSn, surfaceView, this);
|
|
} else {
|
|
MoGoAiCloudTrafficLive.stopCarLive(liveSn);
|
|
}
|
|
});
|
|
|
|
surfaceView.setOnClickListener(v -> {
|
|
if (liveToggleBtn.getVisibility() == View.VISIBLE) {
|
|
liveToggleBtn.setVisibility(View.GONE);
|
|
etLookRoomId.setVisibility(View.GONE);
|
|
} else {
|
|
liveToggleBtn.setVisibility(View.VISIBLE);
|
|
etLookRoomId.setVisibility(View.VISIBLE);
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
@Override
|
|
protected void onDestroy() {
|
|
super.onDestroy();
|
|
MoGoAiCloudTrafficLive.stopCarLive(liveSn);
|
|
WifiStateManager.getInstance().unRegisterWifiStateListener(this);
|
|
}
|
|
|
|
@Override
|
|
public void onLive(String liveSn) {
|
|
Log.d(TAG, "开始直播 onLive");
|
|
}
|
|
|
|
@Override
|
|
public void onDisConnect() {
|
|
Log.w(TAG, "失去连接 onDisConnect");
|
|
}
|
|
|
|
@Override
|
|
public void onPlaying() {
|
|
Log.i(TAG, "拉流状态:拉流成功,播放中 …………");
|
|
}
|
|
|
|
@Override
|
|
public void onPlaRequesting() {
|
|
Log.i(TAG, "拉流状态:拉流还没成功,努力加载中 …………");
|
|
}
|
|
|
|
@Override
|
|
public void onError(String errorMsg) {
|
|
Log.d(TAG, "拉流状态:发生错误 onError msg: " + errorMsg);
|
|
}
|
|
|
|
@Override
|
|
public void onWifiState(WifiInfo wifiInfo) {
|
|
tvWifiState.setText("wifiLevel: " + Math.abs(wifiInfo.getRssi()));
|
|
}
|
|
} |