创建看直播服务

创建看直播服务

创建直播服务,可以直接拉流,观看直播

Builder参数 描述
IVideoPlayer 视频
IAudioPlayer 音频
bufferSeconds 加载时长
reconnectTimes 重连时间
connectTimeout 超时时间
defaultDPI 默认使用的分辨率
defaultStream 默认使用的协议
LiveCallback 直播回调

创建直播的就Builder构造

WatchLive.Builder builder = new WatchLive.Builder();
        builder.videoPlayer(player)
                .bufferSeconds(6)
                .defaultDPI(DPI_SAME)
                .callback(new LiveCallback());
        WatchLive vhClassLive = builder.build(mContext);

开始拉流

vhClassLive.start();

停止拉流

vhClassLive.stop();

设置填充模式

vhClassLive.setDrawMode();

设置是否在播放

vhClassLive.getPlaying();

设置分辨率

在设置分辨率时,必须先获取支持的分辨率,从消息中的 IVHPlayer.EVENT_SUPPORT_DPI : 获取可用的分辨率 如果当前分辨率可用,才能设置

支持的分辨率 描述
IVHPlayer.DPI_SAME 默认分辨率,原画
IVHPlayer.DPI_AUDIO 纯音频
IVHPlayer.DPI_LDR 低清(360p)
IVHPlayer.DPI_SDR 标清(480p)
IVHPlayer.DPI_HDR 高清(720p)
vhClassLive.setDPI(DPI_SAME);

举手

调用此方法,会发送一条举手消息通知Web的讲师,讲师会收到消息,选择是否让你上麦互动

VHClass.getInstance().hand(new RequestCallback() {
                @Override
                public void onSuccess() {
                    // 举手成功
                }

                @Override
                public void onError(int errorCode, String errorMsg) {
					// 举手失败
                }
            });

拒绝上麦

当老师邀请你上麦时,你可以选择同意或者拒绝上麦,当调用此方法时,会发送一条消息告知讲师端你拒绝了老师的邀请

VHClass.getInstance().sendRefuseCmd(new RequestCallback() {
            @Override
            public void onSuccess() {

            }

            @Override
            public void onError(int errorCode, String errorMsg) {

            }
        });

销毁播放器

vhClassLive.release();

播放器回调

监听播放器的状态

    public class LivePlayerListener implements VHPlayerListener {

        @Override
        public void onStateChanged(Constants.State state) {
		/*
		*	public static enum State {
		*		NONE, IDLE, START, PAUSE, STOP, BUFFER, END;
		*	}
		*/
        }

        @Override
        public void onEvent(int i, String s) {
		/*
			public static final class Event {
		        public static final int EVENT_VIDEO_SIZE_CHANGED = -0x109;
		        public static final int EVENT_DPI_CHANGED = -0X104;
		        public static final int EVENT_DPI_LIST = -0X105;
		        public static final int EVENT_URL = -0X1000;
		        public static final int EVENT_INIT_SUCCESS = -0X111;
		        public static final int EVENT_STATUS_STARTING = -257;
		        public static final int EVENT_DOWNLOAD_SPEED = -262;
		        public static final int EVENT_STOP_BUFFER = -264;
		        public static final int EVENT_STREAM_START = -272;
		        public static final int EVENT_STREAM_STOP = -273;
		        public static final int EVENT_STREAM_MSG = -274;
		        public static final int EVENT_NO_STREAM = -275;
		        //pusher
		        public static final int EVENT_UPLOAD_SPEED = 0x04;
		        public static final int EVENT_NETWORK_OBS = 0x05;
		        public static final int EVENT_NETWORK_UNOBS = 0x06;
		    }
		*/
        }

        @Override
        public void onError(int i, int i1, String s) {
		/*
			public static final class ErrorCode {
		        public static final int ERROR_INIT = -1;
		        public static final int ERROR_INIT_FIRST = -2;
		        public static final int ERROR_CONNECT = -1;
		        public static final int ERROR_REC = -2;
		        public static final int ERROR_NET = -3;
		        public static final int ERROR_PUSH = 1;
		        public static final int ERROR_VIDEO_CAPTURE = 2;
		        public static final int ERROR_AUDIO_CAPTURE = 3;
		        public static final int ERROR_SEND = 2;
		        public static final int ERROR_PARAM = 3;
		    }
		*/
        }
    }